cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1311046 - in /cxf/trunk/api/src: main/java/org/apache/cxf/staxutils/transform/ test/java/org/apache/cxf/staxutils/resources/ test/java/org/apache/cxf/staxutils/transform/
Date Sun, 08 Apr 2012 17:02:10 GMT
Author: ay
Date: Sun Apr  8 17:02:09 2012
New Revision: 1311046

URL: http://svn.apache.org/viewvc?rev=1311046&view=rev
Log:
[CXF-4176] preserve namespace prefixes in Transform feature

Added:
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest2.xml   (with
props)
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest3.xml   (with
props)
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS.xml   (with props)
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNSIn1.xml   (with
props)
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
    cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1partial.xml
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2.xml
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2partial.xml
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3.xml
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3partial.xml
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
    cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Sun Apr  8 17:02:09 2012
@@ -122,6 +122,18 @@ public class InTransformReader extends D
             QName expected = inElementsMap.get(theName);
             if (expected == null) {
                 expected = theName;
+            } else {
+                String prefix = theName.getPrefix();
+                if (prefix.length() == 0 && theName.getNamespaceURI().length() ==
0
+                    && expected.getNamespaceURI().length() > 0) {
+                    prefix = namespaceContext.getPrefix(expected.getNamespaceURI());
+                    if (prefix == null) {
+                        prefix = namespaceContext.findUniquePrefix(expected.getNamespaceURI());
+                    }
+                } else if (prefix.length() > 0 && expected.getNamespaceURI().length()
== 0) {
+                    prefix = "";
+                }
+                expected = new QName(expected.getNamespaceURI(), expected.getLocalPart(),
prefix);
             }
 
             if (null != appendProp && !replaceContent) {
@@ -278,8 +290,11 @@ public class InTransformReader extends D
     public String getPrefix() {
         QName name = readCurrentElement();
         String prefix = name.getPrefix();
-        if (prefix.length() == 0) {
-            prefix = namespaceContext.findUniquePrefix(name.getNamespaceURI());
+        if (prefix.length() == 0 && getNamespaceURI().length() > 0) {
+            prefix = getNamespaceContext().getPrefix(getNamespaceURI());
+            if (prefix == null) {
+                prefix = "";
+            }
         }
         return prefix;
     }
@@ -298,7 +313,11 @@ public class InTransformReader extends D
         String ns = super.getNamespaceURI(index);
         String actualNs = nsMap.get(ns);
         if (actualNs != null) {
-            return namespaceContext.findUniquePrefix(actualNs);
+            if (actualNs.length() > 0) {
+                return super.getNamespacePrefix(index);
+            } else {
+                return "";
+            }
         } else {
             return namespaceContext.getPrefix(ns);
         }

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=1311046&r1=1311045&r2=1311046&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
Sun Apr  8 17:02:09 2012
@@ -112,6 +112,42 @@ public class OutTransformWriter extends 
         writtenUris.get(0).add(uri);
     }
     
+
+    @Override
+    public void writeDefaultNamespace(String uri) throws XMLStreamException {
+        if (matchesDropped(true)) {
+            return;
+        }
+        String value = nsMap.get(uri);
+        if (value != null && value.length() == 0) {
+            return;
+        }
+        
+        uri = value != null ? value : uri;
+        
+        if (writtenUris.get(0).contains(uri) && "".equals(getPrefix(uri))) {
+            return;
+        }
+        super.writeDefaultNamespace(uri);
+
+        writtenUris.get(0).add(uri);
+    }
+
+    @Override
+    public void setDefaultNamespace(String uri) throws XMLStreamException {
+        if (matchesDropped(true)) {
+            return;
+        }
+        String value = nsMap.get(uri);
+        if (value != null && value.length() == 0) {
+            return;
+        }
+        
+        uri = value != null ? value : uri;
+
+        super.setDefaultNamespace(uri);
+    }
+
     @Override
     public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException
{
         currentDepth++;
@@ -135,6 +171,19 @@ public class OutTransformWriter extends 
         if (expected == null) {
             expected = theName;
         } else {
+            if (prefix.length() == 0 && expected.getNamespaceURI().length() >
0
+                && theName.getNamespaceURI().length() == 0) {
+                // if the element is promoted to a qualified element, use the prefix bound

+                // to that namespace. If the namespace is unbound, generate a new prefix
and
+                // write its declaration later.
+                prefix = getPrefix(expected.getNamespaceURI());
+                if (prefix == null) {
+                    prefix = namespaceContext.findUniquePrefix(expected.getNamespaceURI());
+                }
+            } else if (prefix.length() > 0 && expected.getNamespaceURI().length()
== 0) {
+                // if the element is demoted to a unqualified element, use an empty prefix.
+                prefix = "";
+            }
             expected = new QName(expected.getNamespaceURI(), expected.getLocalPart(), prefix);
         }
         List<ParsingEvent> pe = null;
@@ -158,7 +207,7 @@ public class OutTransformWriter extends 
                         theprefix = "";
                     }
                 }
