cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r590800 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/staxutils/ common/common/src/test/java/org/apache/cxf/staxutils/
Date Wed, 31 Oct 2007 19:39:54 GMT
Author: dkulp
Date: Wed Oct 31 12:39:53 2007
New Revision: 590800

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

........
  r590790 | dkulp | 2007-10-31 15:08:56 -0400 (Wed, 31 Oct 2007) | 2 lines
  
  More fixes for default namespaces in StaxUtils.
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
    incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java
    incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java

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

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=590800&r1=590799&r2=590800&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Wed Oct 31 12:39:53 2007
@@ -438,6 +438,9 @@
 
         if (ns == null || ns.length() == 0) {
             writer.writeStartElement(localName);
+            if (StringUtils.isEmpty(decUri)) {
+                declareNamespace = false;
+            }
         } else {
 //            System.out.println("Calling writeStartElement for local name : " 
 //            + localName + " URI: " + ns + " Prefix :" + prefix);

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java?rev=590800&r1=590799&r2=590800&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
Wed Oct 31 12:39:53 2007
@@ -38,7 +38,7 @@
     private Stack<Element> stack = new Stack<Element>();
     private Document document;
     private Element currentNode;
-    private NamespaceContext context;
+    private NamespaceContext context = new W3CNamespaceContext();
     private Map properties = Collections.EMPTY_MAP;
 
     public W3CDOMStreamWriter() throws ParserConfigurationException {
@@ -59,10 +59,7 @@
         this.document = e.getOwnerDocument();
         
         currentNode = e;
-
-        W3CNamespaceContext newContext = new W3CNamespaceContext();
-        newContext.setElement(currentNode);
-        this.context = newContext;
+        ((W3CNamespaceContext)context).setElement(e);
     }
 
     public void setProperties(Map properties) {
@@ -84,11 +81,10 @@
         } else {
             document.appendChild(element);
         }
-
-        W3CNamespaceContext newContext = new W3CNamespaceContext();
-        newContext.setElement(element);
-        this.context = newContext;
-
+        if (!(context instanceof W3CNamespaceContext)) {
+            context = new W3CNamespaceContext();
+        }
+        ((W3CNamespaceContext)context).setElement(element);
         currentNode = element;
     }
 

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java?rev=590800&r1=590799&r2=590800&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java
Wed Oct 31 12:39:53 2007
@@ -45,6 +45,10 @@
     }
 
     private String getNamespaceURI(Element e, String name) {
+        if (e == null) {
+            return null;
+        }
+
         Attr attr = e.getAttributeNode(name);
         if (attr == null) {
             Node n = e.getParentNode();

Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=590800&r1=590799&r2=590800&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Wed Oct 31 12:39:53 2007
@@ -32,6 +32,7 @@
 
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.helpers.XMLUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -178,10 +179,28 @@
         String testString = "<ns1:a xmlns:ns1=\"http://www.apache.org/\"><s1 xmlns=\"\">"
             + "abc</s1><s2 xmlns=\"\">def</s2></ns1:a>";
         
-        StringReader reader = new StringReader(testString);
+        cycleString(testString);
+        
+        testString = "<a xmlns=\"http://www.apache.org/\"><s1 xmlns=\"\">"
+            + "abc</s1><s2 xmlns=\"\">def</s2></a>";
+        cycleString(testString);
+
+        testString = "<a xmlns=\"http://www.apache.org/\"><s1 xmlns=\"\">"
+            + "abc</s1><s2>def</s2></a>";
+        cycleString(testString);
+        
+        testString = "<ns1:a xmlns:ns1=\"http://www.apache.org/\"><s1>"
+            + "abc</s1><s2 xmlns=\"\">def</s2></ns1:a>";
+        
+        cycleString(testString);
+    }
+    
+    private void cycleString(String s) throws Exception {
+        StringReader reader = new StringReader(s);
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         dbf.setNamespaceAware(true);
         Document doc = dbf.newDocumentBuilder().parse(new InputSource(reader));
+        String orig = XMLUtils.toString(doc.getDocumentElement());
         
         StringWriter sw = new StringWriter();
         XMLStreamWriter swriter = StaxUtils.createXMLStreamWriter(sw);
@@ -191,8 +210,12 @@
         swriter.close();
         
         String output = sw.toString();
-        assertEquals(testString, output);
-
+        assertEquals(s, output);
+        
+        W3CDOMStreamWriter domwriter = new W3CDOMStreamWriter();
+        StaxUtils.writeDocument(doc, domwriter, false, true);
+        output = XMLUtils.toString(domwriter.getDocument().getDocumentElement());
+        assertEquals(orig, output);
     }
 
 }



Mime
View raw message