ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1381121 - in /webservices/commons/trunk/modules/axiom/modules/axiom-dom/src: main/java/org/apache/axiom/om/impl/dom/ test/java/org/apache/axiom/om/impl/dom/
Date Wed, 05 Sep 2012 09:58:46 GMT
Author: veithen
Date: Wed Sep  5 09:58:46 2012
New Revision: 1381121

URL: http://svn.apache.org/viewvc?rev=1381121&view=rev
Log:
Fixed a couple of DOOM issues.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    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-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java?rev=1381121&r1=1381120&r2=1381121&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
Wed Sep  5 09:58:46 2012
@@ -19,6 +19,8 @@
 
 package org.apache.axiom.om.impl.dom;
 
+import javax.xml.XMLConstants;
+
 import org.w3c.dom.DOMException;
 
 /** Utility class for the OM-DOM implementation */
@@ -30,8 +32,7 @@ class DOMUtil {
         return true;
     }
 
-    public static boolean isValidNamespace(String namespaceURI,
-                                           String qualifiedname) {
+    public static void validateAttrNamespace(String namespaceURI, String localName, String
prefix) {
         // TODO check for valid namespace
         /**
          * if the qualifiedName has a prefix and the namespaceURI is null, if
@@ -40,9 +41,21 @@ class DOMUtil {
          * qualifiedName, or its prefix, is "xmlns" and the namespaceURI is
          * different from " http://www.w3.org/2000/xmlns/".
          */
-        // throw new UnsupportedOperationException("TODO");
-        // temporary fix
-        return true;
+        
+        if (namespaceURI == null) {
+            if (localName.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
+            }
+        } else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+            if (prefix != null && !prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)
+                    || prefix == null && !localName.equals(XMLConstants.XMLNS_ATTRIBUTE))
{
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
+            }
+        } else {
+            if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
+            }
+        }
     }
 
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1381121&r1=1381120&r2=1381121&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Wed Sep  5 09:58:46 2012
@@ -131,18 +131,18 @@ public class DocumentImpl extends RootNo
             throws DOMException {
         String localName = DOMUtil.getLocalName(qualifiedName);
         String prefix = DOMUtil.getPrefix(qualifiedName);
+        DOMUtil.validateAttrNamespace(namespaceURI, localName, prefix);
 
         if (!XMLConstants.XMLNS_ATTRIBUTE.equals(localName)) {
             this.checkQName(prefix, localName);
-        } else {
-            return this.createAttribute(localName);
         }
 
         OMNamespace namespace;
         if (namespaceURI == null) {
             namespace = null;
         } else {
-            namespace = new OMNamespaceImpl(namespaceURI, prefix == null ? "" : prefix);
+            namespace = new OMNamespaceImpl(namespaceURI,
+                    prefix == null && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)
? "" : prefix);
         }
         return new AttrImpl(this, localName, namespace, this.factory);
     }

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=1381121&r1=1381120&r2=1381121&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
Wed Sep  5 09:58:46 2012
@@ -444,19 +444,30 @@ public class ElementImpl extends ParentN
      */
     public void setAttributeNS(String namespaceURI, String qualifiedName,
                                String value) throws DOMException {
-
-        if (namespaceURI != null && !"".equals(namespaceURI)) {
-            AttrImpl attr = new AttrImpl(ownerDocument(), DOMUtil
-                    .getLocalName(qualifiedName), value, this.factory);
-            attr.setOMNamespace(new OMNamespaceImpl(namespaceURI, DOMUtil
-                    .getPrefix(qualifiedName)));
-
-            this.setAttributeNodeNS(attr);
-        } else {
-            // When the namespace is null, the attr name given better not be
-            // a qualified name
-            // But anyway check and set it
-            this.setAttribute(DOMUtil.getLocalName(qualifiedName), value);
+        
+        if (namespaceURI != null && namespaceURI.length() == 0) {
+            namespaceURI = null;
+        }
+        String localName = DOMUtil.getLocalName(qualifiedName);
+        String prefix = DOMUtil.getPrefix(qualifiedName);
+        DOMUtil.validateAttrNamespace(namespaceURI, localName, prefix);
+        
+        AttrImpl attr = (AttrImpl)getAttributeNodeNS(namespaceURI, localName);
+        if (attr != null) {
+            attr.setPrefix(prefix);
+            attr.setValue(value);
+        } else {
+            if (namespaceURI != null) {
+                attr = new AttrImpl(ownerDocument(), localName, value, this.factory);
+                attr.setOMNamespace(new OMNamespaceImpl(namespaceURI, prefix));
+    
+                this.setAttributeNodeNS(attr);
+            } else {
+                // When the namespace is null, the attr name given better not be
+                // a qualified name
+                // But anyway check and set it
+                this.setAttribute(localName, value);
+            }
         }
 
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1381121&r1=1381120&r2=1381121&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
Wed Sep  5 09:58:46 2012
@@ -23,21 +23,10 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
 import org.apache.axiom.ts.dom.DOMTestSuiteBuilder;
-import org.apache.axiom.ts.dom.document.TestCreateAttributeNS;
-import org.apache.axiom.ts.dom.document.TestCreateAttributeNSInvalid;
-import org.apache.axiom.ts.dom.element.TestSetAttributeNSExisting;
-import org.apache.axiom.ts.dom.element.TestSetAttributeNSInvalid;
 
 public class DOMImplementationTest extends TestCase {
     public static TestSuite suite() {
         DOMTestSuiteBuilder builder = new DOMTestSuiteBuilder(new OMDOMMetaFactory().newDocumentBuilderFactory());
-        
-        // TODO
-        builder.exclude(TestCreateAttributeNS.class, "(name=xmlns)");
-        builder.exclude(TestCreateAttributeNSInvalid.class);
-        builder.exclude(TestSetAttributeNSInvalid.class);
-        builder.exclude(TestSetAttributeNSExisting.class);
-        
         return builder.build();
     }
 }



Mime
View raw message