-                write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(),
theprefix));
+                write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(),
theprefix), false);
                 if (nsadded && theprefix.length() > 0) {
                     writeNamespace(theprefix, appendQName.getNamespaceURI());
                 }
@@ -188,7 +237,11 @@ public class OutTransformWriter extends 
             dropDepth = currentDepth - 1;
             return;
         }
-        write(expected);
+        write(expected, false);
+        if (expected.getNamespaceURI().length() > 0 && theName.getNamespaceURI().length()
== 0) {
+            // the element is promoted to a qualified element, thus write its declaration
+            writeNamespace(expected.getPrefix(), expected.getNamespaceURI());
+        }
         pushedAheadEvents.push(pe);
         elementsStack.push(expected);
 
@@ -200,7 +253,7 @@ public class OutTransformWriter extends 
             if (appendProp.getText() == null) {
                 // ap-post-wrap
                 write(new QName(appendQName.getNamespaceURI(), appendQName.getLocalPart(),

-                                theprefix == null ? "" : theprefix));
+                                theprefix == null ? "" : theprefix), false);
                 if (getNamespaceContext().getPrefix(appendQName.getNamespaceURI()) == null)
{
                     this.writeNamespace(theprefix, uri);
                 }
@@ -255,7 +308,7 @@ public class OutTransformWriter extends 
                 for (ParsingEvent pe : pes) {
                     switch (pe.getEvent()) {
                     case XMLStreamConstants.START_ELEMENT:
-                        write(pe.getName());
+                        write(pe.getName(), true);
                         break;
                     case XMLStreamConstants.END_ELEMENT:
                         super.writeEndElement();
@@ -284,11 +337,13 @@ public class OutTransformWriter extends 
         super.writeCharacters(text);
     }
     
-    private void write(QName qname) throws XMLStreamException {
+    private void write(QName qname, boolean replacePrefix) throws XMLStreamException {
         boolean writeNs = false;
         String prefix = "";
         if (qname.getNamespaceURI().length() > 0) {
-            if (qname.getPrefix().length() == 0) {
+            if ((replacePrefix || isDefaultNamespaceRedefined()) 
+                && qname.getPrefix().length() == 0) {
+                // if the default namespace is configured to be replaced, a non-empty prefix
must be assigned 
                 prefix = getPrefix(qname.getNamespaceURI());
                 if (prefix == null) {
                     prefix = namespaceContext.findUniquePrefix(qname.getNamespaceURI());
@@ -300,7 +355,7 @@ public class OutTransformWriter extends 
             }
             
         }
-        if (defaultNamespace != null && defaultNamespace.equals(qname.getNamespaceURI()))
{
+        if (isDefaultNamespaceRedefined(qname.getNamespaceURI())) {
             prefix = "";
         }
         
@@ -310,6 +365,14 @@ public class OutTransformWriter extends 
         }
     }
     
+    private boolean isDefaultNamespaceRedefined() {
+        return defaultNamespace != null;
+    }
+    
+    private boolean isDefaultNamespaceRedefined(String uri) {
+        return isDefaultNamespaceRedefined() && defaultNamespace.equals(uri);
+    }
+
     private boolean matchesDropped(boolean shallow) {
         if ((dropDepth > 0 && dropDepth <= currentDepth) 
             || (shallow && (elementsStack.size() > 0 && dropElements.contains(elementsStack.peek()))))
{

Added: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest2.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest2.xml?rev=1311046&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest2.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest3.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest3.xml?rev=1311046&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/AddRequest3.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml (original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml Sun Apr
 8 17:02:09 2012
@@ -20,12 +20,12 @@
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
     <ns2:SoapHeaderIn xmlns:ns4="http://cxf.apache.org/transform/fault"
-      xmlns:ps1="http://cxf.apache.org/transform/header/element"
+      xmlns:ns3="http://cxf.apache.org/transform/header/element"
       xmlns:ns2="http://cxf.apache.org/transform/header"
       xmlns="http://cxf.apache.org/transform/test">
       <ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>
       <ns2:SomeComplexHeaderType>
-        <ps1:CallerCorrelationId>SomeComplexValue</ps1:CallerCorrelationId>
+        <ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>
       </ns2:SomeComplexHeaderType>
     </ns2:SoapHeaderIn>
   </soap:Header>

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1partial.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1partial.xml?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1partial.xml
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1partial.xml
Sun Apr  8 17:02:09 2012
@@ -20,12 +20,12 @@
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
     <ns2:SoapHeaderIn xmlns:ns4="http://cxf.apache.org/transform/fault" 
-      xmlns:ps1="http://cxf.apache.org/transform/header/element" 
+      xmlns:ns3="http://cxf.apache.org/transform/header/element" 
       xmlns:ns2="http://cxf.apache.org/transform/header" 
       xmlns="http://cxf.apache.org/transform/test">
       <ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>
       <ns2:SomeComplexHeaderType>
-        <ps1:CallerCorrelationId>SomeComplexValue</ps1:CallerCorrelationId>
+        <ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>
       </ns2:SomeComplexHeaderType>
     </ns2:SoapHeaderIn>
   </soap:Header>

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2.xml?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2.xml (original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2.xml Sun Apr
 8 17:02:09 2012
@@ -20,19 +20,18 @@
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
     <ns2:SoapHeaderIn xmlns:ns4="http://cxf.apache.org/transform/fault"
-      xmlns:ps1="http://cxf.apache.org/transform/header/otherelement"
-      xmlns:ns2="http://cxf.apache.org/transform/header"
-      xmlns:ps2="http://cxf.apache.org/transform/othertest">
+      xmlns:ns3="http://cxf.apache.org/transform/header/otherelement"
+      xmlns:ns2="http://cxf.apache.org/transform/header">
       <ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>
       <ns2:SomeComplexHeaderType>
-        <ps1:CallerCorrelationId>SomeComplexValue</ps1:CallerCorrelationId>
+        <ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>
       </ns2:SomeComplexHeaderType>
     </ns2:SoapHeaderIn>
   </soap:Header>
   <soap:Body>
-    <ps2:TransformTestRequest xmlns:ps2="http://cxf.apache.org/transform/othertest"
+    <TransformTestRequest xmlns="http://cxf.apache.org/transform/othertest"
       xmlns:ns2="http://cxf.apache.org/transform/header"
-      xmlns:ps1="http://cxf.apache.org/transform/header/otherelement"
+      xmlns:ns3="http://cxf.apache.org/transform/header/otherelement"
       xmlns:ns4="http://cxf.apache.org/transform/fault"/>
   </soap:Body>
 </soap:Envelope>

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2partial.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2partial.xml?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2partial.xml
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq2partial.xml
Sun Apr  8 17:02:09 2012
@@ -20,12 +20,11 @@
 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header>
     <ns2:SoapHeaderIn xmlns:ns4="http://cxf.apache.org/transform/fault"
-      xmlns:ps1="http://cxf.apache.org/transform/header/otherelement"
-      xmlns:ns2="http://cxf.apache.org/transform/header"
-      xmlns:ps2="http://cxf.apache.org/transform/othertest">
+      xmlns:ns3="http://cxf.apache.org/transform/header/otherelement"
+      xmlns:ns2="http://cxf.apache.org/transform/header">
       <ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>
       <ns2:SomeComplexHeaderType>
-        <ps1:CallerCorrelationId>SomeComplexValue</ps1:CallerCorrelationId>
+        <ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>
       </ns2:SomeComplexHeaderType>
     </ns2:SoapHeaderIn>
   </soap:Header>

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3.xml?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3.xml (original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3.xml Sun Apr
 8 17:02:09 2012
@@ -14,25 +14,24 @@
   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
+  specific language sgoverning permissions and limitations
   under the License.
 -->
-<ps1:TheEnvelope xmlns:ps1="http://schemas.xmlsoap.org/soap/envelope/">
+<soap:TheEnvelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <ns2:SoapHeaderIn xmlns:ns4="http://cxf.apache.org/transform/fault"
-      xmlns:ps2="http://cxf.apache.org/transform/header/otherelement"
-      xmlns:ns2="http://cxf.apache.org/transform/header"
-      xmlns:ps3="http://cxf.apache.org/transform/othertest">
+	xmlns:ns2="http://cxf.apache.org/transform/header"
+	xmlns:ns3="http://cxf.apache.org/transform/header/otherelement"
+	xmlns="http://cxf.apache.org/transform/othertest">
       <ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>
       <ns2:SomeComplexHeaderType>
-        <ps2:CallerCorrelationId>SomeComplexValue</ps2:CallerCorrelationId>
+        <ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>
       </ns2:SomeComplexHeaderType>
     </ns2:SoapHeaderIn>
   </soap:Header>
   <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
-    <ps3:TransformTestRequest xmlns:ps3="http://cxf.apache.org/transform/othertest"
-      xmlns:ns2="http://cxf.apache.org/transform/header"
-      xmlns:ps2="http://cxf.apache.org/transform/header/otherelement"
+    <TransformTestRequest xmlns="http://cxf.apache.org/transform/othertest"
+      xmlns:ns2="http://cxf.apache.org/transform/header/otherelement"
       xmlns:ns4="http://cxf.apache.org/transform/fault"/>
   </soap:Body>
-</ps1:TheEnvelope>
+</soap:TheEnvelope>

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3partial.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3partial.xml?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3partial.xml
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq3partial.xml
Sun Apr  8 17:02:09 2012
@@ -17,17 +17,17 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<ps1:TheEnvelope xmlns:ps1="http://schemas.xmlsoap.org/soap/envelope/">
-  <soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+<soap:TheEnvelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+  <soap:Header>
     <ns2:SoapHeaderIn xmlns:ns4="http://cxf.apache.org/transform/fault" 
-      xmlns:ps2="http://cxf.apache.org/transform/header/otherelement" 
+      xmlns:ns3="http://cxf.apache.org/transform/header/otherelement" 
       xmlns:ns2="http://cxf.apache.org/transform/header" 
-      xmlns:ps3="http://cxf.apache.org/transform/othertest">
+      xmlns="http://cxf.apache.org/transform/othertest">
       <ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>
       <ns2:SomeComplexHeaderType>
-        <ps2:CallerCorrelationId>SomeComplexValue</ps2:CallerCorrelationId>
+        <ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>
       </ns2:SomeComplexHeaderType>
     </ns2:SoapHeaderIn>
   </soap:Header>
   <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>
-</ps1:TheEnvelope>
+</soap:TheEnvelope>

Added: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS.xml?rev=1311046&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNSIn1.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNSIn1.xml?rev=1311046&view=auto
==============================================================================
Binary file - no diff available.

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNSIn1.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNSIn1.xml
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
Sun Apr  8 17:02:09 2012
@@ -84,7 +84,7 @@ public class InTransformReaderTest exten
         StaxUtils.copy(reader, bos);
         String value = bos.toString();
         assertEquals(
-                "<ps1:test xmlns:ps1=\"http://foo\"><ps1:a>1 2 3</ps1:a></ps1:test>",
value);        
+                "<ns:test xmlns:ns=\"http://foo\"><ns:a>1 2 3</ns:a></ns:test>",
value);        
     }
     
     @Test
@@ -99,7 +99,7 @@ public class InTransformReaderTest exten
         ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
         StaxUtils.copy(reader, bos);
         String value = bos.toString();
-        assertEquals("<ps1:test xmlns:ps1=\"http://bar\"><subtest xmlns=\"\"/></ps1:test>",
+        assertEquals("<test xmlns=\"http://bar\"><subtest xmlns=\"\"/></test>",
                      value);        
     }
     
@@ -120,7 +120,7 @@ public class InTransformReaderTest exten
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 InTransformReader.class.getResourceAsStream("../resources/complexReq1.xml"));
-        TransformTestUtils.verifyReaders(reader2, reader, true);
+        TransformTestUtils.verifyReaders(reader2, reader, true, true);
     }
     
     @Test
@@ -142,7 +142,7 @@ public class InTransformReaderTest exten
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 InTransformReader.class.getResourceAsStream("../resources/complexReq2.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, reader, true);
+        TransformTestUtils.verifyReaders(reader2, reader, true, true);
     }
     
     @Test
@@ -166,7 +166,7 @@ public class InTransformReaderTest exten
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 InTransformReader.class.getResourceAsStream("../resources/complexReq3.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, reader, true);
+        TransformTestUtils.verifyReaders(reader2, reader, true, true);
     }
 
     @Test
@@ -188,7 +188,7 @@ public class InTransformReaderTest exten
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 InTransformReader.class.getResourceAsStream("../resources/complexReq1partial.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, filteredReader, false);
+        TransformTestUtils.verifyReaders(reader2, filteredReader, false, true);
     }
     
     @Test
@@ -213,7 +213,7 @@ public class InTransformReaderTest exten
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 InTransformReader.class.getResourceAsStream("../resources/complexReq2partial.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, filteredReader, false);
+        TransformTestUtils.verifyReaders(reader2, filteredReader, false, true);
     }
     
     @Test
@@ -241,7 +241,7 @@ public class InTransformReaderTest exten
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                   InTransformReader.class.getResourceAsStream("../resources/complexReq3partial.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, filteredReader, false);
+        TransformTestUtils.verifyReaders(reader2, filteredReader, false, true);
     }
     
     
@@ -338,7 +338,7 @@ public class InTransformReaderTest exten
         appendElements.put("{http://apache.org/cxf/calculator/types}add",
                            "{http://www.w3.org/2003/05/soap-envelope}Body");
         TransformTestUtils.transformInStreamAndCompare("../resources/AddRequestIn2.xml",

-                                                     "../resources/AddRequest.xml",
+                                                     "../resources/AddRequest2.xml",
                                   transformElements, appendElements, null, null, null);
     }
 
@@ -351,7 +351,7 @@ public class InTransformReaderTest exten
         appendElements.put("{http://apache.org/cxf/calculator/types}add",
                            "{http://www.w3.org/2003/05/soap-envelope}Body");
         TransformTestUtils.transformInStreamAndCompare("../resources/AddRequestIn2nospace.xml",

-                                                     "../resources/AddRequest.xml",
+                                                     "../resources/AddRequest2.xml",
                                   transformElements, appendElements, null, null, null);
     }
 
@@ -419,7 +419,7 @@ public class InTransformReaderTest exten
         dropElements.add("param");
 
         TransformTestUtils.transformInStreamAndCompare("../resources/AddRequestIn3.xml",

-                                                     "../resources/AddRequest.xml",
+                                                     "../resources/AddRequest3.xml",
                                   transformElements, appendElements, dropElements, null,
null);
         
     }
@@ -438,4 +438,15 @@ public class InTransformReaderTest exten
         
     }
 
+    @Test
+    public void testPreservePrefixBindings() throws Exception {
+        Map<String, String> transformElements = new HashMap<String, String>();
+        transformElements.put("{urn:abc}*",
+                              "{urn:a}*");
+
+        TransformTestUtils.transformInStreamAndCompare("../resources/multiNSIn1.xml", 
+                                                     "../resources/multiNS.xml",
+                                  transformElements, null, null, null, null);
+    }
+
 }

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=1311046&r1=1311045&r2=1311046&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
Sun Apr  8 17:02:09 2012
@@ -77,7 +77,7 @@ public class OutTransformWriterTest exte
                                                                     Collections.<String,
