You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/10/14 22:03:39 UTC
svn commit: r825251 - in /cxf/branches/2.1.x-fixes: ./
common/common/src/main/java/org/apache/cxf/staxutils/
common/common/src/test/java/org/apache/cxf/staxutils/
Author: dkulp
Date: Wed Oct 14 20:03:39 2009
New Revision: 825251
URL: http://svn.apache.org/viewvc?rev=825251&view=rev
Log:
Merged revisions 825234 via svnmerge from
https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................
r825234 | dkulp | 2009-10-14 15:35:09 -0400 (Wed, 14 Oct 2009) | 10 lines
Merged revisions 825221 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r825221 | dkulp | 2009-10-14 15:02:38 -0400 (Wed, 14 Oct 2009) | 2 lines
[CXF-2468] Make the StaxUtils.copy stuff repare attribute namespaces as
well as element namespaces
........
................
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java?rev=825251&r1=825250&r2=825251&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java (original)
+++ cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java Wed Oct 14 20:03:39 2009
@@ -270,6 +270,9 @@
public Iterator getPrefixes(String namespaceURI) {
String pfx = getPrefix(namespaceURI);
+ if (pfx == null) {
+ return Collections.emptyList().iterator();
+ }
return Collections.singleton(pfx).iterator();
}
Modified: cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=825251&r1=825250&r2=825251&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/branches/2.1.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Wed Oct 14 20:03:39 2009
@@ -68,6 +68,7 @@
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.XMLUtils;
@@ -449,9 +450,16 @@
// System.out.println("STAXUTILS:writeStartElement : node name : " + local + " namespace URI" + uri);
boolean writeElementNS = false;
if (uri != null) {
- String boundPrefix = writer.getPrefix(uri);
- if (boundPrefix == null || !prefix.equals(boundPrefix)) {
- writeElementNS = true;
+ writeElementNS = true;
+ Iterator<String> it = CastUtils.cast(writer.getNamespaceContext().getPrefixes(uri));
+ while (it != null && it.hasNext()) {
+ String s = it.next();
+ if (s == null) {
+ s = "";
+ }
+ if (s.equals(prefix)) {
+ writeElementNS = false;
+ }
}
}
@@ -509,6 +517,20 @@
writer.writeAttribute(reader.getAttributeNamespace(i), reader.getAttributeLocalName(i),
reader.getAttributeValue(i));
} else {
+ Iterator<String> it = CastUtils.cast(writer.getNamespaceContext().getPrefixes(ns));
+ boolean writeNs = true;
+ while (it != null && it.hasNext()) {
+ String s = it.next();
+ if (s == null) {
+ s = "";
+ }
+ if (s.equals(nsPrefix)) {
+ writeNs = false;
+ }
+ }
+ if (writeNs) {
+ writer.writeNamespace(nsPrefix, ns);
+ }
writer.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i), reader
.getAttributeLocalName(i), reader.getAttributeValue(i));
}
Modified: cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=825251&r1=825250&r2=825251&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java (original)
+++ cxf/branches/2.1.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java Wed Oct 14 20:03:39 2009
@@ -28,7 +28,9 @@
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
+import org.w3c.dom.Attr;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.xml.sax.InputSource;
@@ -111,6 +113,22 @@
assertEquals(input, output);
}
+ @Test
+ public void testCXF2468() throws Exception {
+ Document doc = XMLUtils.newDocument();
+ doc.appendChild(doc.createElementNS("http://blah.org/", "blah"));
+ Element foo = doc.createElementNS("http://blah.org/", "foo");
+ Attr attr = doc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil");
+ attr.setValue("true");
+ foo.setAttributeNodeNS(attr);
+ doc.getDocumentElement().appendChild(foo);
+ XMLStreamReader sreader = StaxUtils.createXMLStreamReader(doc);
+ StringWriter sw = new StringWriter();
+ XMLStreamWriter swriter = StaxUtils.createXMLStreamWriter(sw);
+ StaxUtils.copy(sreader, swriter, true);
+ swriter.flush();
+ assertTrue("No xsi namespace: " + sw.toString(), sw.toString().contains("XMLSchema-instance"));
+ }
@Test
public void testNonNamespaceAwareParser() throws Exception {