Example usage for org.w3c.dom Element removeChild

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

Introduction

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

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

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

/**
 * Downgrade <anhang> elements to OpenImmo 1.2.3.
 * <p>//  w ww. j  a va  2  s .c  o m
 * The options "QRCODE", "FILM", "FILMLINK" for the "gruppe" attribute of
 * &lt;anhang&gt; elements are not available in version 1.2.3.
 * <p>
 * The option "REMOTE" for the "location" attribute of
 * &lt;anhang&gt; elements is not available in version 1.2.3.
 * <p>
 * The the child element &lt;check&gt; of &lt;anhang&gt; elements is not
 * available in version 1.2.3.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException
 */
protected void downgradeAnhangElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:anhang | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String value = StringUtils.trimToNull(node.getAttribute("gruppe"));
        if ("QRCODE".equalsIgnoreCase(value))
            node.removeAttribute("gruppe");
        else if ("FILM".equalsIgnoreCase(value))
            node.removeAttribute("gruppe");
        else if ("FILMLINK".equalsIgnoreCase(value))
            node.removeAttribute("gruppe");

        value = StringUtils.trimToNull(node.getAttribute("location"));
        if ("REMOTE".equalsIgnoreCase(value))
            node.setAttribute("location", "EXTERN");

        List childNodes = XmlUtils.newXPath("io:check", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            node.removeChild((Node) childItem);
        }
    }
}

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

/**
 * Remove unsupported children from all &lt;interessent&gt; elements in
 * feedback XML.//from  w  w  w.j  av  a 2s .c o m
 * <p>
 * OpenImmo 1.2.3 does not support more then one &lt;bevorzugt&gt;,
 * &lt;wunsch&gt; elements in feedback XML.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException
 */
protected void removeFeedbackInteressentChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo_feedback/io:objekt/io:interessent", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element parentNode = (Element) item;
        boolean bevorzugtPassed = false;
        boolean wunschPassed = false;

        List childNodes = XmlUtils.newXPath("io:bevorzugt", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Element node = (Element) childItem;
            if (!bevorzugtPassed)
                bevorzugtPassed = true;
            else
                parentNode.removeChild(node);
        }

        childNodes = XmlUtils.newXPath("io:wunsch", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Element node = (Element) childItem;
            if (!wunschPassed)
                wunschPassed = true;
            else
                parentNode.removeChild(node);
        }
    }
}

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

/**
 * Remove &lt;version&gt; elements in feedback XML.
 * <p>/*from w  w  w .  ja  v a 2 s  .c o m*/
 * OpenImmo 1.2.3 does not support &lt;version&gt; elements in feedback XML.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException
 */
protected void removeFeedbackVersionElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo_feedback/io:version", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}

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

/**
 * Remove unsupported children from all &lt;preise&gt; elements.
 * <p>//  w w  w .  ja  v a  2s. c om
 * OpenImmo 1.2.3 does not support the following children for
 * &lt;preise&gt; elements: &lt;provision_teilen&gt;, &lt;kaution_text&gt;,
 * &lt;richtpreis&gt;
 * <p>
 * These elements are removed by this function.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException
 */
protected void removePreiseChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:preise/io:provision_teilen | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:kaution_text | "
            + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:richtpreis", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}

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

/**
 * Remove &lt;wintergarten&gt; elements.
 * <p>/*  w  w  w  .  ja va 2 s.c o  m*/
 * OpenImmo 1.2.3 does not support &lt;wintergarten&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.4
 * @throws JaxenException
 */
protected void removeWintergartenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:wintergarten", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}

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

/**
 * Upgrade &lt;anzahl_balkon_terrassen&gt; elements to OpenImmo 1.2.4.
 * <p>/*from   w  w  w.j  a  v a 2s .  c  o m*/
 * The &lt;anzahl_balkon_terrassen&gt; is not supported anymore in version
 * 1.2.4. The element is replaced by &lt;anzahl_balkone&gt; and
 * &lt;anzahl_terrassen&gt;.
 * <p>
 * Any &lt;anzahl_balkon_terrassen&gt; element is removed. Its content is
 * copied into &lt;anzahl_balkone&gt;, if this element is not already present.
 *
 * @param doc OpenImmo document in version 1.2.3
 * @throws JaxenException
 */
protected void upgradeAnzahlBalkonTerrassenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_balkon_terrassen", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        String value = StringUtils.trimToNull(node.getTextContent());
        if (value != null) {
            Element newNode = (Element) XmlUtils.newXPath("io:anzahl_balkone", doc)
                    .selectSingleNode(parentNode);
            if (newNode == null) {
                newNode = doc.createElementNS(StringUtils.EMPTY, "anzahl_balkone");
                newNode.setTextContent(value);
                parentNode.appendChild(newNode);
            } else if (StringUtils.isBlank(newNode.getTextContent())) {
                newNode.setTextContent(value);
            }
        }
        parentNode.removeChild(node);
    }
}

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

