ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1481294 - in /webservices/axiom/trunk/modules: axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/ axiom-common-impl/src/main...
Date Sat, 11 May 2013 11:20:27 GMT
Author: veithen
Date: Sat May 11 11:20:27 2013
New Revision: 1481294

URL: http://svn.apache.org/r1481294
Log:
Ensure that the SAXSource returned by getSAXSource has the same behavior as OMSource.

Modified:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/Serializer.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransform.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransformOnFragment.java

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/Serializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/Serializer.java?rev=1481294&r1=1481293&r2=1481294&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/Serializer.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/Serializer.java
Sat May 11 11:20:27 2013
@@ -18,7 +18,9 @@
  */
 package org.apache.axiom.om.impl.common.serializer.push;
 
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamException;
@@ -49,12 +51,28 @@ public abstract class Serializer {
     private static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
     private static final String XSI_LOCAL_NAME = "type";
     
+    private final OMSerializable root;
     private final OMElement contextElement;
     private final boolean namespaceRepairing;
+    private final boolean preserveNamespaceContext;
     
-    public Serializer(OMSerializable contextNode, boolean namespaceRepairing) {
-        if (contextNode instanceof OMNode) {
-            OMContainer parent = ((OMNode)contextNode).getParent();
+    /**
+     * Constructor.
+     * 
+     * @param root
+     *            the root node of the object model subtree that is being serialized; this
+     *            information is used by the serializer in scenarios that require access
to the
+     *            namespace context of the parent of the root node
+     * @param namespaceRepairing
+     *            indicates if the serializer should perform namespace repairing
+     * @param preserveNamespaceContext
+     *            indicates if the namespace context determined by the ancestors of the root
node
+     *            should be strictly preserved in the output
+     */
+    public Serializer(OMSerializable root, boolean namespaceRepairing, boolean preserveNamespaceContext)
{
+        this.root = root;
+        if (root instanceof OMNode) {
+            OMContainer parent = ((OMNode)root).getParent();
             if (parent instanceof OMElement) {
                 contextElement = (OMElement)parent; 
             } else {
@@ -64,6 +82,7 @@ public abstract class Serializer {
             contextElement = null;
         }
         this.namespaceRepairing = namespaceRepairing;
+        this.preserveNamespaceContext = preserveNamespaceContext;
     }
 
     public final void serializeStartpart(OMElement element) throws OutputException {
@@ -73,9 +92,30 @@ public abstract class Serializer {
         } else {
             internalBeginStartElement(ns.getPrefix(), ns.getNamespaceURI(), element.getLocalName());
         }
-        for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
-            ns = (OMNamespace)it.next();
-            mapNamespace(ns.getPrefix(), ns.getNamespaceURI(), true, false);
+        if (preserveNamespaceContext && element == root) {
+            // Maintain a set of the prefixes we have already seen. This is required to take
into
+            // account that a namespace mapping declared on an element can hide another one
declared
+            // for the same prefix on an ancestor of the element.
+            Set/*<String>*/ seenPrefixes = new HashSet();
+            OMElement current = element;
+            while (true) {
+                for (Iterator it = current.getAllDeclaredNamespaces(); it.hasNext(); ) {
+                    ns = (OMNamespace)it.next();
+                    if (seenPrefixes.add(ns.getPrefix())) {
+                        mapNamespace(ns.getPrefix(), ns.getNamespaceURI(), true, false);
+                    }
+                }
+                OMContainer parent = current.getParent();
+                if (!(parent instanceof OMElement)) {
+                    break;
+                }
+                current = (OMElement)parent;
+            }
+        } else {
+            for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
+                ns = (OMNamespace)it.next();
+                mapNamespace(ns.getPrefix(), ns.getNamespaceURI(), true, false);
+            }
         }
         for (Iterator it = element.getAllAttributes(); it.hasNext(); ) {
             OMAttribute attr = (OMAttribute)it.next();

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java?rev=1481294&r1=1481293&r2=1481294&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java
Sat May 11 11:20:27 2013
@@ -45,8 +45,8 @@ public class SAXSerializer extends Seria
     private int depth;
     private final SAXHelper helper = new SAXHelper();
     
-    public SAXSerializer(OMSerializable contextNode, ContentHandler contentHandler, LexicalHandler
lexicalHandler) {
-        super(contextNode, false);
+    public SAXSerializer(OMSerializable root, ContentHandler contentHandler, LexicalHandler
lexicalHandler) {
+        super(root, false, true);
         this.contentHandler = contentHandler;
         this.lexicalHandler = lexicalHandler;
     }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java?rev=1481294&r1=1481293&r2=1481294&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java
Sat May 11 11:20:27 2013
@@ -43,8 +43,8 @@ public class StAXSerializer extends Seri
     private final XMLStreamWriter writer;
     private DataHandlerWriter dataHandlerWriter;
     
-    public StAXSerializer(OMSerializable contextNode, XMLStreamWriter writer) {
-        super(contextNode, true);
+    public StAXSerializer(OMSerializable root, XMLStreamWriter writer) {
+        super(root, true, false);
         this.writer = writer;
     }
 

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1481294&r1=1481293&r2=1481294&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
(original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Sat May 11 11:20:27 2013
@@ -261,8 +261,10 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestGetQNameWithoutNamespace(metaFactory));
         for (int i=0; i<XSLTImplementation.INSTANCES.length; i++) {
             XSLTImplementation xsltImplementation = XSLTImplementation.INSTANCES[i];
-            addTest(new org.apache.axiom.ts.om.element.TestGetSAXSourceIdentityTransform(metaFactory,
xsltImplementation));
-            addTest(new org.apache.axiom.ts.om.element.TestGetSAXSourceIdentityTransformOnFragment(metaFactory,
xsltImplementation));
+            addTest(new org.apache.axiom.ts.om.element.TestGetSAXSourceIdentityTransform(metaFactory,
xsltImplementation, true));
+            addTest(new org.apache.axiom.ts.om.element.TestGetSAXSourceIdentityTransform(metaFactory,
xsltImplementation, false));
+            addTest(new org.apache.axiom.ts.om.element.TestGetSAXSourceIdentityTransformOnFragment(metaFactory,
xsltImplementation, true));
+            addTest(new org.apache.axiom.ts.om.element.TestGetSAXSourceIdentityTransformOnFragment(metaFactory,
xsltImplementation, false));
         }
         addTest(new org.apache.axiom.ts.om.element.TestGetText(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetTextAsQName(metaFactory));

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransform.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransform.java?rev=1481294&r1=1481293&r2=1481294&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransform.java
(original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransform.java
Sat May 11 11:20:27 2013
@@ -33,17 +33,19 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLBuilderFactory;
 import org.apache.axiom.om.impl.jaxp.OMResult;
-import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.testutils.suite.XSLTImplementation;
 import org.apache.axiom.ts.AxiomTestCase;
 
 public class TestGetSAXSourceIdentityTransform extends AxiomTestCase {
     private final XSLTImplementation xsltImplementation;
+    private final boolean cache;
 
-    public TestGetSAXSourceIdentityTransform(OMMetaFactory metaFactory, XSLTImplementation
xsltImplementation) {
+    public TestGetSAXSourceIdentityTransform(OMMetaFactory metaFactory, XSLTImplementation
xsltImplementation, boolean cache) {
         super(metaFactory);
         this.xsltImplementation = xsltImplementation;
+        this.cache = cache;
         xsltImplementation.addTestParameters(this);
+        addTestParameter("cache", String.valueOf(cache));
     }
 
     private InputStream getInput() {
@@ -55,9 +57,8 @@ public class TestGetSAXSourceIdentityTra
         
         OMFactory factory = metaFactory.getOMFactory();
         OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, getInput()).getDocumentElement();
-        OMSource omSource = new OMSource(element);
         OMResult omResult = new OMResult(factory);
-        transformer.transform(omSource, omResult);
+        transformer.transform(element.getSAXSource(cache), omResult);
         
         StreamSource streamSource = new StreamSource(getInput());
         StringWriter out = new StringWriter();

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransformOnFragment.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransformOnFragment.java?rev=1481294&r1=1481293&r2=1481294&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransformOnFragment.java
(original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetSAXSourceIdentityTransformOnFragment.java
Sat May 11 11:20:27 2013
@@ -51,11 +51,14 @@ import org.apache.axiom.ts.AxiomTestCase
  */
 public class TestGetSAXSourceIdentityTransformOnFragment extends AxiomTestCase {
     private final XSLTImplementation xsltImplementation;
+    private final boolean cache;
 
-    public TestGetSAXSourceIdentityTransformOnFragment(OMMetaFactory metaFactory, XSLTImplementation
xsltImplementation) {
+    public TestGetSAXSourceIdentityTransformOnFragment(OMMetaFactory metaFactory, XSLTImplementation
xsltImplementation, boolean cache) {
         super(metaFactory);
         this.xsltImplementation = xsltImplementation;
+        this.cache = cache;
         xsltImplementation.addTestParameters(this);
+        addTestParameter("cache", String.valueOf(cache));
     }
 
     private InputStream getInput() {
@@ -67,9 +70,8 @@ public class TestGetSAXSourceIdentityTra
         
         OMFactory factory = metaFactory.getOMFactory();
         OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, getInput()).getDocumentElement().getFirstElement();
-        OMSource omSource = new OMSource(element);
         OMResult omResult = new OMResult(factory);
-        transformer.transform(omSource, omResult);
+        transformer.transform(element.getSAXSource(cache), omResult);
         
         OMNamespace ns = omResult.getRootElement().findNamespaceURI("p");
         assertNotNull(ns);



Mime
View raw message