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);
}
}
}
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;
}
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);
}
}
}
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();
}
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;
}
Aggregations