/**
 * Upgrade &lt;sonstige&gt; elements to OpenImmo 1.2.4.
 * <p>//from  w  ww.  ja  v  a 2s. c o m
 * The options "GARAGEN", "PARKFLACHE" for the "sonstige_typ" attribute of
 * &lt;sonstige&gt; elements were removed with OpenImmo 1.2.4.
 * <p>
 * For any occurence of these values the corresponding &lt;sonstige&gt;
 * element is replaced with a &lt;parken&gt; element.
 *
 * @param doc OpenImmo document in version 1.2.3
 * @throws JaxenException
 */
protected void upgradeSonstigeElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:sonstige[@sonstige_typ]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("sonstige_typ"));
        if ("GARAGEN".equalsIgnoreCase(value) || "PARKFLACHE".equalsIgnoreCase(value)) {
            Element parentNode = (Element) node.getParentNode();
            parentNode.removeChild(node);

            Element newNode = doc.createElementNS(StringUtils.EMPTY, "parken");
            newNode.setAttribute("parken_typ", "STELLPLATZ");
            parentNode.appendChild(newNode);
        }
    }
}

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

/**
 * Downgrade &lt;energiepass&gt; elements to OpenImmo 1.2.4.
 * <p>/*from   ww w.  ja v  a 2  s.  c  om*/
 * The child elements &lt;hwbwert&gt;, &lt;hwbklasse&gt;,
 * &lt;fgeewert&gt;, &lt;fgeeklasse&gt; are copied into separate
 * &lt;user_defined_simplefield&gt; elements as it was
 * suggested by OpenImmo e.V..
 *
 * @param doc OpenImmo document in version 1.2.5
 * @throws JaxenException
 */
protected void downgradeEnergiepassElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:energiepass", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        boolean hwbwertPassed = false;
        boolean hwbklassePassed = false;
        boolean fgeewertPassed = false;
        boolean fgeeklassePassed = false;
        List childNodes;

        // create a <user_defined_simplefield> for <hwbwert> elements
        childNodes = XmlUtils.newXPath("io:hwbwert", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Node childNode = (Node) childItem;
            if (!hwbwertPassed) {
                String value = StringUtils.trimToNull(childNode.getTextContent());
                if (value != null) {
                    parentNode.appendChild(
                            OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_hwbwert", value));
                    hwbwertPassed = true;
                }
            }
            node.removeChild(childNode);
        }

        // create a <user_defined_simplefield> for <hwbklasse> elements
        childNodes = XmlUtils.newXPath("io:hwbklasse", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Node childNode = (Node) childItem;
            if (!hwbklassePassed) {
                String value = StringUtils.trimToNull(childNode.getTextContent());
                if (value != null) {
                    parentNode.appendChild(
                            OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_hwbklasse", value));
                    hwbklassePassed = true;
                }
            }
            node.removeChild(childNode);
        }

        // create a <user_defined_simplefield> for <fgeewert> elements
        childNodes = XmlUtils.newXPath("io:fgeewert", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Node childNode = (Node) childItem;
            if (!fgeewertPassed) {
                String value = StringUtils.trimToNull(childNode.getTextContent());
                if (value != null) {
                    parentNode.appendChild(
                            OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_fgeewert", value));
                    fgeewertPassed = true;
                }
            }
            node.removeChild(childNode);
        }

        // create a <user_defined_simplefield> for <baujahr> elements
        childNodes = XmlUtils.newXPath("io:fgeeklasse", doc).selectNodes(node);
        for (Object childItem : childNodes) {
            Node childNode = (Node) childItem;
            if (!fgeeklassePassed) {
                String value = StringUtils.trimToNull(childNode.getTextContent());
                if (value != null) {
                    parentNode.appendChild(
                            OpenImmoUtils.createUserDefinedSimplefield(doc, "epass_fgeeklasse", value));
                    fgeeklassePassed = true;
                }
            }
            node.removeChild(childNode);
        }
    }
}

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

/**
 * Remove &lt;anzahl_logia&gt; elements.
 * <p>/*from  w ww.j a v a  2  s.c om*/
 * OpenImmo 1.2.4 does not support &lt;anzahl_logia&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.5
 * @throws JaxenException
 */
protected void removeAnzahlLogiaElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:flaechen/io:anzahl_logia", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}

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

/**
 * Remove &lt;erschliessung_umfang&gt; elements.
 * <p>/*from   www  .j  a  v  a  2 s .  c  om*/
 * OpenImmo 1.2.4 does not support &lt;erschliessung_umfang&gt; elements.
 *
 * @param doc OpenImmo document in version 1.2.5
 * @throws JaxenException
 */
protected void removeErschliessungUmfangElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:zustand_angaben/io:erschliessung_umfang", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        Element parentNode = (Element) node.getParentNode();
        parentNode.removeChild(node);
    }
}