use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiJsonResult method getPage.
/**
* Get a page corresponding to a page node.
*
* @param wiki Wiki.
* @param pageNode Page node.
* @param knownPages Already known pages.
* @param useDisambig True if disambiguation property should be used.
* @return Page.
*/
protected static Page getPage(EnumWikipedia wiki, Element pageNode, List<Page> knownPages, boolean useDisambig) {
if (pageNode == null) {
return null;
}
String title = pageNode.getAttributeValue("title");
Attribute pageIdAttr = pageNode.getAttribute("pageid");
Integer pageId = null;
if (pageIdAttr != null) {
try {
String tmp = pageIdAttr.getValue();
pageId = Integer.valueOf(tmp);
} catch (NumberFormatException e) {
//
}
}
String revisionId = pageNode.getAttributeValue("lastrevid");
Page page = DataManager.getPage(wiki, title, pageId, revisionId, knownPages);
page.setNamespace(pageNode.getAttributeValue("ns"));
if (pageNode.getAttribute("missing") != null) {
page.setExisting(Boolean.FALSE);
} else if (pageId != null) {
page.setExisting(Boolean.TRUE);
}
if (pageNode.getAttribute("redirect") != null) {
page.getRedirects().isRedirect(true);
}
if (useDisambig) {
Element pageProps = pageNode.getChild("pageprops");
boolean dabPage = (pageProps != null) && (pageProps.getAttribute("disambiguation") != null);
page.setDisambiguationPage(Boolean.valueOf(dabPage));
}
return page;
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiXmlResult method shouldContinue.
/**
* Manage query-continue in request.
*
* @param root Root of the DOM tree.
* @param queryContinue XPath query to the query-continue node.
* @param properties Properties defining request.
* @return True if request should be continued.
*/
protected boolean shouldContinue(Element root, String queryContinue, Map<String, String> properties) {
if ((root == null) || (queryContinue == null)) {
return false;
}
boolean result = false;
XPathExpression<Element> xpa = XPathFactory.instance().compile(queryContinue, Filters.element());
List<Element> results = xpa.evaluate(root);
if ((results == null) || (results.isEmpty())) {
xpa = XPathFactory.instance().compile("/api/continue", Filters.element());
results = xpa.evaluate(root);
}
if (results != null) {
for (Object currentNode : results) {
List attributes = ((Element) currentNode).getAttributes();
if (attributes != null) {
for (Object currentAttribute : attributes) {
Attribute attribute = (Attribute) currentAttribute;
properties.put(attribute.getName(), attribute.getValue());
result = true;
}
}
}
}
return result;
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiXmlExpandResult method executeExpandTemplates.
/**
* Execute expand templates request.
*
* @param properties Properties defining request.
* @return Expanded text.
* @throws APIException Exception thrown by the API.
*/
@Override
public String executeExpandTemplates(Map<String, String> properties) throws APIException {
try {
XPathExpression<Element> xpaText = XPathFactory.instance().compile("/api/expandtemplates/wikitext", Filters.element());
Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
Element text = xpaText.evaluateFirst(root);
return (text != null) ? text.getText() : null;
} catch (JDOMException e) {
log.error("Error expanding templates", e);
throw new APIException("Error parsing XML", e);
}
}
use of org.adempiere.pipo2.Element in project wpcleaner by WPCleaner.
the class ApiXmlLoginResult method constructLogin.
/**
* Analyze login answer.
*
* @param root Root element in MediaWiki answer.
* @return Result of the login.
* @throws APIException Exception thrown by the API.
*/
private LoginResult constructLogin(Element root) throws APIException {
// try {
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/login", Filters.element());
Element node = xpa.evaluateFirst(root);
if (node != null) {
String result = node.getAttributeValue("result");
if ("Success".equalsIgnoreCase(result)) {
getWiki().getConnection().setLgInformation(node.getAttributeValue("lgtoken"), node.getAttributeValue("lgusername"), node.getAttributeValue("lguserid"));
return LoginResult.createCorrectLogin();
} else if (EnumLoginResult.NEED_TOKEN.getCode().equalsIgnoreCase(result)) {
return LoginResult.createNeedTokenLogin(node.getAttributeValue("token"));
}
String details = node.getAttributeValue("details");
if (details == null) {
details = node.getAttributeValue("reason");
}
return LoginResult.createErrorLogin(result, details, node.getAttributeValue("wait"));
}
// }
return LoginResult.createErrorLogin(null, null, null);
}
use of org.adempiere.pipo2.Element in project bigwarp by saalfeldlab.
the class BigWarp method loadSettings.
protected void loadSettings(final String xmlFilename) throws IOException, JDOMException {
final SAXBuilder sax = new SAXBuilder();
final Document doc = sax.build(xmlFilename);
final Element root = doc.getRootElement();
viewerP.stateFromXml(root.getChild("viewerP"));
viewerQ.stateFromXml(root.getChild("viewerQ"));
setupAssignments.restoreFromXml(root);
bookmarks.restoreFromXml(root);
activeSourcesDialogP.update();
activeSourcesDialogQ.update();
// auto-save settings
Element autoSaveElem = root.getChild("autosave");
final String autoSavePath = autoSaveElem.getChild("location").getText();
final long autoSavePeriod = Integer.parseInt(autoSaveElem.getChild("period").getText());
setAutosaveFolder(new File(autoSavePath));
BigWarpAutoSaver.setAutosaveOptions(this, autoSavePeriod, autoSavePath);
viewerFrameP.repaint();
viewerFrameQ.repaint();
}
Aggregations