Search in sources :

Example 71 with Attr

use of org.w3c.dom.Attr in project jackrabbit by apache.

the class PrivilegeXmlHandler method updateNamespaceMapping.

/**
     * Update the specified namespace mappings with the namespace declarations
     * defined by the given XML element.
     * 
     * @param elem
     * @param namespaces
     */
private static void updateNamespaceMapping(Element elem, Map<String, String> namespaces) {
    NamedNodeMap attributes = elem.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (attr.getName().startsWith(ATTR_XMLNS)) {
            String prefix = attr.getName().substring(ATTR_XMLNS.length());
            String uri = attr.getValue();
            namespaces.put(prefix, uri);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 72 with Attr

use of org.w3c.dom.Attr in project jackrabbit by apache.

the class DOMWalker method getNamespaces.

/**
     * Returns the namespace mappings defined in the current element.
     * The returned property set contains the prefix to namespace
     * mappings specified by the <code>xmlns</code> attributes of the
     * current element.
     *
     * @return prefix to namespace mappings of the current element
     */
public Properties getNamespaces() {
    Properties namespaces = new Properties();
    NamedNodeMap attributes = current.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attribute = (Attr) attributes.item(i);
        if (attribute.getName().startsWith("xmlns:")) {
            namespaces.setProperty(attribute.getName().substring(6), attribute.getValue());
        }
    }
    return namespaces;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Properties(java.util.Properties) Attr(org.w3c.dom.Attr)

Example 73 with Attr

use of org.w3c.dom.Attr in project jackrabbit by apache.

the class ExportDocViewTest method compareNode.

/**
     * Compares the given node with the given element. Comparison is succesful
     * if the number of exported child nodes and exported properties match the
     * found child elements and attributes considering the possible exceptions
     * and if the comparison of the properties of the node with the attributes
     * of the element is successful too.
     *
     * @param node
     * @param elem
     * @throws RepositoryException
     */
private void compareNode(Node node, Element elem) throws RepositoryException, IOException {
    // count the child nodes and compare with the exported child elements
    compareChildNumber(node, elem);
    // count the properties and compare with attributes exported
    comparePropNumber(node, elem);
    PropertyIterator propIter = node.getProperties();
    while (propIter.hasNext()) {
        Property prop = propIter.nextProperty();
        Attr attr = findAttribute(prop, elem);
        checkAttribute(prop, attr);
        if (attr != null) {
            compareProperty(prop, attr);
        }
    }
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) Attr(org.w3c.dom.Attr)

Example 74 with Attr

use of org.w3c.dom.Attr in project logging-log4j2 by apache.

the class XmlConfiguration method getType.

private String getType(final Element element) {
    if (strict) {
        final NamedNodeMap attrs = element.getAttributes();
        for (int i = 0; i < attrs.getLength(); ++i) {
            final org.w3c.dom.Node w3cNode = attrs.item(i);
            if (w3cNode instanceof Attr) {
                final Attr attr = (Attr) w3cNode;
                if (attr.getName().equalsIgnoreCase("type")) {
                    final String type = attr.getValue();
                    attrs.removeNamedItem(attr.getName());
                    return type;
                }
            }
        }
    }
    return element.getTagName();
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 75 with Attr

use of org.w3c.dom.Attr in project jackrabbit by apache.

the class ValueUtil method valueToXml.

public static Element valueToXml(Value jcrValue, Document document) throws RepositoryException {
    String type = PropertyType.nameFromValue(jcrValue.getType());
    String serializedValue = ValueHelper.serialize(jcrValue, true);
    Element xmlValue = document.createElementNS(JcrRemotingConstants.NS_URI, JcrRemotingConstants.NS_PREFIX + ":" + JcrRemotingConstants.XML_VALUE);
    Text txt = document.createTextNode(serializedValue);
    xmlValue.appendChild(txt);
    Attr attr = document.createAttributeNS(JcrRemotingConstants.NS_URI, JcrRemotingConstants.NS_PREFIX + ":" + JcrRemotingConstants.ATTR_VALUE_TYPE);
    attr.setValue(type);
    xmlValue.setAttributeNodeNS(attr);
    return xmlValue;
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) Attr(org.w3c.dom.Attr)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6