protected Element importElement(Element element) { Document document = getOwnerDocument(); Document oldDocument = element.getOwnerDocument(); if (!oldDocument.equals(document)) { return (Element) document.importNode(element, true); } else { return element; } }
private static String getAttributeValueFrom( Element element, String uri, String localName, String prefix, String qualifiedName) { String nonzeroLengthUri = (uri == null || uri.length() == 0) ? null : uri; boolean mustUseGetAttributeNodeNS = (nonzeroLengthUri != null); if (mustUseGetAttributeNodeNS) { if (!element.hasAttributeNS(uri, localName)) { return null; } String attrValue = element.getAttributeNS(nonzeroLengthUri, localName); return attrValue; } Attr attribute = null; attribute = element.getAttributeNode(qualifiedName); return attribute == null ? null : attribute.getValue(); }
protected static SOAPElement replaceElementWithSOAPElement(Element element, ElementImpl copy) { Iterator eachAttribute = getAllAttributesFrom(element); while (eachAttribute.hasNext()) { Name name = (Name) eachAttribute.next(); copy.addAttributeBare(name, getAttributeValueFrom(element, name)); } Iterator eachChild = getChildElementsFrom(element); while (eachChild.hasNext()) { Node nextChild = (Node) eachChild.next(); copy.insertBefore(nextChild, null); } Node parent = element.getParentNode(); if (parent != null) { parent.replaceChild(copy, element); } // XXX else throw an exception? return copy; }
protected static Iterator getAllAttributesFrom(final Element element) { final NamedNodeMap attributes = element.getAttributes(); return new Iterator() { int attributesLength = attributes.getLength(); int attributeIndex = 0; String currentName; public boolean hasNext() { return attributeIndex < attributesLength; } public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } Node current = attributes.item(attributeIndex++); currentName = current.getNodeName(); String prefix = NameImpl.getPrefixFromTagName(currentName); if (prefix.length() == 0) { return NameImpl.createFromUnqualifiedName(currentName); } else { Name attributeName = NameImpl.createFromQualifiedName(currentName, current.getNamespaceURI()); return attributeName; } } public void remove() { if (currentName == null) { throw new IllegalStateException(); } attributes.removeNamedItem(currentName); } }; }