cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1384552 - in /cxf/branches/2.6.x-fixes: ./ api/src/main/java/org/apache/cxf/staxutils/transform/ api/src/test/java/org/apache/cxf/staxutils/resources/ api/src/test/java/org/apache/cxf/staxutils/transform/
Date Thu, 13 Sep 2012 21:33:43 GMT
Author: ay
Date: Thu Sep 13 21:33:42 2012
New Revision: 1384552

URL: http://svn.apache.org/viewvc?rev=1384552&view=rev
Log:
Merged revisions 1384365 via  svn merge from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1384365 | ay | 2012-09-13 17:17:46 +0200 (Thu, 13 Sep 2012) | 1 line
  
  [CXF-4503] TransformOutInterceptor may lose namespace declarations in some elements
........

Added:
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml
      - copied unchanged from r1384365, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBean.xml
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml
      - copied unchanged from r1384365, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn1.xml
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml
      - copied unchanged from r1384365, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn2.xml
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml
      - copied unchanged from r1384365, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/doubleBeanIn3.xml
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
    cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java

Propchange: cxf/branches/2.6.x-fixes/
            ('svn:mergeinfo' removed)

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

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1384552&r1=1384551&r2=1384552&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
Thu Sep 13 21:33:42 2012
@@ -20,6 +20,8 @@ package org.apache.cxf.staxutils.transfo
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
 import javax.xml.namespace.NamespaceContext;
