You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2006/02/18 05:40:48 UTC

svn commit: r378687 - in /jakarta/commons/proper/digester/trunk/src: java/org/apache/commons/digester/NodeCreateRule.java test/org/apache/commons/digester/NodeCreateRuleTestCase.java test/org/apache/commons/digester/Test10.xml

Author: skitching
Date: Fri Feb 17 20:40:46 2006
New Revision: 378687

URL: http://svn.apache.org/viewcvs?rev=378687&view=rev
Log:
Fix bugzilla#36773, where NodeCreateRule was losing xml attribute prefix when
creating an element to represent an attribute in an input document. Thanks to
Kurt Zettel II for the patch (and for his patience). This potentially causes
an incompatibility with the old version of this class, in that the DOM node
created now (correctly) has a namespace prefix on the QName.

Added:
    jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test10.xml
Modified:
    jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/NodeCreateRule.java
    jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.java

Modified: jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/NodeCreateRule.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/NodeCreateRule.java?rev=378687&r1=378686&r2=378687&view=diff
==============================================================================
--- jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/NodeCreateRule.java (original)
+++ jakarta/commons/proper/digester/trunk/src/java/org/apache/commons/digester/NodeCreateRule.java Fri Feb 17 20:40:46 2006
@@ -397,7 +397,7 @@
                     doc.createElementNS(namespaceURI, name);
                 for (int i = 0; i < attributes.getLength(); i++) {
                     element.setAttributeNS(attributes.getURI(i),
-                                           attributes.getLocalName(i),
+                                           attributes.getQName(i),
                                            attributes.getValue(i));
                 }
             } else {

Modified: jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.java?rev=378687&r1=378686&r2=378687&view=diff
==============================================================================
--- jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.java (original)
+++ jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/NodeCreateRuleTestCase.java Fri Feb 17 20:40:46 2006
@@ -381,6 +381,55 @@
 
     }
 
+    /**
+     * Tests whether namespaced attributes are handled correctly, using the example from 
+     * the file Test10 XML file.
+     */
+    public void testNamespacedAttribute()
+        throws SAXException, ParserConfigurationException, IOException {
+        
+        digester.setNamespaceAware(true);
+        digester.setRuleNamespaceURI(null);
+        digester.addRule("employee",
+                         new NodeCreateRule(Node.ELEMENT_NODE));
+        Object result = digester.parse(getInputStream("Test10.xml"));
+
+        assertNotNull(result);
+        assertTrue(result instanceof Element);
+        Element element = (Element)result;
+        
+        assertNotNull(element.getAttributeNodeNS("http://jakarta.apache.org/digester/Bar", "test"));
+        assertEquals("MyTestAttribute", element.getAttributeNodeNS("http://jakarta.apache.org/digester/Bar", "test").getNodeValue());
+        assertEquals("test", element.getAttributeNodeNS("http://jakarta.apache.org/digester/Bar", "test").getLocalName());
+        assertEquals("bar", element.getAttributeNodeNS("http://jakarta.apache.org/digester/Bar", "test").getPrefix());
+        assertEquals("bar:test", element.getAttributeNodeNS("http://jakarta.apache.org/digester/Bar", "test").getName());
+
+    }      
+    
+    /**
+     * Tests whether non-namespaced attributes are handled correctly, using the example from 
+     * the file Test11 XML file.
+     */
+    public void testNonNamespacedAttribute()
+        throws SAXException, ParserConfigurationException, IOException {
+        
+        digester.setNamespaceAware(true);
+        digester.setRuleNamespaceURI(null);
+        digester.addRule("employee",
+                         new NodeCreateRule(Node.ELEMENT_NODE));
+        Object result = digester.parse(getInputStream("Test10.xml"));
+
+        assertNotNull(result);
+        assertTrue(result instanceof Element);
+        Element element = (Element)result;
+        
+        assertNotNull(element.getAttributeNodeNS(null, "firstName"));
+        assertEquals("First Name", element.getAttributeNodeNS(null, "firstName").getNodeValue());
+        assertEquals("firstName", element.getAttributeNodeNS(null, "firstName").getLocalName());
+        assertEquals(null, element.getAttributeNodeNS(null, "firstName").getPrefix());
+        assertEquals("firstName", element.getAttributeNodeNS(null, "firstName").getName());
+
+    }     
 
     /**
      * Tests whether the created fragment can be imported into an existing 
@@ -402,7 +451,6 @@
         doc.getFirstChild().appendChild(importedFragment);
 
     }
-
 
     // ------------------------------------------------ Utility Support Methods
 

Added: jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test10.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test10.xml?rev=378687&view=auto
==============================================================================
--- jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test10.xml (added)
+++ jakarta/commons/proper/digester/trunk/src/test/org/apache/commons/digester/Test10.xml Fri Feb 17 20:40:46 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+
+<!--
+ Copyright 2006 The Apache Software Foundation.
+  
+ Licensed 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.
+-->
+
+<foo:employee firstName="First Name" lastName="Last Name"
+   xmlns:foo="http://jakarta.apache.org/digester/Foo"
+   xmlns:bar="http://jakarta.apache.org/digester/Bar" bar:test="MyTestAttribute"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org