Example usage for org.w3c.dom NamedNodeMap getLength

List of usage examples for org.w3c.dom NamedNodeMap getLength

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap getLength.

Prototype

public int getLength();

Source Link

Document

The number of nodes in this map.

Usage

From source file:com.evolveum.midpoint.util.DOMUtil.java

private static Attr findAttributeByQName(NamedNodeMap attrs, QName qname) {
    for (int i = 0; i < attrs.getLength(); i++) {
        Node aItem = attrs.item(i);
        Attr aAttr = (Attr) aItem;
        if (aAttr.getLocalName() == null) {
            continue;
        }/*from   ww  w . ja v  a2s. c  o  m*/
        QName aQname = new QName(aAttr.getNamespaceURI(), aAttr.getLocalName());
        if (aQname.equals(qname)) {
            return aAttr;
        }
    }
    return null;
}

From source file:org.joy.config.Configuration.java

private Properties parseAttributes(Node node) {
    Properties attributes = new Properties();
    NamedNodeMap nnm = node.getAttributes();
    for (int i = 0; i < nnm.getLength(); i++) {
        Node attribute = nnm.item(i);
        String value = attribute.getNodeValue();
        attributes.put(attribute.getNodeName(), value);
    }/*  w ww  . j a  v a2  s .co  m*/

    return attributes;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static boolean hasApplicationAttributes(Element element) {
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (isApplicationAttribute(attr)) {
            return true;
        }//from  www  . jav  a2  s  .  c o  m
    }
    return false;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static Collection<Attr> listApplicationAttributes(Element element) {
    Collection<Attr> attrs = new ArrayList<Attr>();
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (isApplicationAttribute(attr)) {
            attrs.add(attr);//from   w  w w  . ja  v a2s  .  co m
        }
    }
    return attrs;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static void copyContent(Element source, Element destination) {
    NamedNodeMap attributes = source.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        Attr clone = (Attr) attr.cloneNode(true);
        destination.setAttributeNode(clone);
    }/*  w w w. j a v  a 2s.  co  m*/
    NodeList childNodes = source.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node item = childNodes.item(i);
        destination.appendChild(item);
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

/**
 * Returns map of all namespace declarations from specified element (prefix -> namespace).
 *///from w w  w . j a  va  2 s .c o  m
public static Map<String, String> getNamespaceDeclarations(Element element) {
    Map<String, String> nsDeclMap = new HashMap<String, String>();
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (isNamespaceDefinition(attr)) {
            String prefix = getNamespaceDeclarationPrefix(attr);
            String namespace = getNamespaceDeclarationNamespace(attr);
            nsDeclMap.put(prefix, namespace);
        }
    }
    return nsDeclMap;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static String getNamespaceDeclarationForPrefix(Element targetElement, String prefix) {
    NamedNodeMap attributes = targetElement.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (isNamespaceDefinition(attr)) {
            String thisPrefix = getNamespaceDeclarationPrefix(attr);
            if (comparePrefix(prefix, thisPrefix)) {
                return getNamespaceDeclarationNamespace(attr);
            }/*w  w w  .  j  a  va 2s . com*/
        }
    }
    return null;
}

From source file:com.nridge.core.base.io.xml.DocumentReplyXML.java

/**
 * Parses an XML DOM element and loads it into a document list.
 *
 * @param anElement DOM element.//from   w  ww.j  a v a  2  s  . c o  m
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void load(Element anElement) throws IOException {
    Attr nodeAttr;
    Node nodeItem;
    Document document;
    Element nodeElement;
    DocumentXML documentXML;
    String nodeName, nodeValue;

    nodeName = anElement.getNodeName();
    if (StringUtils.equalsIgnoreCase(nodeName, IO.XML_REPLY_NODE_NAME)) {
        mField.clearFeatures();
        String attrValue = anElement.getAttribute(Doc.FEATURE_OP_STATUS_CODE);
        if (StringUtils.isNotEmpty(attrValue)) {
            mField.setName(Doc.FEATURE_OP_STATUS_CODE);
            mField.setValue(attrValue);
            NamedNodeMap namedNodeMap = anElement.getAttributes();
            int attrCount = namedNodeMap.getLength();
            for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) {
                nodeAttr = (Attr) namedNodeMap.item(attrOffset);
                nodeName = nodeAttr.getNodeName();
                nodeValue = nodeAttr.getNodeValue();

                if (StringUtils.isNotEmpty(nodeValue)) {
                    if ((!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_STATUS_CODE))
                            && (!StringUtils.equalsIgnoreCase(nodeName, Doc.FEATURE_OP_COUNT)))
                        mField.addFeature(nodeName, nodeValue);
                }
            }
        }
        NodeList nodeList = anElement.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            nodeItem = nodeList.item(i);

            if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
                continue;

            // We really do not know how the node was named, so we will just accept it.

            nodeElement = (Element) nodeItem;
            documentXML = new DocumentXML();
            documentXML.load(nodeElement);
            document = documentXML.getDocument();
            if (document != null)
                mDocumentList.add(document);
        }
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static boolean isPrefixUsed(Element targetElement, String prefix) {
    if (comparePrefix(prefix, targetElement.getPrefix())) {
        return true;
    }/*from  w ww.  j  av  a2  s  .c  o m*/
    NamedNodeMap attributes = targetElement.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (comparePrefix(prefix, attr.getPrefix())) {
            return true;
        }
    }
    NodeList childNodes = targetElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            if (isPrefixUsed(element, prefix)) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

private static void fixNamespaceDeclarations(Element targetElement, Element currentElement) {
    NamedNodeMap attributes = currentElement.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (isNamespaceDefinition(attr)) {
            String prefix = getNamespaceDeclarationPrefix(attr);
            String namespace = getNamespaceDeclarationNamespace(attr);
            if (hasNamespaceDeclarationForPrefix(targetElement, prefix)) {
                if (targetElement != currentElement) {
                    // We are processing parent element, while the original element already
                    // has prefix declaration. That means it must have been processed before
                    // we can skip the usage check
                    continue;
                }/*from   ww w  .j av a  2  s .  c o  m*/
            } else {
                setNamespaceDeclaration(targetElement, prefix, getNamespaceDeclarationNamespace(attr));
            }
        }
    }
    Node parentNode = currentElement.getParentNode();
    if (parentNode instanceof Element) {
        fixNamespaceDeclarations(targetElement, (Element) parentNode);
    }
}