@@ -27,32 +29,45 @@ import javax.xml.namespace.NamespaceCont
 import org.apache.cxf.helpers.CastUtils;
 
 class DelegatingNamespaceContext implements NamespaceContext {
-
-    private Map<String, String> prefixes = new HashMap<String, String>();
+    private List<Map<String, String>> prefixes;
     private NamespaceContext nc;
     private Map<String, String> nsMap;
     
     public DelegatingNamespaceContext(NamespaceContext nc, Map<String, String> nsMap)
{
         this.nc = nc;
         this.nsMap = nsMap;
+        this.prefixes =  new LinkedList<Map<String, String>>();
+        this.prefixes.add(new HashMap<String, String>());
+    }
+    
+    public void down() {
+        Map<String, String> pm = new HashMap<String, String>();
+        if (prefixes.size() > 0) {
+            pm.putAll(prefixes.get(0));
+        }
+        prefixes.add(0, pm);
+    }
+    
+    public void up() {
+        prefixes.remove(0);
     }
     
     public void addPrefix(String prefix, String namespace) {
-        prefixes.put(namespace, prefix);
+        prefixes.get(0).put(namespace, prefix);
     }
     
     public String findUniquePrefix(String namespace) {
         if (namespace.length() == 0) {
             return null;
         }
-        String existingPrefix = prefixes.get(namespace);
+        String existingPrefix = prefixes.get(0).get(namespace);
         if (existingPrefix != null) {
             return existingPrefix;
         }
         
         int i = 0;
         while (true) {
-            if (!prefixes.containsValue("ps" + ++i)) {
+            if (!prefixes.get(0).containsValue("ps" + ++i)) {
                 String prefix = "ps" + i;
                 addPrefix(prefix, namespace);
                 return prefix;
@@ -61,7 +76,7 @@ class DelegatingNamespaceContext impleme
     }
     
     public String getNamespaceURI(String prefix) {
-        for (Map.Entry<String, String> entry : prefixes.entrySet()) {
+        for (Map.Entry<String, String> entry : prefixes.get(0).entrySet()) {
             if (entry.getValue().equals(prefix)) {
                 return entry.getKey();
             }
@@ -81,8 +96,8 @@ class DelegatingNamespaceContext impleme
         }
         
         String actualNs = value == null ? ns : value;
-        if (prefixes.containsKey(actualNs)) {
-            return prefixes.get(actualNs);
+        if (prefixes.get(0).containsKey(actualNs)) {
+            return prefixes.get(0).get(actualNs);
         }
         String prefix = nc.getPrefix(actualNs);
         addPrefix(prefix, actualNs);

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1384552&r1=1384551&r2=1384552&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Thu Sep 13 21:33:42 2012
@@ -111,6 +111,7 @@ public class InTransformReader extends D
         int event = super.next();
         if (event == XMLStreamConstants.START_ELEMENT) {
             attributesIndexed = false;
+            namespaceContext.down();
             final QName theName = super.getName();
             final ElementProperty appendProp = inAppendMap.remove(theName);
             final boolean replaceContent = appendProp != null && theName.equals(appendProp.getName());
@@ -168,6 +169,7 @@ public class InTransformReader extends D
                 LOG.fine("read EndElement " + theName + " at " + getDepth());
             }
             
+            namespaceContext.up();
             final boolean dropped = inDropSet.contains(theName);
             if (!dropped) {
                 List<ParsingEvent> pe = pushedAheadEvents.pop();

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java?rev=1384552&r1=1384551&r2=1384552&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/OutTransformWriter.java
Thu Sep 13 21:33:42 2012
@@ -153,6 +153,7 @@ public class OutTransformWriter extends 
     @Override
     public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException
{
         currentDepth++;
+        namespaceContext.down();
         if (matchesDropped(false)) {
             return;
         }
@@ -293,6 +294,7 @@ public class OutTransformWriter extends 
 
     @Override
     public void writeEndElement() throws XMLStreamException {
+        namespaceContext.up();
         --currentDepth;
         if (matchesDropped(false)) {
             return;

Modified: cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java?rev=1384552&r1=1384551&r2=1384552&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/OutTransformWriterTest.java
Thu Sep 13 21:33:42 2012
@@ -218,6 +218,74 @@ public class OutTransformWriterTest exte
     }
 
     @Test
+    public void testReadWithComplexTransformationNamespace2() throws Exception {
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("{http://testbeans.com/double}*", 
+            "{http://testbeans.com/double/v2}*");
+        map.put("{http://testbeans.com}*", 
+            "{http://testbeans.com/v3}*");
+        
+        // the namespaces are prefixed in the input
+        XMLStreamReader reader = 
+            TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn1.xml",

+                                                                map, null, null, null, false,
null);
+        XMLStreamReader reader2 = 
+            StaxUtils.createXMLStreamReader(
+                InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
       
+        TransformTestUtils.verifyReaders(reader2, reader, true, false);
+
+        // the child elements with the default namespace that is declared in the elements
+        reader = 
+            TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn2.xml",

+                                                                map, null, null, null, false,
null);
+        reader2 = 
+            StaxUtils.createXMLStreamReader(
+                InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
       
+        TransformTestUtils.verifyReaders(reader2, reader, true, false);
+
+        // the child elements with the default namespace that is declared in their parent
element
+        reader = 
+            TransformTestUtils.createOutTransformedStreamReader("../resources/doubleBeanIn3.xml",

+                                                                map, null, null, null, false,
null);
+        reader2 = 
+            StaxUtils.createXMLStreamReader(
+                InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
       
+        TransformTestUtils.verifyReaders(reader2, reader, true, false);
+        
+        // writing each child separately (as the soap header children are serialized)
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        XMLStreamWriter writer =
+            new OutTransformWriter(StaxUtils.createXMLStreamWriter(os, "UTF-8"), 
+                                   map, null,
+                                   null, null, false, null);
+        boolean nsset = "ns3".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com/double"));
+        writer.writeStartElement("ns3", "testDoubleBean", "http://testbeans.com/double");
+        if (!nsset) {
+            writer.writeNamespace("ns3", "http://testbeans.com/double");
+        }
+        nsset = "".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com"));
+        writer.writeStartElement("", "bean", "http://testbeans.com");
+        if (!nsset) {
+            writer.writeNamespace("", "http://testbeans.com");    
+        }
+        writer.writeEndElement();
+        nsset = "".equals(writer.getNamespaceContext().getPrefix("http://testbeans.com"));
+        writer.writeStartElement("", "beanNext", "http://testbeans.com");
+        if (!nsset) {
+            writer.writeNamespace("", "http://testbeans.com");    
+        }
+        writer.writeEndElement();
+        writer.writeEndElement();
+        writer.flush();
+        
+        reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(os.toByteArray()));
+        reader2 = 
+            StaxUtils.createXMLStreamReader(
+                InTransformReader.class.getResourceAsStream("../resources/doubleBean.xml"));
       
+        TransformTestUtils.verifyReaders(reader2, reader, true, false);
+    }
+
+    @Test
     public void testReadWithReplaceAppend() throws Exception {
         Map<String, String> transformElements = new HashMap<String, String>();
         transformElements.put("requestValue",



Mime
View raw message