cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6103] Updating IgnoreNamespaceWriter to optionally block xsi attributes
Date Fri, 14 Nov 2014 22:03:12 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4681cb3b5 -> 632d7dd86


[CXF-6103] Updating IgnoreNamespaceWriter to optionally block xsi attributes


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

Branch: refs/heads/3.0.x-fixes
Commit: 632d7dd866f508e746f94129f8cc1e4889e2b92c
Parents: 4681cb3
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Nov 14 21:58:33 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Nov 14 22:02:51 2014 +0000

----------------------------------------------------------------------
 .../cxf/staxutils/transform/IgnoreNamespacesWriter.java  | 11 ++++++++++-
 .../cxf/jaxrs/provider/aegis/AegisJSONProvider.java      |  2 +-
 .../cxf/jaxrs/provider/json/DataBindingJSONProvider.java |  2 +-
 .../org/apache/cxf/jaxrs/provider/json/JSONProvider.java |  2 +-
 .../apache/cxf/jaxrs/provider/json/utils/JSONUtils.java  | 10 +++++-----
 5 files changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/632d7dd8/core/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
b/core/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
index ea558ed..75d8f9a 100644
--- a/core/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
+++ b/core/src/main/java/org/apache/cxf/staxutils/transform/IgnoreNamespacesWriter.java
@@ -24,13 +24,22 @@ import javax.xml.stream.XMLStreamWriter;
 import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
 
 public class IgnoreNamespacesWriter extends DelegatingXMLStreamWriter {
-    
+    private static final String XSI_PREFIX = "xsi";
+    private boolean ignoreXsiAttributes;
     public IgnoreNamespacesWriter(XMLStreamWriter writer) {
+        this(writer, true);
+    }
+    public IgnoreNamespacesWriter(XMLStreamWriter writer, boolean ignoreXsiAttributes) {
         super(writer);
+        this.ignoreXsiAttributes = ignoreXsiAttributes;
     }
 
     public void writeAttribute(String prefix, String uri, 
                                String local, String value) throws XMLStreamException {
+        if (ignoreXsiAttributes && XSI_PREFIX.equals(prefix)
+            && ("type".equals(local) || "nil".equals(local))) {
+            return;
+        }
         super.writeAttribute(local, value);
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/632d7dd8/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
index 332f60e..3bf5894 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
@@ -136,7 +136,7 @@ public final class AegisJSONProvider<T> extends AegisElementProvider<T>
{
                                           writeXsiType && !ignoreNamespaces, false,
null);
         XMLStreamWriter writer = JSONUtils.createStreamWriter(os, typeQName, 
              writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
dropRootElement, enc);
-        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
+        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/632d7dd8/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
index 0768fc6..a41f577 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
@@ -102,7 +102,7 @@ public class DataBindingJSONProvider<T> extends DataBindingProvider<T>
{
         XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, 
              writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
dropRootElement, enc);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
-        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
+        return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/632d7dd8/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
index d361fd1..c4a410a 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
@@ -573,7 +573,7 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
              writeXsiType && !ignoreNamespaces, config, rootIsArray, theArrayKeys,
              isCollection || dropRootInXmlNeeded, enc);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
-        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
+        writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType);
         return createTransformWriterIfNeeded(writer, os, dropElementsInXmlStreamProp);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/632d7dd8/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
index c194cfc..b12d1db 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
@@ -42,7 +42,6 @@ import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
 import org.apache.cxf.staxutils.DocumentDepthProperties;
 import org.apache.cxf.staxutils.transform.IgnoreNamespacesWriter;
-import org.apache.cxf.wsdl.WSDLConstants;
 import org.codehaus.jettison.AbstractXMLStreamWriter;
 import org.codehaus.jettison.badgerfish.BadgerFishXMLInputFactory;
 import org.codehaus.jettison.badgerfish.BadgerFishXMLOutputFactory;
@@ -56,7 +55,7 @@ import org.codehaus.jettison.mapped.TypeConverter;
 public final class JSONUtils {
 
     public static final String XSI_PREFIX = "xsi";
-    public static final String XSI_URI = WSDLConstants.NS_SCHEMA_XSI; 
+    public static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance"; 
     
     private JSONUtils() {
     }
@@ -121,8 +120,9 @@ public final class JSONUtils {
     }
     
     public static XMLStreamWriter createIgnoreNsWriterIfNeeded(XMLStreamWriter writer, 
-                                                               boolean ignoreNamespaces)
{
-        return ignoreNamespaces ? new IgnoreNamespacesWriter(writer) : writer; 
+                                                               boolean ignoreNamespaces,
+                                                               boolean ignoreXsiAttributes)
{
+        return ignoreNamespaces ? new IgnoreNamespacesWriter(writer, ignoreXsiAttributes)
: writer; 
     }
     
     private static String getKey(MappedNamespaceConvention convention, QName qname) throws
Exception {
@@ -239,7 +239,7 @@ public final class JSONUtils {
         
         public void writeAttribute(String prefix, String uri,
                                    String local, String value) throws XMLStreamException
{
-            if (!writeXsiType && "xsi".equals(prefix)
+            if (!writeXsiType && XSI_PREFIX.equals(prefix)
                     && ("type".equals(local) || "nil".equals(local))) {
                 return;
             }


Mime
View raw message