cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1056611 - in /cxf/branches/2.3.x-fixes: ./ common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Date Sat, 08 Jan 2011 03:40:13 GMT
Author: dkulp
Date: Sat Jan  8 03:40:13 2011
New Revision: 1056611

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

........
  r1056610 | dkulp | 2011-01-07 22:37:39 -0500 (Fri, 07 Jan 2011) | 2 lines
  
  [CXF-3193] Allow CachingXmlEventWriter ns cache to have multiple
  prefixes for a namespace.
........

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

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

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

Modified: cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java?rev=1056611&r1=1056610&r2=1056611&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
(original)
+++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
Sat Jan  8 03:40:13 2011
@@ -233,35 +233,44 @@ public class CachingXmlEventWriter imple
             parent = p;
         }
         public void addNs(String pfx, String ns) {
-            map.put(ns, pfx);
+            map.put(pfx, ns);
         }
         
         public String getNamespaceURI(String prefix) {
-            for (Map.Entry<String, String> e : map.entrySet()) {
-                if (e.getValue().equals(prefix)) {
-                    return e.getKey();
-                }
-            }
-            if (parent != null) {
+            String ret = map.get(prefix);
+            if (ret == null && parent != null) {
                 return parent.getNamespaceURI(prefix);
             }
-            return null;
+            return ret;
         }
 
         public String getPrefix(String namespaceURI) {
-            String ret = map.get(namespaceURI);
-            if (ret == null && parent != null) {
+            for (Map.Entry<String, String> e : map.entrySet()) {
+                if (e.getValue().equals(namespaceURI)) {
+                    return e.getKey();
+                }
+            }
+            if (parent != null) {
                 return parent.getPrefix(namespaceURI);
             }
-            return ret;
+            return null;
         }
 
         public Iterator getPrefixes(String namespaceURI) {
-            String pfx = getPrefix(namespaceURI);
-            if (pfx == null) {
-                return Collections.emptyList().iterator();
+            List<String> l = new ArrayList<String>();
+            for (Map.Entry<String, String> e : map.entrySet()) {
+                if (e.getValue().equals(namespaceURI)) {
+                    l.add(e.getKey());
+                }
+            }
+            if (l.isEmpty()) {
+                String pfx = getPrefix(namespaceURI);
+                if (pfx == null) {
+                    return Collections.emptyList().iterator();
+                }
+                return Collections.singleton(pfx).iterator();
             }
-            return Collections.singleton(pfx).iterator();
+            return l.iterator();
         }
         
     }

Modified: cxf/branches/2.3.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=1056611&r1=1056610&r2=1056611&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
(original)
+++ cxf/branches/2.3.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Sat Jan  8 03:40:13 2011
@@ -23,9 +23,9 @@ import java.io.*;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.XMLEvent;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 
@@ -281,19 +281,32 @@ public class StaxUtilsTest extends Asser
     
     @Test
     public void testDefaultPrefix() throws Exception {
-        try {
-            String soapMessage = "./resources/AddRequest.xml";     
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            XMLStreamReader reader = StaxUtils.createXMLStreamReader(getTestStream(soapMessage));
-            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
-            StaxSource staxSource = new StaxSource(reader);
-            StaxUtils.copy(staxSource, writer);
-            writer.flush();
-            baos.flush();
-        } catch (XMLStreamException e) {
-            fail("shouldn't catch this exception");
+        String soapMessage = "./resources/AddRequest.xml";     
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(getTestStream(soapMessage));
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(baos);
+        StaxSource staxSource = new StaxSource(reader);
+        StaxUtils.copy(staxSource, writer);
+        writer.flush();
+        baos.flush();
+    }
+       
+    @Test
+    public void testCXF3193() throws Exception {
+        String testString = "<a:elem1 xmlns:a=\"test\" xmlns:b=\"test\" a:attr1=\"value\"/>";
+        CachingXmlEventWriter writer = new CachingXmlEventWriter();
+        StaxUtils.copy(StaxUtils.createXMLStreamReader(new StringReader(testString)),
+                       writer);
+        StringWriter swriter = new StringWriter();
+        XMLStreamWriter xwriter = StaxUtils.createXMLStreamWriter(swriter);
+        for (XMLEvent event : writer.getEvents()) {
+            StaxUtils.writeEvent(event, xwriter);
         }
-           
+        xwriter.flush();
         
-    }
+        String s = swriter.toString();
+        int idx = s.indexOf("xmlns:a");
+        idx = s.indexOf("xmlns:a", idx + 1);
+        assertEquals(-1, idx);        
+    }        
 }



Mime
View raw message