cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r590165 - in /incubator/cxf/trunk/common/common/src: main/java/org/apache/cxf/staxutils/StaxUtils.java test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Date Tue, 30 Oct 2007 17:26:54 GMT
Author: dkulp
Date: Tue Oct 30 10:26:53 2007
New Revision: 590165

URL: http://svn.apache.org/viewvc?rev=590165&view=rev
Log:
Fix issue of default namespaces being defined twice

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=590165&r1=590164&r2=590165&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Tue Oct 30 10:26:53 2007
@@ -448,12 +448,13 @@
         for (int i = 0; i < attrs.getLength(); i++) {
             Node attr = attrs.item(i);
 
-            String name = attr.getNodeName();
-            String attrPrefix = "";
-            int prefixIndex = name.indexOf(':');
-            if (prefixIndex != -1) {
-                attrPrefix = name.substring(0, prefixIndex);
-                name = name.substring(prefixIndex + 1);
+            String name = attr.getLocalName();
+            String attrPrefix = attr.getPrefix();
+            if (attrPrefix == null) {
+                attrPrefix = "";
+            }
+            if (name == null) {
+                name = attr.getNodeName();
             }
      
             if ("xmlns".equals(attrPrefix)) {
@@ -467,6 +468,9 @@
                 if ("xmlns".equals(name) && "".equals(attrPrefix)) {
                     writer.writeNamespace("", attr.getNodeValue());
                     if (attr.getNodeValue().equals(ns)) {
+                        declareNamespace = false;
+                    } else if (StringUtils.isEmpty(attr.getNodeValue())
+                        && StringUtils.isEmpty(ns)) {
                         declareNamespace = false;
                     }
                 } else {

Modified: incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=590165&r1=590164&r2=590165&view=diff
==============================================================================
--- incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
(original)
+++ incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Tue Oct 30 10:26:53 2007
@@ -172,4 +172,27 @@
         assertTrue(output.contains("snarf"));        
         assertTrue(output.contains("blop"));        
     }
+    
+    @Test
+    public void testEmptyNamespace() throws Exception {
+        String testString = "<ns1:a xmlns:ns1=\"http://www.apache.org/\"><s1 xmlns=\"\">"
+            + "abc</s1><s2 xmlns=\"\">def</s2></ns1:a>";
+        
+        StringReader reader = new StringReader(testString);
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        Document doc = dbf.newDocumentBuilder().parse(new InputSource(reader));
+        
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter swriter = StaxUtils.createXMLStreamWriter(sw);
+        //should not throw an exception
+        StaxUtils.writeDocument(doc, swriter, false, true);
+        swriter.flush();
+        swriter.close();
+        
+        String output = sw.toString();
+        assertEquals(testString, output);
+
+    }
+
 }



Mime
View raw message