Search in sources :

Example 16 with Element

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;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Page(org.wikipediacleaner.api.data.Page)

Example 17 with Element

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;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) List(java.util.List)

Example 18 with Element

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);
    }
}
Also used : APIException(org.wikipediacleaner.api.APIException) Element(org.jdom2.Element) JDOMException(org.jdom2.JDOMException)

Example 19 with Element

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);
}
Also used : Element(org.jdom2.Element)

Example 20 with Element

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();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File)

Aggregations

Element (org.jdom2.Element)3601 Document (org.jdom2.Document)589 Test (org.junit.Test)469 ArrayList (java.util.ArrayList)376 IOException (java.io.IOException)317 JDOMException (org.jdom2.JDOMException)230 Attribute (org.jdom2.Attribute)217 SAXBuilder (org.jdom2.input.SAXBuilder)169 Namespace (org.jdom2.Namespace)157 List (java.util.List)148 Element (org.osate.aadl2.Element)143 File (java.io.File)140 XMLOutputter (org.jdom2.output.XMLOutputter)136 Test (org.junit.jupiter.api.Test)134 HashMap (java.util.HashMap)132 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 StringReader (java.io.StringReader)85 NamedElement (org.osate.aadl2.NamedElement)77 Iterator (java.util.Iterator)72