cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r590209 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Date Tue, 30 Oct 2007 18:24:51 GMT
Author: dkulp
Date: Tue Oct 30 11:24:50 2007
New Revision: 590209

URL: http://svn.apache.org/viewvc?rev=590209&view=rev
Log:
Merged revisions 590165 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r590165 | dkulp | 2007-10-30 13:26:53 -0400 (Tue, 30 Oct 2007) | 2 lines
  
  Fix issue of default namespaces being defined twice
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=590209&r1=590208&r2=590209&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Tue Oct 30 11:24:50 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/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=590209&r1=590208&r2=590209&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Tue Oct 30 11:24:50 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