String>emptyMap(),
                                                                     Collections.<String>emptyList(),
                                                                     false,
-                                                                    null);
+                                                                    "");
         JAXBContext context = JAXBContext.newInstance(TestBean.class);
         Marshaller m = context.createMarshaller();
         m.marshal(new TestBean(), transformWriter);
@@ -175,7 +175,7 @@ public class OutTransformWriterTest exte
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 OutTransformWriter.class.getResourceAsStream("../resources/complexReq1.xml"));
-        TransformTestUtils.verifyReaders(reader2, reader, true);
+        TransformTestUtils.verifyReaders(reader2, reader, true, true);
     }
     
     @Test
@@ -192,8 +192,8 @@ public class OutTransformWriterTest exte
         
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
-                InTransformReader.class.getResourceAsStream("../resources/complexReq2.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, reader, true);
+                InTransformReader.class.getResourceAsStream("../resources/complexReq2.xml"));
+        TransformTestUtils.verifyReaders(reader2, reader, true, true);
     }
     
     @Test
@@ -214,7 +214,7 @@ public class OutTransformWriterTest exte
         XMLStreamReader reader2 = 
             StaxUtils.createXMLStreamReader(
                 InTransformReader.class.getResourceAsStream("../resources/complexReq3.xml"));
       
-        TransformTestUtils.verifyReaders(reader2, reader, true);
+        TransformTestUtils.verifyReaders(reader2, reader, true, false);
     }
 
     @Test
