* @throws APIException
*/
private LoginResult constructLogin(Element root)
throws APIException {
try {
XPath xpa = XPath.newInstance("/api/login");
Element node = (Element) xpa.selectSingleNode(root);
if (node != null) {
XPath xpaResult = XPath.newInstance("./@result");
String result = xpaResult.valueOf(node);
if ("Success".equalsIgnoreCase(result)) {
XPath xpaUserid = XPath.newInstance("./@lguserid");
XPath xpaUsername = XPath.newInstance("./@lgusername");
XPath xpaToken = XPath.newInstance("./@lgtoken");
getWiki().getConnection().setLgInformation(
xpaToken.valueOf(node),
xpaUsername.valueOf(node),
xpaUserid.valueOf(node));
return LoginResult.createCorrectLogin();
} else if (EnumLoginResult.NEED_TOKEN.getCode().equalsIgnoreCase(result)) {
XPath xpaToken = XPath.newInstance("./@token");
return LoginResult.createNeedTokenLogin(xpaToken.valueOf(node));
}
XPath xpaWait = XPath.newInstance("./@wait");
XPath xpaDetails = XPath.newInstance("./@details");
return LoginResult.createErrorLogin(result, xpaDetails.valueOf(node), xpaWait.valueOf(node));
}
} catch (JDOMException e) {
log.error("Error login", e);
throw new APIException("Error parsing XML result", e);
}