You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/08/30 20:17:12 UTC
svn commit: r1379045 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/
axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
Author: veithen
Date: Thu Aug 30 18:17:12 2012
New Revision: 1379045
URL: http://svn.apache.org/viewvc?rev=1379045&view=rev
Log:
Ensure that DOM attributes representing namespace declarations retain their identity, i.e. that querying such an attribute returns the same/original instance, not an instance generated on the fly.
This change should also solve the issue with the patch proposed in AXIOM-423.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1379045&r1=1379044&r2=1379045&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java Thu Aug 30 18:17:12 2012
@@ -18,6 +18,7 @@
*/
package org.apache.axiom.ts.dom;
+import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.axiom.testutils.conformance.ConformanceTestFile;
@@ -112,7 +113,10 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSReplace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSWrongDocument(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeWrongDocument(dbf));
- addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, "urn:ns2", "q", "attr", "value"));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, null, null, "attr", "value"));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", "ns", "urn:ns"));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, XMLConstants.XMLNS_ATTRIBUTE_NS_URI, null, "xmlns", "urn:ns"));
addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithoutNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNull(dbf));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java?rev=1379045&r1=1379044&r2=1379045&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java Thu Aug 30 18:17:12 2012
@@ -27,21 +27,38 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
public class TestSetAttributeNS extends DOMTestCase {
- public TestSetAttributeNS(DocumentBuilderFactory dbf) {
+ private final String namespaceURI;
+ private final String prefix;
+ private final String localName;
+ private final String name;
+ private final String value;
+
+ public TestSetAttributeNS(DocumentBuilderFactory dbf, String namespaceURI, String prefix, String localName, String value) {
super(dbf);
+ this.namespaceURI = namespaceURI;
+ this.prefix = prefix;
+ this.localName = localName;
+ name = prefix == null ? localName : prefix + ":" + localName;
+ this.value = value;
+ addTestProperty("uri", namespaceURI == null ? "" : namespaceURI);
+ addTestProperty("name", name);
}
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS("urn:ns1", "p:element");
- element.setAttributeNS("urn:ns2", "q:attr", "value");
+ element.setAttributeNS(namespaceURI, name, value);
+ assertTrue(element.hasAttributes());
NamedNodeMap attributes = element.getAttributes();
assertEquals(1, attributes.getLength());
Attr attr = (Attr)attributes.item(0);
- assertEquals("urn:ns2", attr.getNamespaceURI());
- assertEquals("q", attr.getPrefix());
- assertEquals("attr", attr.getLocalName());
- assertEquals("value", attr.getValue());
- assertSame(attr, element.getAttributeNodeNS("urn:ns2", "attr"));
+ assertSame(document, attr.getOwnerDocument());
+ assertSame(element, attr.getOwnerElement());
+ assertEquals(namespaceURI, attr.getNamespaceURI());
+ assertEquals(prefix, attr.getPrefix());
+ assertEquals(localName, attr.getLocalName());
+ assertEquals(name, attr.getName());
+ assertEquals(value, attr.getValue());
+ assertSame(attr, element.getAttributeNodeNS(namespaceURI, localName));
}
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java?rev=1379045&r1=1379044&r2=1379045&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java Thu Aug 30 18:17:12 2012
@@ -19,7 +19,6 @@
package org.apache.axiom.om.impl.dom;
-import org.apache.axiom.om.OMCloneOptions;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -216,26 +215,6 @@ public class AttributeMap implements Nam
return previous;
}
- void cloneContent(OMCloneOptions options, AttributeMap srcmap) {
- Vector srcnodes = srcmap.nodes;
- if (srcnodes != null) {
- int size = srcnodes.size();
- if (size != 0) {
- if (nodes == null) {
- nodes = new Vector(size);
- }
- nodes.setSize(size);
- for (int i = 0; i < size; ++i) {
- AttrImpl n = (AttrImpl) srcnodes.elementAt(i);
- AttrImpl clone = (AttrImpl)n.clone(options, null, true, false);
- clone.isSpecified(n.isSpecified());
- nodes.setElementAt(clone, i);
- clone.setOwnerElement(ownerNode, true);
- }
- }
- }
- }
-
/**
* From org.apache.xerces.dom.NamedNodeMapImpl
* <p/>
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1379045&r1=1379044&r2=1379045&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Thu Aug 30 18:17:12 2012
@@ -59,7 +59,6 @@ import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
/** Implementation of the org.w3c.dom.Element and org.apache.axiom.om.Element interfaces. */
@@ -98,14 +97,8 @@ public class ElementImpl extends ParentN
private AttributeMap attributes;
- private HashMap namespaces;
-
private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator();
- private static final OMNamespace XMLNS_NAMESPACE_WITH_PREFIX = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX);
-
- private static final OMNamespace XMLNS_NAMESPACE_WITHOUT_PREFIX = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, null);
-
public ElementImpl(ParentNode parentNode, String localName, OMNamespace ns, OMXMLParserWrapper builder,
OMFactory factory, boolean generateNSDecl) {
super(factory);
@@ -259,13 +252,6 @@ public class ElementImpl extends ParentN
* @see org.w3c.dom.Element#removeAttribute(String)
*/
public void removeAttribute(String name) throws DOMException {
- if (name.startsWith(OMConstants.XMLNS_NS_PREFIX)) {
- String namespacePrefix = DOMUtil.getLocalName(name);
- if (this.findNamespaceURI(namespacePrefix) != null) {
- this.removeNamespace(namespacePrefix);
- }
- }
-
if (this.attributes != null) {
this.attributes.removeNamedItem(name);
}
@@ -279,13 +265,7 @@ public class ElementImpl extends ParentN
*/
public void removeAttributeNS(String namespaceURI, String localName)
throws DOMException {
- if (OMConstants.XMLNS_NS_URI.equals(namespaceURI)) {
- //look in the ns list
- if (this.namespaces != null) {
- this.namespaces.remove(DOMUtil.getLocalName(localName));
- }
-
- } else if (this.attributes != null) {
+ if (this.attributes != null) {
this.attributes.removeNamedItemNS(namespaceURI, localName);
}
}
@@ -367,21 +347,8 @@ public class ElementImpl extends ParentN
* @see org.w3c.dom.Element#getAttributeNodeNS(String, String)
*/
public Attr getAttributeNodeNS(String namespaceURI, String localName) {
-
- if (OMConstants.XMLNS_NS_URI.equals(namespaceURI)) {
- OMNamespace ns = this.findNamespaceURI(localName);
- String nsuri = ns != null ? ns.getNamespaceURI() : "";
-
- AttrImpl namespaceAttr = new AttrImpl(ownerDocument(),
- localName, nsuri, this.factory);
- OMNamespaceImpl xmlNs = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, null);
- namespaceAttr.setOMNamespace(xmlNs);
- return namespaceAttr;
- }
-
return (this.attributes == null) ? null : (Attr) this.attributes
.getNamedItemNS(namespaceURI, localName);
-
}
/**
@@ -444,43 +411,34 @@ public class ElementImpl extends ParentN
}
public Attr setAttributeNodeNS(Attr attr) throws DOMException {
- return setAttributeNodeNS(attr, true);
+ return setAttributeNodeNS(attr, true, false);
}
- private Attr setAttributeNodeNS(Attr attr, boolean useDomSemantics) throws DOMException {
-
- // Check whether the attr is a namespace declaration
- // if so add a namespace NOT an attribute
- if (attr.getNamespaceURI() != null
- && attr.getNamespaceURI().equals(OMConstants.XMLNS_NS_URI)) {
- this.declareNamespace(attr.getName(), attr.getValue());
- return attr;
- } else {
- AttrImpl attrImpl = (AttrImpl) attr;
-
- if (useDomSemantics) {
- checkSameOwnerDocument(attr);
- }
+ private Attr setAttributeNodeNS(Attr attr, boolean useDomSemantics, boolean generateNSDecl) throws DOMException {
+ AttrImpl attrImpl = (AttrImpl) attr;
- // check whether the attr is in use
- attrImpl.checkInUse();
+ if (useDomSemantics) {
+ checkSameOwnerDocument(attr);
+ }
- if (this.attributes == null) {
- this.attributes = new AttributeMap(this);
- }
+ // check whether the attr is in use
+ attrImpl.checkInUse();
- // handle the namespaces
- if (!useDomSemantics && attr.getNamespaceURI() != null
- && findNamespace(attr.getNamespaceURI(), attr.getPrefix())
- == null) {
- // TODO checkwhether the same ns is declared with a different
- // prefix and remove it
- this.declareNamespace(new OMNamespaceImpl(attr.getNamespaceURI(),
- attr.getPrefix()));
- }
+ if (this.attributes == null) {
+ this.attributes = new AttributeMap(this);
+ }
- return (Attr) this.attributes.setAttribute(attr, useDomSemantics);
+ // handle the namespaces
+ if (generateNSDecl && attr.getNamespaceURI() != null
+ && findNamespace(attr.getNamespaceURI(), attr.getPrefix())
+ == null) {
+ // TODO checkwhether the same ns is declared with a different
+ // prefix and remove it
+ this.declareNamespace(new OMNamespaceImpl(attr.getNamespaceURI(),
+ attr.getPrefix()));
}
+
+ return (Attr) this.attributes.setAttribute(attr, useDomSemantics);
}
/**
@@ -492,17 +450,12 @@ public class ElementImpl extends ParentN
String value) throws DOMException {
if (namespaceURI != null && !"".equals(namespaceURI)) {
- if (namespaceURI.equals(OMConstants.XMLNS_NS_URI)) {
- this.declareNamespace(value, DOMUtil
- .getLocalName(qualifiedName));
- } else {
- AttrImpl attr = new AttrImpl(ownerDocument(), DOMUtil
- .getLocalName(qualifiedName), value, this.factory);
- attr.setOMNamespace(new OMNamespaceImpl(namespaceURI, DOMUtil
- .getPrefix(qualifiedName)));
+ AttrImpl attr = new AttrImpl(ownerDocument(), DOMUtil
+ .getLocalName(qualifiedName), value, this.factory);
+ attr.setOMNamespace(new OMNamespaceImpl(namespaceURI, DOMUtil
+ .getPrefix(qualifiedName)));
- this.setAttributeNodeNS(attr);
- }
+ this.setAttributeNodeNS(attr);
} else {
// When the namespace is null, the attr name given better not be
// a qualified name
@@ -567,10 +520,7 @@ public class ElementImpl extends ParentN
/** Returns whether this element contains any attribute or not. */
public boolean hasAttributes() {
- // DOM represents namespace declarations as attributes; therefore
- // we need to check both "attributes" and "namespaces"
- return attributes != null && attributes.getLength() > 0
- || namespaces != null && !namespaces.isEmpty();
+ return attributes != null && attributes.getLength() > 0;
}
/*
@@ -640,7 +590,7 @@ public class ElementImpl extends ParentN
}
}
- this.setAttributeNodeNS((Attr) attr, false);
+ this.setAttributeNodeNS((Attr) attr, false, true);
return attr;
}
@@ -660,12 +610,8 @@ public class ElementImpl extends ParentN
}
public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
- if (namespaces == null) {
- this.namespaces = new HashMap(5);
- }
- OMNamespace ns = new OMNamespaceImpl(uri, prefix);
- namespaces.put(prefix, ns);
- return ns;
+ setAttributeNS(OMConstants.XMLNS_NS_URI, prefix.length() == 0 ? OMConstants.XMLNS_NS_PREFIX : OMConstants.XMLNS_NS_PREFIX + ":" + prefix, uri);
+ return new OMNamespaceImpl(uri, prefix);
}
/**
@@ -674,10 +620,6 @@ public class ElementImpl extends ParentN
* @see org.apache.axiom.om.OMElement#declareNamespace (org.apache.axiom.om.OMNamespace)
*/
public OMNamespace declareNamespace(OMNamespace namespace) {
- if (namespaces == null) {
- this.namespaces = new HashMap(5);
- }
-
if (namespace != null) {
String prefix = namespace.getPrefix();
if (prefix == null) {
@@ -689,17 +631,14 @@ public class ElementImpl extends ParentN
}
if (!namespace.getPrefix().startsWith(OMConstants.XMLNS_NS_PREFIX)) {
- namespaces.put(namespace.getPrefix(), namespace);
+ setAttributeNS(OMConstants.XMLNS_NS_URI, prefix.length() == 0 ? OMConstants.XMLNS_NS_PREFIX : OMConstants.XMLNS_NS_PREFIX + ":" + prefix, namespace.getNamespaceURI());
}
}
return namespace;
}
public void undeclarePrefix(String prefix) {
- if (namespaces == null) {
- this.namespaces = new HashMap(5);
- }
- namespaces.put(prefix, new OMNamespaceImpl("", prefix));
+ setAttributeNS(OMConstants.XMLNS_NS_URI, prefix.length() == 0 ? OMConstants.XMLNS_NS_PREFIX : OMConstants.XMLNS_NS_PREFIX + ":" + prefix, "");
}
public OMNamespace declareNamespace(String uri, String prefix) {
@@ -719,20 +658,15 @@ public class ElementImpl extends ParentN
"the namespace information of the element");
}
- OMNamespaceImpl ns = new OMNamespaceImpl(uri, "");
- if (namespaces == null) {
- this.namespaces = new HashMap(5);
- }
- namespaces.put("", ns);
- return ns;
+ setAttributeNS(OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX, uri);
+ return new OMNamespaceImpl(uri, "");
}
public OMNamespace getDefaultNamespace() {
- if (namespaces != null) {
- OMNamespaceImpl defaultNS = (OMNamespaceImpl) namespaces.get("");
- if (defaultNS != null) {
- return defaultNS.getNamespaceURI().length() == 0 ? null : defaultNS;
- }
+ Attr decl = (Attr)attributes.getNamedItemNS(OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX);
+ if (decl != null) {
+ String uri = decl.getValue();
+ return uri.length() == 0 ? null : new OMNamespaceImpl(uri, "");
}
ParentNode parentNode = parentNode();
@@ -778,23 +712,24 @@ public class ElementImpl extends ParentN
}
public OMNamespace findNamespaceURI(String prefix) {
- OMNamespace ns = this.namespaces == null ?
- null :
- (OMNamespace) this.namespaces.get(prefix);
-
- if (ns == null) {
- ParentNode parentNode = parentNode();
- if (parentNode instanceof OMElement) {
- // try with the parent
- return ((OMElement)parentNode).findNamespaceURI(prefix);
- } else {
- return null;
+ if (attributes != null) {
+ Attr decl = (Attr)attributes.getNamedItemNS(OMConstants.XMLNS_NS_URI, prefix.length() == 0 ? OMConstants.XMLNS_NS_PREFIX : prefix);
+ if (decl != null) {
+ String namespaceURI = decl.getValue();
+ if (prefix != null && prefix.length() > 0 && namespaceURI.length() == 0) {
+ // Prefix undeclaring case (XML 1.1 only)
+ return null;
+ } else {
+ return new OMNamespaceImpl(namespaceURI, prefix);
+ }
}
- } else if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length() == 0) {
- // Prefix undeclaring case (XML 1.1 only)
- return null;
+ }
+ ParentNode parentNode = parentNode();
+ if (parentNode instanceof OMElement) {
+ // try with the parent
+ return ((OMElement)parentNode).findNamespaceURI(prefix);
} else {
- return ns;
+ return null;
}
}
@@ -805,7 +740,9 @@ public class ElementImpl extends ParentN
private OMNamespace findDeclaredNamespace(String uri, String prefix) {
if (uri == null) {
- return namespaces == null ? null : (OMNamespace)namespaces.get(prefix);
+ Attr decl = (Attr)attributes.getNamedItemNS(OMConstants.XMLNS_NS_URI,
+ prefix.length() == 0 ? OMConstants.XMLNS_NS_PREFIX : prefix);
+ return decl == null ? null : new OMNamespaceImpl(decl.getValue(), prefix);
}
// If the prefix is available and uri is available and its the xml
// namespace
@@ -814,24 +751,23 @@ public class ElementImpl extends ParentN
return new OMNamespaceImpl(uri, prefix);
}
- if (namespaces == null) {
- return null;
- }
-
if (prefix == null || "".equals(prefix)) {
- Iterator namespaceListIterator = namespaces.values().iterator();
- while (namespaceListIterator.hasNext()) {
- OMNamespace omNamespace = (OMNamespace) namespaceListIterator.next();
- String nsURI = omNamespace.getNamespaceURI();
- if (nsURI != null && nsURI.equals(uri)) {
- return omNamespace;
+ for (int i=0; i<attributes.getLength(); i++) {
+ Attr attr = (Attr)attributes.item(i);
+ if (OMConstants.XMLNS_NS_URI.equals(attr.getNamespaceURI())) {
+ String declaredUri = attr.getValue();
+ if (declaredUri.equals(uri)) {
+ return new OMNamespaceImpl(uri, attr.getPrefix() == null ? "" : attr.getLocalName());
+ }
}
}
-
} else {
- OMNamespace namespace = (OMNamespace) namespaces.get(prefix);
- if (namespace != null && uri.equals(namespace.getNamespaceURI())) {
- return namespace;
+ Attr decl = (Attr)attributes.getNamedItemNS(OMConstants.XMLNS_NS_URI, prefix);
+ if (decl != null) {
+ String declaredUri = decl.getValue();
+ if (declaredUri.equals(uri)) {
+ return new OMNamespaceImpl(uri, prefix);
+ }
}
}
@@ -1037,10 +973,7 @@ public class ElementImpl extends ParentN
/** @see org.apache.axiom.om.OMElement#getAllDeclaredNamespaces() */
public Iterator getAllDeclaredNamespaces() throws OMException {
- if (namespaces == null) {
- return EMPTY_ITERATOR;
- }
- return namespaces.values().iterator();
+ return new NSDeclIterator(attributes);
}
public Iterator getNamespacesInScope() {
@@ -1120,18 +1053,11 @@ public class ElementImpl extends ParentN
} else {
clone = new ElementImpl(targetParent, localName, namespace, null, factory, namespaceRepairing);
}
- for (Iterator it = getAllDeclaredNamespaces(); it.hasNext(); ) {
- OMNamespace ns = (OMNamespace)it.next();
- clone.declareNamespace(ns);
- }
- clone.attributes.cloneContent(options, attributes);
- if (namespaceRepairing) {
- for (Iterator it = getAllAttributes(); it.hasNext(); ) {
- OMNamespace ns = ((OMAttribute)it.next()).getNamespace();
- if (ns != null) {
- clone.declareNamespace(ns);
- }
- }
+ for (int i=0, l=attributes.getLength(); i<l; i++) {
+ AttrImpl attr = (AttrImpl)attributes.item(i);
+ AttrImpl clonedAttr = (AttrImpl)attr.clone(options, null, true, false);
+ clonedAttr.isSpecified(attr.isSpecified());
+ clone.setAttributeNodeNS(clonedAttr, false, namespaceRepairing && !OMConstants.XMLNS_NS_URI.equals(attr.getNamespaceURI()));
}
return clone;
}
@@ -1150,36 +1076,7 @@ public class ElementImpl extends ParentN
/** Returns the set of attributes of this node and the namespace declarations available. */
public NamedNodeMap getAttributes() {
- AttributeMap attributeMap = new AttributeMap(this);
-
- // Add the set of existing attrs
- for (int i = 0; i < this.attributes.getLength(); i++) {
- attributeMap.addItem((Attr) this.attributes.getItem(i));
- }
-
- // Add the NS declarations
- if (this.namespaces != null) {
- Iterator nsDecls = this.namespaces.keySet().iterator();
- while (nsDecls.hasNext()) {
- String prefix = (String) nsDecls.next();
- if (prefix != null){
-
- OMNamespace ns = (OMNamespace)this.namespaces.get(prefix);
-
- if ("".equals(prefix)) {
- AttrImpl attr = new AttrImpl(ownerDocument(), "xmlns", ns.getNamespaceURI(), this.factory);
- attr.setOMNamespace(XMLNS_NAMESPACE_WITHOUT_PREFIX);
- attributeMap.addItem(attr);
- } else {
- AttrImpl attr = new AttrImpl(ownerDocument(), prefix, ns.getNamespaceURI(), this.factory);
- attr.setOMNamespace(XMLNS_NAMESPACE_WITH_PREFIX);
- attributeMap.addItem(attr);
- }
- }
- }
- }
-
- return attributeMap;
+ return attributes;
}
/**
@@ -1194,22 +1091,6 @@ public class ElementImpl extends ParentN
return (ns != null) ? ns.getNamespaceURI() : null;
}
- /**
- * Removes a declared namespace given its prefix.
- *
- * @param prefix
- * @return Returns whether the namespace relevant to the given prefix was removed or not
- */
- public boolean removeNamespace(String prefix) {
- Object ns = this.namespaces.get(prefix);
- if (ns != null) {
- this.namespaces.remove(prefix);
- return true;
- } else {
- return false;
- }
- }
-
public void discard() throws OMException {
OMElementImplUtil.discard(this);
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java?rev=1379045&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java Thu Aug 30 18:17:12 2012
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.dom;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMConstants;
+import org.apache.axiom.om.impl.common.OMNamespaceImpl;
+import org.w3c.dom.Attr;
+
+class NSDeclIterator implements Iterator {
+ private final AttributeMap attributes;
+ private boolean hasNextCalled;
+ private int index = -1;
+ private Attr nsDecl;
+
+ public NSDeclIterator(AttributeMap attributes) {
+ this.attributes = attributes;
+ }
+
+ public boolean hasNext() {
+ if (!hasNextCalled) {
+ while (true) {
+ index++;
+ if (index >= attributes.getLength()) {
+ nsDecl = null;
+ hasNextCalled = true;
+ break;
+ }
+ Attr attr = (Attr)attributes.item(index);
+ if (OMConstants.XMLNS_NS_URI.equals(attr.getNamespaceURI())) {
+ nsDecl = attr;
+ hasNextCalled = true;
+ break;
+ }
+ }
+ }
+ return nsDecl != null;
+ }
+
+ public Object next() {
+ hasNext();
+ hasNextCalled = false;
+ return new OMNamespaceImpl(nsDecl.getValue(), nsDecl.getPrefix() == null ? "" : nsDecl.getLocalName());
+ }
+
+ public void remove() {
+ if (hasNextCalled || nsDecl == null) {
+ throw new IllegalStateException();
+ }
+ attributes.removeItem(index);
+ nsDecl = null;
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NSDeclIterator.java
------------------------------------------------------------------------------
svn:eol-style = native