@@ -226,7 +226,6 @@ public class OutTransformWriterTest exte
         Map<String, String> appendElements = new HashMap<String, String>();
         appendElements.put("requestValue",
                            "{http://cxf.apache.org/hello_world_soap_http/types}greetMe");
-
         TransformTestUtils.transformOutStreamAndCompare("../resources/greetMeReqIn1.xml",

                                                      "../resources/greetMeReq.xml",
                                   transformElements, appendElements, null, null, null);
@@ -310,7 +309,7 @@ public class OutTransformWriterTest exte
         appendElements.put("{http://apache.org/cxf/calculator/types}add",
                            "{http://www.w3.org/2003/05/soap-envelope}Body");
         TransformTestUtils.transformOutStreamAndCompare("../resources/AddRequestIn2.xml",

-                                                     "../resources/AddRequest.xml",
+                                                     "../resources/AddRequest2.xml",
                                   transformElements, appendElements, null, null, null);
     }
 
@@ -323,7 +322,7 @@ public class OutTransformWriterTest exte
         appendElements.put("{http://apache.org/cxf/calculator/types}add",
                            "{http://www.w3.org/2003/05/soap-envelope}Body");
         TransformTestUtils.transformOutStreamAndCompare("../resources/AddRequestIn2nospace.xml",

-                                                     "../resources/AddRequest.xml",
+                                                     "../resources/AddRequest2.xml",
                                   transformElements, appendElements, null, null, null);
     }
 
