ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1481531 - in /webservices/axiom/trunk/modules: axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/elem...
Date Sun, 12 May 2013 11:54:48 GMT
Author: veithen
Date: Sun May 12 11:54:47 2013
New Revision: 1481531

URL: http://svn.apache.org/r1481531
Log:
AXIOM-288: Fixed an issue with the getElementText method of the XMLStreamReader returned by
getXMLStreamReaderWithoutCaching that occurs if the reader needs to switch to pull-through
mode in the middle of the element.

Modified:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.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/sr/TestGetElementTextFromParser.java

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java?rev=1481531&r1=1481530&r2=1481531&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/StreamSwitch.java
Sun May 12 11:54:47 2013
@@ -67,4 +67,44 @@ final class StreamSwitch extends StreamR
         }
         return eventType;
     }
+
+    public String getElementText() throws XMLStreamException {
+        // getElementText is tricky for the same reasons as nextTag.
+        String text = super.getElementText();
+        if (text != null) {
+            return text;
+        } else {
+            ///////////////////////////////////////////////////////
+            //// Code block directly from the API documentation ///
+            if (getEventType() != XMLStreamConstants.START_ELEMENT) {
+                throw new XMLStreamException(
+                        "parser must be on START_ELEMENT to read next text", getLocation());
+            }
+            int eventType = next();
+            StringBuffer content = new StringBuffer();
+            while (eventType != XMLStreamConstants.END_ELEMENT) {
+                if (eventType == XMLStreamConstants.CHARACTERS
+                        || eventType == XMLStreamConstants.CDATA
+                        || eventType == XMLStreamConstants.SPACE
+                        || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
+                    content.append(getText());
+                } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+                        || eventType == XMLStreamConstants.COMMENT) {
+                    // skipping
+                } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
+                    throw new XMLStreamException(
+                            "unexpected end of document when reading element text content");
+                } else if (eventType == XMLStreamConstants.START_ELEMENT) {
+                    throw new XMLStreamException(
+                            "element text content may not contain START_ELEMENT");
+                } else {
+                    throw new XMLStreamException(
+                            "Unexpected event type " + eventType, getLocation());
+                }
+                eventType = next();
+            }
+            return content.toString();
+            ///////////////////////////////////////////////////////////////
+        }
+    }
 }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java?rev=1481531&r1=1481530&r2=1481531&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/SwitchingWrapper.java
Sun May 12 11:54:47 2013
@@ -699,13 +699,8 @@ class SwitchingWrapper extends AbstractX
     }
 
     public String getElementText() throws XMLStreamException {
-        if (parser != null) {
-            String elementText = parser.getElementText();
-            currentEvent = END_ELEMENT;
-            return elementText;
-        } else {
-            return super.getElementText();
-        }
+        // Let StreamSwitch handle this method
+        return null;
     }
 
     /**

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=1481531&r1=1481530&r2=1481531&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
Sun May 12 11:54:47 2013
@@ -350,8 +350,10 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.sr.TestGetElementText(metaFactory));
         for (int i=0; i<builderFactories.length; i++) {
             BuilderFactory bf = builderFactories[i];
-            addTest(new org.apache.axiom.ts.om.element.sr.TestGetElementTextFromParser(metaFactory,
bf, true));
-            addTest(new org.apache.axiom.ts.om.element.sr.TestGetElementTextFromParser(metaFactory,
bf, false));
+            addTest(new org.apache.axiom.ts.om.element.sr.TestGetElementTextFromParser(metaFactory,
bf, true, 0));
+            for (int build=0; build<6; build++) {
+                addTest(new org.apache.axiom.ts.om.element.sr.TestGetElementTextFromParser(metaFactory,
bf, false, build));
+            }
         }
         addTest(new org.apache.axiom.ts.om.element.sr.TestGetNamespaceContext(metaFactory,
true));
         addTest(new org.apache.axiom.ts.om.element.sr.TestGetNamespaceContext(metaFactory,
false));

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestGetElementTextFromParser.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestGetElementTextFromParser.java?rev=1481531&r1=1481530&r2=1481531&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestGetElementTextFromParser.java
(original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestGetElementTextFromParser.java
Sun May 12 11:54:47 2013
@@ -19,9 +19,11 @@
 package org.apache.axiom.ts.om.element.sr;
 
 import java.io.StringReader;
+import java.util.Iterator;
 
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
@@ -32,13 +34,24 @@ import org.xml.sax.InputSource;
 public class TestGetElementTextFromParser extends AxiomTestCase {
     private final BuilderFactory builderFactory;
     private final boolean cache;
+    private final int build;
     
-    public TestGetElementTextFromParser(OMMetaFactory metaFactory, BuilderFactory builderFactory,
boolean cache) {
+    /**
+     * Constructor.
+     * 
+     * @param metaFactory
+     * @param builderFactory
+     * @param cache
+     * @param build the number of descendants that should be built before calling {@link
OMContainer#getXMLStreamReader(boolean)}
+     */
+    public TestGetElementTextFromParser(OMMetaFactory metaFactory, BuilderFactory builderFactory,
boolean cache, int build) {
         super(metaFactory);
         this.builderFactory = builderFactory;
         this.cache = cache;
+        this.build = build;
         builderFactory.addTestParameters(this);
         addTestParameter("cache", Boolean.toString(cache));
+        addTestParameter("build", String.valueOf(build));
     }
 
     protected void runTest() throws Throwable {
@@ -49,6 +62,14 @@ public class TestGetElementTextFromParse
                 new StringReader("<a><b>AB<!--comment text-->CD</b></a>")));
         OMElement element = builder.getDocumentElement();
         
+        // Build a certain number of descendants. This is used to test scenarios where the
XMLStreamReader
+        // needs to switch to pull through mode in the middle of the element from which we
attempt to
+        // get the text.
+        Iterator it = element.getDescendants(true);
+        for (int i=0; i<build; i++) {
+            it.next();
+        }
+        
         XMLStreamReader reader = element.getXMLStreamReader(cache);
         assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
         assertEquals(XMLStreamReader.START_ELEMENT, reader.next());



Mime
View raw message