Example usage for org.w3c.dom Element getLocalName

List of usage examples for org.w3c.dom Element getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Element getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.openestate.io.immobiliare_it.ImmobiliareItDocument.java

/**
 * Checks, if a {@link Document} is readable as a
 * {@link ImmobiliareItDocument}./*from www.  ja  v  a 2s.  c  o m*/
 *
 * @param doc
 * document to check
 *
 * @return
 * true, if the document is usable, otherwise false
 */
public static boolean isReadable(Document doc) {
    Element root = XmlUtils.getRootElement(doc);
    return "feed".equals(root.getLocalName());
}

From source file:org.openestate.io.immoxml.ImmoXmlDocument.java

/**
 * Checks, if a {@link Document} is readable as a {@link ImmoXmlDocument}.
 *
 * @param doc/*  w  w  w  .j a  v  a2  s  .c  o m*/
 * document to check
 *
 * @return
 * true, if the document is usable, otherwise false
 */
public static boolean isReadable(Document doc) {
    Element root = XmlUtils.getRootElement(doc);
    return "immoxml".equals(root.getLocalName());
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Downgrade <url> elements to Kyero 2.1.
 * <p>/*w ww  .j  a  v  a 2  s  .c  o m*/
 * The &lt;url&gt; elements only support a simple text value in version
 * 2.1. Version 3 allows different URL's for different languages.
 * <p>
 * Any children of &lt;url&gt; elements are removed. The english URL or the
 * first found URL is copied as simple value into the &lt;url&gt; element.
 *
 * @param doc Kyero document in version 3
 * @throws JaxenException
 */
protected void downgradeUrlElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:url", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String enUrlValue = null;
        String fallbackUrlValue = null;
        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Element langNode = (Element) childItem;
            if ("en".equalsIgnoreCase(langNode.getLocalName()))
                enUrlValue = StringUtils.trimToNull(langNode.getTextContent());
            else if (fallbackUrlValue == null)
                fallbackUrlValue = StringUtils.trimToNull(langNode.getTextContent());
            node.removeChild(langNode);
        }

        node.setTextContent((enUrlValue != null) ? enUrlValue : fallbackUrlValue);
    }
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Remove elements with translations in unsupported languages.
 * <p>//  w w  w.j  a  v a2 s .c om
 * Kyero 2.1 does only support translation in &lt;title&gt; (for images),
 * &lt;desc&gt; (for properties) elements for "en", "es", "de", "nl", "fr".
 *
 * @param doc OpenImmo document in version 3
 * @throws JaxenException
 */
protected void removeUnsupportedLanguageElements(Document doc) throws JaxenException {
    String[] unsupportedLanguages = new String[] { "ar", "bg", "ca", "cs", "da", "el", "et", "fa", "fi", "he",
            "hi", "hu", "id", "it", "ja", "ko", "lt", "lv", "no", "pl", "pt", "ro", "ru", "sk", "sl", "sv",
            "th", "tr", "uk", "vi", "zh", };
    List nodes = XmlUtils
            .newXPath("/io:root/io:property/io:desc | " + "/io:root/io:property/io:images/io:image/io:title",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Element langNode = (Element) childItem;
            String lang = langNode.getLocalName().toLowerCase();
            if (ArrayUtils.contains(unsupportedLanguages, lang)) {
                node.removeChild(langNode);
            }
        }
    }
}

From source file:org.openestate.io.kyero.converters.Kyero_3.java

/**
 * Upgrade &lt;type&gt; elements to Kyero 3.
 * <p>/*from   w  w  w .j  a va 2 s . c o  m*/
 * The &lt;type&gt; elements do not support any child element in version 3.
 * <p>
 * Any child elements of &lt;type&gt; are removed. The text from the
 * &lt;en&gt; child element is copied into the &lt;type&gt; element.
 *
 * @param doc Kyero document in version 2.1
 * @throws JaxenException
 */
protected void upgradeTypeElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:root/io:property/io:type", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String enTypeValue = null;
        String fallbackTypeValue = null;
        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Element langNode = (Element) childItem;
            if ("en".equalsIgnoreCase(langNode.getLocalName()))
                enTypeValue = StringUtils.trimToNull(langNode.getTextContent());
            else if (fallbackTypeValue == null)
                fallbackTypeValue = StringUtils.trimToNull(langNode.getTextContent());
            node.removeChild(langNode);
        }
        node.setTextContent((enTypeValue != null) ? enTypeValue : fallbackTypeValue);
    }
}

From source file:org.openestate.io.kyero.KyeroDocument.java

/**
 * Checks, if a {@link Document} is readable as a {@link KyeroDocument}.
 *
 * @param doc//  w  w w .  ja  va 2 s . c  om
 * document to check
 *
 * @return
 * true, if the document is usable, otherwise false
 */
public static boolean isReadable(Document doc) {
    Element root = XmlUtils.getRootElement(doc);
    return "root".equals(root.getLocalName());
}

From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_2.java

