cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1327243 - in /cxf/trunk/api/src: main/java/org/apache/cxf/feature/StaxTransformFeature.java main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Date Tue, 17 Apr 2012 19:49:30 GMT
Author: ay
Date: Tue Apr 17 19:49:30 2012
New Revision: 1327243

URL: http://svn.apache.org/viewvc?rev=1327243&view=rev
Log:
[CXF-4244] OutTransformWriter's defaultNamespace setting may not replace all default namespace
declarations

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java?rev=1327243&r1=1327242&r2=1327243&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java Tue Apr 17
19:49:30 2012
@@ -84,6 +84,10 @@ public class StaxTransformFeature extend
         in.setInTransformElements(inElements);
     }
     
+    public void setOutDefaultNamespace(String ns) {
+        out.setDefaultNamespace(ns);
+    }
+    
     public void setContextPropertyName(String propertyName) {
         in.setContextPropertyName(propertyName);
         out.setContextPropertyName(propertyName);

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1327243&r1=1327242&r2=1327243&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
Tue Apr 17 19:49:30 2012
@@ -119,7 +119,8 @@ public class OutTransformWriter extends 
             return;
         }
         String value = nsMap.get(uri);
-        if (value != null && value.length() == 0) {
+        if ((value != null && value.length() == 0) 
+            || (isDefaultNamespaceRedefined() && !isDefaultNamespaceRedefined(uri)))
{
             return;
         }
         
@@ -139,7 +140,8 @@ public class OutTransformWriter extends 
             return;
         }
         String value = nsMap.get(uri);
-        if (value != null && value.length() == 0) {
+        if ((value != null && value.length() == 0)
+            || (isDefaultNamespaceRedefined() && !isDefaultNamespaceRedefined(uri)))
{
             return;
         }
         

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java?rev=1327243&r1=1327242&r2=1327243&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Tue Apr 17 19:49:30 2012
@@ -416,4 +416,25 @@ public class OutTransformWriterTest exte
                                                      "../resources/multiNS.xml",
                                   transformElements, null, null, null, null);
     }
+
+    @Test
+    public void testReplaceDefaultNamespace() throws Exception {
+        InputStream is = new ByteArrayInputStream(
+                "<test xmlns=\"http://bar\"><a>1</a></test>".getBytes());
+
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        XMLStreamWriter writer = 
+            new OutTransformWriter(StaxUtils.createXMLStreamWriter(os, "UTF-8"), 
+                                   null, null, null, null, false, "");
+        StaxUtils.copy(new StreamSource(is), writer);
+        writer.flush();
+
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(os.toByteArray()));
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        StaxUtils.copy(reader, bos);
+        String value = bos.toString();
+        assertEquals("<ps1:test xmlns:ps1=\"http://bar\"><ps1:a>1</ps1:a></ps1:test>",
value);        
+    }
+
 }



Mime
View raw message