Example usage for org.w3c.dom Element removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name) throws DOMException;

Source Link

Document

Removes an attribute by name.

Usage

From source file:org.linguafranca.pwdb.kdbx.dom.DomSerializableDatabase.java

@Override
public SerializableDatabase load(InputStream inputStream) throws IOException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    try {/*from  www  .j  a v  a  2 s .c  om*/
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(inputStream);

        // we need to decrypt all protected fields
        // TODO we assume they are all strings, which is wrong
        NodeList protectedContent = (NodeList) DomHelper.xpath.evaluate("//*[@Protected='True']", doc,
                XPathConstants.NODESET);
        for (int i = 0; i < protectedContent.getLength(); i++) {
            Element element = ((Element) protectedContent.item(i));
            String base64 = DomHelper.getElementContent(".", element);
            // Android compatibility
            byte[] encrypted = Base64.decodeBase64(base64.getBytes());
            String decrypted = new String(encryption.decrypt(encrypted), "UTF-8");
            DomHelper.setElementContent(".", element, decrypted);
            element.removeAttribute("Protected");
        }

        return this;
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException("Instantiating Document Builder", e);
    } catch (SAXException e) {
        throw new IllegalStateException("Parsing exception", e);
    } catch (XPathExpressionException e) {
        throw new IllegalStateException("XPath Exception", e);
    }
}

From source file:org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser.java

/**
 * Determine the bean class corresponding to the supplied {@link Element} based on an
 * explicit "class" attribute./*www  . j  ava 2 s. c om*/
 *
 * @param element the <code>Element</code> that is being parsed
 * @return the {@link Class} of the bean that is being defined via parsing the supplied <code>Element</code>
 *         (must <b>not</b> be <code>null</code>)
 * @see #parseInternal(org.w3c.dom.Element,ParserContext)
 */
protected Class<?> getBeanClassFromAttribute(Element element) {
    String att = beanPropertyConfiguration.getAttributeAlias(ATTRIBUTE_CLASS);
    String className = element.getAttribute(att);
    Class<?> clazz = null;
    if (StringUtils.isNotBlank(className)) {
        try {
            element.removeAttribute(att);
            clazz = ClassUtils.loadClass(className, getClass());
        } catch (ClassNotFoundException e) {
            logger.error("could not load class: " + className, e);
        }
    }
    return clazz;
}

From source file:org.mule.config.spring.parsers.specific.RetryPolicyDefinitionParser.java

@Override
protected void preProcess(Element element) {
    super.preProcess(element);

    // Is this an asynchronous retry policy?
    asynchronous = !Boolean.parseBoolean(element.getAttribute("blocking"));
    element.removeAttribute("blocking");

    // Deprecated attribute from 2.x kept for backwards-compatibility.  Remove for the next major release.
    if (StringUtils.isNotEmpty(element.getAttribute("asynchronous"))) {
        asynchronous = Boolean.parseBoolean(element.getAttribute("asynchronous"));
        element.removeAttribute("asynchronous");
        return;// w w w .j av a 2 s . com
    }
}

From source file:org.nuxeo.runtime.model.persistence.fs.FileSystemStorage.java

@Override
public Contribution updateContribution(Contribution contribution) {
    File file = new File(root, contribution.getName() + ".xml");
    String content = safeRead(file);
    DocumentBuilder docBuilder;//from   ww w.j  av  a2 s.c  om
    try {
        docBuilder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    Document doc;
    try {
        doc = docBuilder.parse(new ByteArrayInputStream(content.getBytes()));
    } catch (SAXException | IOException e) {
        throw new RuntimeException(e);
    }
    Element root = doc.getDocumentElement();
    if (contribution.isDisabled()) {
        root.setAttribute("disabled", "true");
    } else {
        root.removeAttribute("disabled");
    }
    Node node = root.getFirstChild();
    while (node != null) {
        if (node.getNodeType() == Node.ELEMENT_NODE && "documentation".equals(node.getNodeName())) {
            break;
        }
        node = node.getNextSibling();
    }
    String description = contribution.getDescription();
    if (description == null) {
        description = "";
    }
    if (node != null) {
        root.removeChild(node);
    }
    Element el = doc.createElement("documentation");
    el.appendChild(doc.createTextNode(description));
    root.appendChild(el);

    try {
        safeWrite(file, DOMSerializer.toString(doc));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return getContribution(contribution.getName());
}

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

/**
 * Downgrade &lt;befeuerung&gt; elements to OpenImmo 1.1.
 * <p>//ww  w . j av  a2s .  c  o m
 * The attributes "FERN", "BLOCK", "WASSER-ELEKTRO" for &lt;befeuerung&gt;
 * elements are not available in version 1.1.
 * <p>
 * Any occurences of these values are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void downgradeBefeuerungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath(
            "/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:befeuerung[@FERN or @BLOCK or @WASSER-ELEKTRO]",
            doc).selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        node.removeAttribute("FERN");
        node.removeAttribute("BLOCK");
        node.removeAttribute("WASSER-ELEKTRO");
    }
}

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

/**
 * Downgrade &lt;haus&gt; elements to OpenImmo 1.1.
 * <p>/*from  w  ww  . j a va 2  s  . com*/
 * The options "KRANKENHAUS", "PFLEGEHEIM", "SANATORIUM", "SENIORENHEIM",
 * "BETREUTES-WOHNEN" for the "haustyp" attribute of &lt;haus&gt;
 * elements are not available in version 1.1.
 * <p>
 * Any occurence of these values is removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void downgradeHausElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:haus[@haustyp]",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("haustyp"));
        if ("KRANKENHAUS".equalsIgnoreCase(value))
            node.removeAttribute("haustyp");
        else if ("PFLEGEHEIM".equalsIgnoreCase(value))
            node.removeAttribute("haustyp");
        else if ("SANATORIUM".equalsIgnoreCase(value))
            node.removeAttribute("haustyp");
        else if ("SENIORENHEIM".equalsIgnoreCase(value))
            node.removeAttribute("haustyp");
        else if ("BETREUTES-WOHNEN".equalsIgnoreCase(value))
            node.removeAttribute("haustyp");
    }
}

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

