You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/05/06 12:12:06 UTC

svn commit: r1100157 - in /cxf/trunk/common/common/src: main/java/org/apache/cxf/staxutils/StaxUtils.java test/java/org/apache/cxf/staxutils/StaxUtilsTest.java test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java

Author: sergeyb
Date: Fri May  6 10:12:06 2011
New Revision: 1100157

URL: http://svn.apache.org/viewvc?rev=1100157&view=rev
Log:
[CXF-3493] Reverting the change causing the regression with unqualified elements becoming qualified after StaxUtils.copy

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

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=1100157&r1=1100156&r2=1100157&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Fri May  6 10:12:06 2011
@@ -569,16 +569,14 @@ public final class StaxUtils {
             if (nsPrefix == null) {
                 nsPrefix = "";
             }
-            if (nsURI.length() > 0) {
-                if (nsPrefix.length() == 0) {
-                    writer.writeDefaultNamespace(nsURI);
-                    writer.setDefaultNamespace(nsURI);
-                } else {
-                    writer.writeNamespace(nsPrefix, nsURI);
-                    writer.setPrefix(nsPrefix, nsURI);
-                }
+            if (nsPrefix.length() == 0) {
+                writer.writeDefaultNamespace(nsURI);
+                writer.setDefaultNamespace(nsURI);
+            } else {
+                writer.writeNamespace(nsPrefix, nsURI);
+                writer.setPrefix(nsPrefix, nsURI);
             }
-
+            
             if (nsURI.equals(uri) && nsPrefix.equals(prefix)) {
                 writeElementNS = false;
             }

Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=1100157&r1=1100156&r2=1100157&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java (original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Fri May  6 10:12:06 2011
@@ -19,7 +19,13 @@
 
 package org.apache.cxf.staxutils;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -36,6 +42,7 @@ import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
 import org.apache.cxf.helpers.XMLUtils;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -309,4 +316,22 @@ public class StaxUtilsTest extends Asser
         idx = s.indexOf("xmlns:a", idx + 1);
         assertEquals(-1, idx);        
     }        
+    
+    @Test
+    public void testCopyWithEmptyNamespace() throws Exception {
+        StringBuilder in = new StringBuilder();
+        in.append("<foo xmlns=\"http://example.com/\">");
+        in.append("<bar xmlns=\"\"/>");
+        in.append("</foo>");
+        
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(
+             new ByteArrayInputStream(in.toString().getBytes()));
+        
+        Writer out = new StringWriter();
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
+        StaxUtils.copy(reader, writer);
+        writer.close();
+        
+        assertEquals(in.toString(), out.toString());
+    }
 }

Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java?rev=1100157&r1=1100156&r2=1100157&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java (original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java Fri May  6 10:12:06 2011
@@ -42,7 +42,22 @@ public class InTransformReaderTest exten
         ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
         StaxUtils.copy(reader, bos);
         String value = bos.toString();
-        assertTrue("<test2/>".equals(value)
-                   || "<test2></test2>".equals(value));        
+        assertTrue("<test2 xmlns=\"\"/>".equals(value));        
+    }
+    
+    @Test
+    public void testReadWithParentDefaultNamespace() throws Exception {
+        InputStream is = new ByteArrayInputStream(
+            "<test xmlns=\"http://bar\"><ns:subtest xmlns:ns=\"http://bar1\"/></test>".getBytes());
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+        reader = new InTransformReader(reader, 
+                                       Collections.singletonMap("{http://bar1}subtest", "subtest"),
+                                       null, false);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        StaxUtils.copy(reader, bos);
+        String value = bos.toString();
+        assertEquals("<ps1:test xmlns:ps1=\"http://bar\"><subtest xmlns=\"\"/></ps1:test>",
+                     value);        
     }
 }