You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2016/02/05 21:39:54 UTC

[3/3] cxf git commit: Update SourceProvider to be able to write out any Nodes and not just Documents

Update SourceProvider to be able to write out any Nodes and not just Documents


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/96802a24
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/96802a24
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/96802a24

Branch: refs/heads/3.1.x-fixes
Commit: 96802a240f833a1e1cf66cca376f8123b75d68cf
Parents: bbe5e87
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Feb 5 17:53:39 2016 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Feb 5 20:39:46 2016 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/provider/SourceProvider.java    | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/96802a24/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
index 52bf495..20e29d0 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
@@ -44,7 +44,7 @@ import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamSource;
 
 import org.w3c.dom.Document;
-
+import org.w3c.dom.Node;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.MessageContext;
@@ -72,7 +72,7 @@ public class SourceProvider<T> extends AbstractConfigurableProvider implements
     
     public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
         return Source.class.isAssignableFrom(type)
-            || Document.class.isAssignableFrom(type);
+            || Node.class.isAssignableFrom(type);
     }
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
@@ -189,9 +189,14 @@ public class SourceProvider<T> extends AbstractConfigurableProvider implements
         
         String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name());
         
-        XMLStreamReader reader = 
-            source instanceof Source ? StaxUtils.createXMLStreamReader((Source)source) 
-                    : StaxUtils.createXMLStreamReader((Document)source);
+        XMLStreamReader reader = null;
+        if (source instanceof Source) {
+            reader = StaxUtils.createXMLStreamReader((Source)source);
+        } else if (source instanceof Document) {
+            reader = StaxUtils.createXMLStreamReader((Document)source);
+        } else {
+            reader = StaxUtils.createXMLStreamReader(new DOMSource((Node)source));
+        }
         XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, encoding);
         try {
             StaxUtils.copy(reader, writer);