You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/12/22 00:41:54 UTC

svn commit: r728554 - in /webservices/commons/trunk/modules/axiom/modules: axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java

Author: veithen
Date: Sun Dec 21 15:41:53 2008
New Revision: 728554

URL: http://svn.apache.org/viewvc?rev=728554&view=rev
Log:
Modified ElementImpl#getNamespaceURI() so that it always returns null (an not an empty string) if the element has no namespace. The DOM spec is not particularly clear about this, but this is the behavior of Xerces and it is also expected by XMLUnit.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java

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=728554&r1=728553&r2=728554&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 Sun Dec 21 15:41:53 2008
@@ -176,7 +176,14 @@
 
     /** Returns the value of the namespace URI. */
     public String getNamespaceURI() {
-        return (this.namespace != null) ? this.namespace.getNamespaceURI().intern() : null;
+        if (this.namespace == null) {
+            return null;
+        } else {
+            // If the element has no namespace, the result should be null, not
+            // an empty string.
+            String uri = this.namespace.getNamespaceURI();
+            return uri.length() == 0 ? null : uri.intern();
+        }
     }
 
     // /

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java?rev=728554&r1=728553&r2=728554&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java Sun Dec 21 15:41:53 2008
@@ -178,4 +178,18 @@
             }
         });
     }
+    
+    public void testGetNamespaceURIWithNoNamespace() throws Exception {
+        DOMTestUtil.execute(new DOMTestUtil.Test() {
+            public void execute(DocumentBuilderFactory dbf) throws Exception {
+                Document doc = dbf.newDocumentBuilder().newDocument();
+                Element element = doc.createElement("test");
+                assertNull(element.getNamespaceURI());
+                element = doc.createElementNS(null, "test");
+                assertNull(element.getNamespaceURI());
+                element = doc.createElementNS("", "test");
+                assertNull(element.getNamespaceURI());
+            }
+        });
+    }
 }