List of usage examples for org.w3c.dom Attr getName
public String getName();
From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) { Document doc = ptr.getOwnerDocument(); Node parent = ptr.getParentNode(); if (keepSrcElement) { Element replacement = (Element) doc.importNode(src, true); parent.replaceChild(replacement, ptr); return (lval == ptr) ? replacement : lval; }//www .j a v a 2 s.c o m Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName()); NodeList nl = src.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) replacement.appendChild(doc.importNode(nl.item(i), true)); NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true)); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually int colonIdx = attr.getValue().indexOf(":"); if (colonIdx > 0) { String prefix = attr.getValue().substring(0, colonIdx); String attrValNs = src.lookupPrefix(prefix); if (attrValNs != null) replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs); } } } parent.replaceChild(replacement, ptr); DOMUtils.copyNSContext(ptr, replacement); return (lval == ptr) ? replacement : lval; }
From source file:org.apache.ode.bpel.rtrep.v2.ASSIGN.java
private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) { Document doc = ptr.getOwnerDocument(); Node parent = ptr.getParentNode(); if (keepSrcElement) { Element replacement = (Element) doc.importNode(src, true); parent.replaceChild(replacement, ptr); return (lval == ptr) ? replacement : lval; }/*from ww w . j a v a2 s. co m*/ Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName()); if (ptr.getPrefix() != null) { replacement.setPrefix(ptr.getPrefix()); } NodeList nl = src.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) replacement.appendChild(doc.importNode(nl.item(i), true)); NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true)); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually int colonIdx = attr.getValue().indexOf(":"); if (colonIdx > 0) { String prefix = attr.getValue().substring(0, colonIdx); String attrValNs = src.lookupPrefix(prefix); if (attrValNs != null) replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs); } } } parent.replaceChild(replacement, ptr); DOMUtils.copyNSContext(ptr, replacement); return (lval == ptr) ? replacement : lval; }
From source file:org.apache.ode.bpel.rtrep.v2.AssignHelper.java
/** * madars.vitolins _at gmail.com - 2009.04.17 - moved from ASSIGN here *///from www . ja v a2s.c om public Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) { Document doc = ptr.getOwnerDocument(); Node parent = ptr.getParentNode(); if (keepSrcElement) { Element replacement = (Element) doc.importNode(src, true); parent.replaceChild(replacement, ptr); return (lval == ptr) ? replacement : lval; } Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getLocalName()); NodeList nl = src.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) replacement.appendChild(doc.importNode(nl.item(i), true)); NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true)); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually int colonIdx = attr.getValue().indexOf(":"); if (colonIdx > 0) { String prefix = attr.getValue().substring(0, colonIdx); String attrValNs = src.lookupPrefix(prefix); if (attrValNs != null) replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs); } } } parent.replaceChild(replacement, ptr); DOMUtils.copyNSContext(ptr, replacement); return (lval == ptr) ? replacement : lval; }
From source file:org.apache.ode.bpel.runtime.AssignHelper.java
private Element replaceElement(Element lval, Element ptr, Element src, boolean keepSrcElement) { Document doc = ptr.getOwnerDocument(); Node parent = ptr.getParentNode(); if (keepSrcElement) { Element replacement = (Element) doc.importNode(src, true); parent.replaceChild(replacement, ptr); return (lval == ptr) ? replacement : lval; }//from w ww .j a va2 s .co m Element replacement = doc.createElementNS(ptr.getNamespaceURI(), ptr.getTagName()); NodeList nl = src.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) replacement.appendChild(doc.importNode(nl.item(i), true)); NamedNodeMap attrs = src.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Attr attr = (Attr) attrs.item(i); if (!attr.getName().startsWith("xmlns")) { replacement.setAttributeNodeNS((Attr) doc.importNode(attrs.item(i), true)); // Case of qualified attribute values, we're forced to add corresponding namespace declaration manually int colonIdx = attr.getValue().indexOf(":"); if (colonIdx > 0) { String prefix = attr.getValue().substring(0, colonIdx); String attrValNs = src.lookupPrefix(prefix); if (attrValNs != null) replacement.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + prefix, attrValNs); } } } parent.replaceChild(replacement, ptr); DOMUtils.copyNSContext(ptr, replacement); return (lval == ptr) ? replacement : lval; }
From source file:org.apache.ode.utils.DOMUtils.java
/** * Fetch the non-null namespace prefix from a {@link Attr} that declares * a namespace. (The DOM APIs will return <code>null</code> for a non-prefixed * declaration.//from www .jav a 2 s . co m * @param a the {@link Attr} with the declaration (must be non-<code>null</code). * @return the namespace prefix or <code>""</code> if none was * declared, e.g., <code>xmlns="foo"</code>. */ public static String getNSPrefixFromNSAttr(Attr a) { assert a != null; assert isNSAttribute(a); if (a.getPrefix() == null) { return ""; } return a.getName().substring(a.getPrefix().length() + 1); }
From source file:org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil.java
/** * Copy the attribues on one element to the other *//*from ww w . j ava2 s.com*/ public static void copyAttributes(Element from, Element to) { // lets copy across all the remainingattributes NamedNodeMap attributes = from.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr node = (Attr) attributes.item(i); to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue()); } }
From source file:org.apache.strutsel.taglib.utils.DOMHelper.java
public static void recordFoundAttributes(org.w3c.dom.Document document, String xpath, Map map) throws TransformerException { CachedXPathAPI xpathAPI = new CachedXPathAPI(); Node foundNode = xpathAPI.selectSingleNode(document.getDocumentElement(), xpath); if (foundNode != null) { NamedNodeMap attrMap = foundNode.getAttributes(); for (int ctr = 0; ctr < attrMap.getLength(); ++ctr) { Attr attrNode = (Attr) attrMap.item(ctr); map.put(attrNode.getName(), attrNode.getValue()); }/* www. j a v a2 s . co m*/ } }
From source file:org.apache.strutsel.taglib.utils.DOMHelper.java
public static void printNode(Node node, int level) { if (node == null) return;//from www. j a va 2 s .c o m String nodeName = node.getNodeName(); NodeList children = node.getChildNodes(); if (children != null) { short nodeType = node.getNodeType(); if (nodeType == Node.TEXT_NODE) { String text = ((Text) node).getData(); System.out.print(text); } else { System.out.print(spaces.substring(0, level) + "<" + nodeName); NamedNodeMap nodeMap = node.getAttributes(); if (nodeMap.getLength() > 0) { StringBuffer sb = new StringBuffer(); for (int ctr = 0; ctr < nodeMap.getLength(); ++ctr) { Attr attrnode = (Attr) nodeMap.item(ctr); String name = attrnode.getName(); String value = attrnode.getValue(); sb.append(" " + name + "=\"" + value + "\""); } System.out.print(sb.toString()); } System.out.println(">"); } for (int ctr = 0; ctr < children.getLength(); ++ctr) { Node child = children.item(ctr); printNode(child, level + 1); } if (nodeType != Node.TEXT_NODE) System.out.println(spaces.substring(0, level) + "</" + nodeName + ">"); } else System.out.println(spaces.substring(0, level) + "<" + nodeName + "/>"); }
From source file:org.apache.ws.security.util.WSSecurityUtil.java
public static String getPrefixNS(String uri, Node e) { while (e != null && (e.getNodeType() == Element.ELEMENT_NODE)) { NamedNodeMap attrs = e.getAttributes(); for (int n = 0; n < attrs.getLength(); n++) { Attr a = (Attr) attrs.item(n); String name = a.getName(); if (name.startsWith("xmlns:") && a.getNodeValue().equals(uri)) { return name.substring(6); }//from w w w.jav a 2s . com } e = e.getParentNode(); } return null; }
From source file:org.apache.xml.security.utils.IdResolver.java
public static int isElement(Element el, String id, Element[] els) { if (!el.hasAttributes()) { return 0; }//from w w w . jav a 2 s . c o m NamedNodeMap ns = el.getAttributes(); int elementIndex = names.indexOf(el.getNamespaceURI()); elementIndex = (elementIndex < 0) ? namesLength : elementIndex; for (int length = ns.getLength(), i = 0; i < length; i++) { Attr n = (Attr) ns.item(i); String s = n.getNamespaceURI(); int index = s == null ? elementIndex : names.indexOf(n.getNamespaceURI()); index = (index < 0) ? namesLength : index; String name = n.getLocalName(); if (name == null) { name = n.getName(); } if (name.length() > 2) { continue; } String value = n.getNodeValue(); if (name.charAt(0) == 'I') { char ch = name.charAt(1); if (ch == 'd' && value.equals(id)) { els[index] = el; if (index == 0) { return 1; } } else if (ch == 'D' && value.endsWith(id)) { if (index != 3) { index = namesLength; } els[index] = el; } } else if ("id".equals(name) && value.equals(id)) { if (index != 2) { index = namesLength; } els[index] = el; } } //For an element namespace search for importants if ((elementIndex == 3) && (el.getAttribute("OriginalRequestID").equals(id) || el.getAttribute("RequestID").equals(id) || el.getAttribute("ResponseID").equals(id))) { els[3] = el; } else if ((elementIndex == 4) && (el.getAttribute("AssertionID").equals(id))) { els[4] = el; } else if ((elementIndex == 5) && (el.getAttribute("RequestID").equals(id) || el.getAttribute("ResponseID").equals(id))) { els[5] = el; } return 0; }