Search in sources :

Example 16 with Element

use of org.hl7.elm.r1.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.hl7.elm.r1.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.hl7.elm.r1.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.hl7.elm.r1.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.hl7.elm.r1.Element in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addExtensionValueQuantity.

/**
 * Adds an {@link Extension} to the specified {@link DomainResource}. {@link Extension#getValue()}
 * will be set to a {@link Quantity} with the specified system and value.
 *
 * @param fhirElement the FHIR element to add the {@link Extension} to
 * @param extensionUrl the {@link Extension#getUrl()} to use
 * @param quantitySystem the {@link Quantity#getSystem()} to use
 * @param quantityValue the {@link Quantity#getValue()} to use
 */
static void addExtensionValueQuantity(IBaseHasExtensions fhirElement, String extensionUrl, String quantitySystem, BigDecimal quantityValue) {
    IBaseExtension<?, ?> extension = fhirElement.addExtension();
    extension.setUrl(extensionUrl);
    extension.setValue(new Quantity().setSystem(extensionUrl).setValue(quantityValue));
// CodeableConcept codeableConcept = new CodeableConcept();
// extension.setValue(codeableConcept);
// 
// Coding coding = codeableConcept.addCoding();
// coding.setSystem(codingSystem).setCode(codingCode);
}
Also used : SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) Quantity(org.hl7.fhir.dstu3.model.Quantity)

Aggregations

Element (org.jdom2.Element)3601 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)659 ArrayList (java.util.ArrayList)616 Document (org.jdom2.Document)589 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)488 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)486 Test (org.junit.Test)474 IOException (java.io.IOException)414 JDOMException (org.jdom2.JDOMException)230 Attribute (org.jdom2.Attribute)217 List (java.util.List)189 SAXBuilder (org.jdom2.input.SAXBuilder)169 File (java.io.File)162 FHIRException (org.hl7.fhir.exceptions.FHIRException)162 HashMap (java.util.HashMap)159 Namespace (org.jdom2.Namespace)157 Test (org.junit.jupiter.api.Test)154 Element (org.osate.aadl2.Element)143 XMLOutputter (org.jdom2.output.XMLOutputter)136 XConfiguration (org.apache.oozie.util.XConfiguration)98