/**
 * Downgrade &lt;objektart&gt; elements to OpenImmo 1.2.1.
 * <p>//from   w  w w . j a va 2s . com
 * The &lt;objektart&gt; element does only allow the same type of child
 * element in version 1.2.1.
 * <p>
 * Any child type, that differs from the first child type, is removed.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException
 */
protected void downgradeObjektartElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element parentNode = (Element) item;
        String type = null;

        List childNodes = XmlUtils.newXPath("*", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Element node = (Element) childItem;
            if (type == null) {
                //LOGGER.debug( "PRIMARY TYPE: " + node.getLocalName() );
                type = node.getLocalName();
            } else if (!type.equalsIgnoreCase(node.getLocalName())) {
                //LOGGER.debug( "REMOVE SECONDARY TYPE: " + node.getLocalName() );
                parentNode.removeChild(node);
            }
        }
    }
}

From source file:org.openestate.io.openimmo.OpenImmoFeedbackDocument.java

/**
 * Checks, if a {@link Document} is readable as a
 * {@link OpenImmoFeedbackDocument}.//from w w  w  . java 2  s  .c om
 *
 * @param doc
 * document to check
 *
 * @return
 * true, if the document is usable, otherwise false
 */
public static boolean isReadable(Document doc) {
    Element root = XmlUtils.getRootElement(doc);
    return "openimmo_feedback".equals(root.getLocalName());
}

From source file:org.openestate.io.openimmo.OpenImmoTransferDocument.java

/**
 * Checks, if a {@link Document} is readable as a
 * {@link OpenImmoTransferDocument}.//  ww w .  ja  v a  2  s .  c  o  m
 *
 * @param doc
 * document to check
 *
 * @return
 * true, if the document is usable, otherwise false
 */
public static boolean isReadable(Document doc) {
    Element root = XmlUtils.getRootElement(doc);
    return "openimmo".equals(root.getLocalName());
}

From source file:org.openmrs.projectbuendia.webservices.rest.XformInstanceResource.java

/**
 * Fixes up the received XForm instance with various adjustments and additions
 * needed to get the observations into OpenMRS, e.g. include Patient ID, adjust
 * datetime formats, etc./*  w ww .java2 s .com*/
 */
static String completeXform(SimpleObject post) throws SAXException, IOException {
    String xml = (String) post.get("xml");
    Integer patientId = (Integer) post.get("patient_id");

    int entererId = (Integer) post.get("enterer_id");
    String dateEntered = (String) post.get("date_entered");
    dateEntered = workAroundClientIssue(dateEntered);
    Document doc = XmlUtil.parse(xml);

    // If we haven't been given a patient id, then the XForms processor will
    // create a patient then fill in the patient.patient_id in the DOM.
    // However, it won't actually create the node, just fill it in.
    // So whatever the case, make sure a patient.patient_id node exists.

    Element root = doc.getDocumentElement();
    Element patient = getFirstElementOrCreate(doc, root, "patient");
    Element patientIdElement = getFirstElementOrCreate(doc, patient, "patient.patient_id");

    // Add patient element if we've been given a patient ID.
    // TODO: Is this okay if there's already a patient element?
    // Need to see how the Xforms module behaves.
    if (patientId != null) {
        patientIdElement.setTextContent(String.valueOf(patientId));
    }

    // Modify header element
    Element header = getElementOrThrow(root, "header");
    getElementOrThrow(header, "enterer").setTextContent(entererId + "^");
    getElementOrThrow(header, "date_entered").setTextContent(dateEntered);

    // NOTE(kpy): We use a form_resource named <form-name>.xFormXslt to alter the translation
    // from XML to HL7 so that the encounter_datetime is recorded with a date and time.
    // (The default XSLT transform records only the date, not the time.)  This means that
    // IF THE FORM IS RENAMED, THE FORM_RESOURCE MUST ALSO BE RENAMED, or the encounter
    // datetime will be recorded with only a date and the time will always be 00:00.

    // Extract the datetime and set it back, to reformat it to a format that OpenMRS
    // will accept, ensure it has a value that OpenMRS will accept, and also to
    // ensure that a datetime is filled in if missing.
    Date datetime = Utils.fixEncounterDateTime(getEncounterDatetime(doc));

    // OpenMRS has trouble handling the encounter_datetime in the format we receive.
    // We must set the encounter_datetime to ensure it is properly formatted.
    setEncounterDatetime(doc, datetime);

    // TODO: we should also have some code here to ensure that the correct XSLT exists
    // for every form; otherwise we lose it on form rename.

    // Make sure that all observations are under the obs element, with appropriate attributes
    Element obs = getFirstElementOrCreate(doc, root, "obs");
    obs.setAttribute("openmrs_concept", "1238^MEDICAL RECORD OBSERVATIONS^99DCT");
    obs.setAttribute("openmrs_datatype", "ZZ");
    for (Element element : getElements(root)) {
        if (!KNOWN_CHILD_ELEMENTS.contains(element.getLocalName())) {
            for (Element observation : getElements(element)) {
                obs.appendChild(observation);
            }
            removeNode(element);
        }
    }

    return XformsUtil.doc2String(doc);
}