@@ -391,7 +390,7 @@ public class OutTransformWriterTest exte
         dropElements.add("param");
 
         TransformTestUtils.transformOutStreamAndCompare("../resources/AddRequestIn3.xml",

-                                                     "../resources/AddRequest.xml",
+                                                     "../resources/AddRequest3.xml",
                                   transformElements, appendElements, dropElements, null,
null);
         
     }
@@ -406,4 +405,15 @@ public class OutTransformWriterTest exte
                                                      "../resources/wstrustReqSTRC.xml",
                                   transformElements, null, null, null, null);
     }
+
+    @Test
+    public void testPreservePrefixBindings() throws Exception {
+        Map<String, String> transformElements = new HashMap<String, String>();
+        transformElements.put("{urn:abc}*",
+                              "{urn:a}*");
+
+        TransformTestUtils.transformOutStreamAndCompare("../resources/multiNSIn1.xml", 
+                                                     "../resources/multiNS.xml",
+                                  transformElements, null, null, null, null);
+    }
 }

Modified: cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java?rev=1311046&r1=1311045&r2=1311046&view=diff
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
(original)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
Sun Apr  8 17:02:09 2012
@@ -67,7 +67,7 @@ public final class TransformTestUtils {
             StaxUtils.createXMLStreamReader(
                       TransformTestUtils.class.getResourceAsStream(outname));
         
-        verifyReaders(teacher, reader, false);
+        verifyReaders(teacher, reader, false, true);
     }
 
     static void transformOutStreamAndCompare(String inname, String outname, 
@@ -85,8 +85,8 @@ public final class TransformTestUtils {
         XMLStreamReader teacher = 
             StaxUtils.createXMLStreamReader(
                       TransformTestUtils.class.getResourceAsStream(outname));
-        
-        verifyReaders(teacher, reader, false);
+ 
+        verifyReaders(teacher, reader, false, true);
     }
 
     static XMLStreamReader createInTransformedStreamReader(
@@ -129,7 +129,7 @@ public final class TransformTestUtils {
      * @throws XMLStreamException
      */
     static void verifyReaders(XMLStreamReader teacher, XMLStreamReader reader, 
-                               boolean eec) throws XMLStreamException {
+                               boolean eec, boolean pfx) throws XMLStreamException {
         // compare the elements and attributes while ignoring comments, line breaks, etc
         for (;;) {
             int revent = getNextEvent(reader);
@@ -145,6 +145,10 @@ public final class TransformTestUtils {
             case XMLStreamConstants.START_ELEMENT:
                 LOG.fine("Start Element " + teacher.getName() + " ? " + reader.getName());
                 Assert.assertEquals(teacher.getName(), reader.getName());
+                if (pfx) {
+                    // verify if the namespace prefix are preserved
+                    Assert.assertEquals(teacher.getPrefix(), reader.getPrefix());
+                }
                 verifyAttributes(teacher, reader);
                 break;
             case XMLStreamConstants.END_ELEMENT:



Mime
View raw message