/**
 * Downgrade &lt;mieteinnahmen_ist&gt;, &lt;mieteinnahmen_soll&gt; elements
 * to OpenImmo 1.1./*w  w w  .  j a  va  2s  .c  o  m*/
 * <p>
 * The "periode" attribute of the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is not available in version 1.1.
 * <p>
 * Any occurences of these values is removed.
 * <p>
 * The numeric value within the &lt;mieteinnahmen_ist&gt; and
 * &lt;mieteinnahmen_soll&gt; elements is converted according to the value of
 * the "periode" attribute.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void downgradeMieteinnahmenElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath(
                    "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_ist[@periode] |"
                            + "/io:openimmo/io:anbieter/io:immobilie/io:preise/io:mieteinnahmen_soll[@periode]",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;

        String value = StringUtils.trimToNull(node.getTextContent());
        Double numericValue = null;
        try {
            numericValue = (value != null) ? DatatypeConverter.parseDouble(value) : null;
        } catch (Exception ex) {
            String tagName = node.getTagName();
            LOGGER.warn("Can't parse <" + tagName + ">" + value + "</" + tagName + "> as number!");
            LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
        }

        if (numericValue != null && numericValue > 0) {
            String periode = StringUtils.trimToNull(node.getAttribute("periode"));
            if ("MONAT".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 12));
            } else if ("WOCHE".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 52));
            } else if ("TAG".equalsIgnoreCase(periode)) {
                node.setTextContent(DatatypeConverter.printDouble(numericValue * 365));
            }
        }

        node.removeAttribute("periode");
    }
}

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

/**
 * Downgrade &lt;uebertragung&gt; elements to OpenImmo 1.1.
 * <p>//from ww w .j a va  2 s .c  o  m
 * The attributes "senderversion", "regi_id", "modus" for &lt;uebertragung&gt;
 * elements are not available in version 1.1.
 * <p>
 * Any occurences of these values are removed.
 *
 * @param doc OpenImmo document in version 1.2.0
 * @throws JaxenException
 */
protected void downgradeUebertragungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:uebertragung[@senderversion or @regi_id or @modus]", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        node.removeAttribute("senderversion");
        node.removeAttribute("regi_id");
        node.removeAttribute("modus");
    }
}

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

/**
 * Downgrade &lt;haus&gt; elements to OpenImmo 1.2.0.
 * <p>//from   w  ww  . j av a  2 s .com
 * The option "BUNGALOW" for the "haustyp" attribute of &lt;haus&gt;
 * elements is not available in version 1.2.0.
 * <p>
 * Any occurence of these values is removed.
 *
 * @param doc OpenImmo document in version 1.2.1
 * @throws JaxenException
 */
protected void downgradeHausElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:objektkategorie/io:objektart/io:haus[@haustyp]",
                    doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        String value = StringUtils.trimToNull(node.getAttribute("haustyp"));
        if ("BUNGALOW".equalsIgnoreCase(value))
            node.removeAttribute("haustyp");
    }
}

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

/**
 * Downgrade &lt;befeuerung&gt; elements to OpenImmo 1.2.1.
 * <p>//from   w  w w.ja  v a2 s.  c o  m
 * The attribute "LUFTWP" for &lt;befeuerung&gt; elements is not available in
 * version 1.2.1.
 * <p>
 * Any occurences of these values are removed.
 *
 * @param doc OpenImmo document in version 1.2.2
 * @throws JaxenException
 */
protected void downgradeBefeuerungElements(Document doc) throws JaxenException {
    List nodes = XmlUtils
            .newXPath("/io:openimmo/io:anbieter/io:immobilie/io:ausstattung/io:befeuerung[@LUFTWP]", doc)
            .selectNodes(doc);
    for (Object item : nodes) {
        Element node = (Element) item;
        node.removeAttribute("LUFTWP");
    }
}