Author: ffang
Date: Thu Sep 2 14:33:24 2010
New Revision: 991951
URL: http://svn.apache.org/viewvc?rev=991951&view=rev
Log:
Merged revisions 991939 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r991939 | ffang | 2010-09-02 22:02:58 +0800 (四, 02 9 2010) | 1 line
[CXF-2969]StreamWriterContentHandler.getPrefix shouldn't return null if
DEFAULT_NS_PREFIX is used
........
Added:
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml
- copied unchanged from r991939,
cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/resources/AddRequest.xml
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java?rev=991951&r1=991950&r2=991951&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StreamWriterContentHandler.java
Thu Sep 2 14:33:24 2010
@@ -163,16 +163,22 @@ public class StreamWriterContentHandler
/**
* Method getPrefix.
+ * @param namespaceURI
*
* @param qname
* @return Returns String.
*/
- private String getPrefix(String ns) {
+ private String getPrefix(String ns, String namespaceURI) {
int idx = ns.indexOf(':');
if (idx != -1) {
return ns.substring(0, idx);
+ } else if (namespaceURI != null && namespaceURI.length() > 0) {
+ //this is the case that have namespaceURI but use DEFAULT_NS_PREFIX
+ return "";
+ } else {
+ //this is the case that namespaceURI is just empty, so NS_PREFIX
is null
+ return null;
}
- return null;
}
/**
@@ -189,7 +195,7 @@ public class StreamWriterContentHandler
String qName,
Attributes atts) throws SAXException {
try {
- String prefix = getPrefix(qName);
+ String prefix = getPrefix(qName, namespaceURI);
// it is only the prefix we want to learn from the QName! so we
can get rid of the
// spliting QName
Modified:
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java?rev=991951&r1=991950&r2=991951&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/StaxUtilsTest.java
Thu Sep 2 14:33:24 2010
@@ -23,6 +23,7 @@ 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.transform.Source;
@@ -269,4 +270,22 @@ public class StaxUtilsTest extends Asser
assertFalse(output.contains("<?pi in='the sky'?>"));
assertFalse(output.contains("<?e excl='gads'?>"));
}
+
+ @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");
+ }
+
+
+ }
}