ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1484163 - 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/docu...
Date Sat, 18 May 2013 19:13:43 GMT
Author: veithen
Date: Sat May 18 19:13:42 2013
New Revision: 1484163

URL: http://svn.apache.org/r1484163
Log:
Correctly handle the CharacterDataReader extension in PullSerializer.

Added:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/NullCharacterDataReader.java
  (with props)
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCharacterDataReaderFromParser.java
  (with props)
Modified:
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.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/AbstractWrapper.java?rev=1484163&r1=1484162&r2=1484163&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
Sat May 18 19:13:42 2013
@@ -18,11 +18,15 @@
  */
 package org.apache.axiom.om.impl.common.serializer.pull;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.ext.stax.CharacterDataReader;
 import org.apache.axiom.ext.stax.DTDReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMDataSource;
@@ -32,7 +36,7 @@ import org.apache.axiom.util.stax.XMLStr
  * Base class for {@link PullSerializerState} implementations that wrap an {@link XMLStreamReader}.
  */
 //TODO: what about the close() method?
-abstract class AbstractWrapper extends PullSerializerState {
+abstract class AbstractWrapper extends PullSerializerState implements CharacterDataReader
{
     protected final XMLStreamReader reader;
     private final PullSerializer serializer;
     private int depth;
@@ -49,6 +53,12 @@ abstract class AbstractWrapper extends P
      */
     private DataHandlerReader dataHandlerReader;
 
+    /**
+     * The {@link CharacterDataReader} extension of the reader, or <code>null</code>
if the extension
+     * has not yet been retrieved.
+     */
+    private CharacterDataReader characterDataReader;
+
     AbstractWrapper(PullSerializer serializer, XMLStreamReader reader, int startDepth) {
         this.reader = reader;
         this.serializer = serializer;
@@ -79,6 +89,24 @@ abstract class AbstractWrapper extends P
         return dataHandlerReader;
     }
 
+    final CharacterDataReader getCharacterDataReader() {
+        if (characterDataReader == null) {
+            try {
+                characterDataReader = (CharacterDataReader)reader.getProperty(CharacterDataReader.PROPERTY);
+            } catch (IllegalArgumentException ex) {
+                // Continue
+            }
+            if (characterDataReader == null) {
+                characterDataReader = this;
+            }
+        }
+        return characterDataReader;
+    }
+
+    public final void writeTextTo(Writer writer) throws XMLStreamException, IOException {
+        writer.write(reader.getText());
+    }
+
     final int getEventType() {
         return reader.getEventType();
     }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.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/ClosedState.java?rev=1484163&r1=1484162&r2=1484163&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
Sat May 18 19:13:42 2013
@@ -22,6 +22,7 @@ import javax.xml.namespace.NamespaceCont
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
+import org.apache.axiom.ext.stax.CharacterDataReader;
 import org.apache.axiom.ext.stax.DTDReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMDataSource;
@@ -39,6 +40,10 @@ final class ClosedState extends PullSeri
         return NullDataHandlerReader.INSTANCE;
     }
 
+    CharacterDataReader getCharacterDataReader() {
+        return NullCharacterDataReader.INSTANCE;
+    }
+
     void close() throws XMLStreamException {
         // no-op
     }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.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/EndDocumentState.java?rev=1484163&r1=1484162&r2=1484163&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
Sat May 18 19:13:42 2013
@@ -26,6 +26,7 @@ import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.ext.stax.CharacterDataReader;
 import org.apache.axiom.ext.stax.DTDReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMDataSource;
@@ -44,6 +45,10 @@ final class EndDocumentState extends Pul
         return NullDataHandlerReader.INSTANCE;
     }
 
+    CharacterDataReader getCharacterDataReader() {
+        return NullCharacterDataReader.INSTANCE;
+    }
+
     int getEventType() {
         return XMLStreamReader.END_DOCUMENT;
     }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.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/Navigator.java?rev=1484163&r1=1484162&r2=1484163&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
Sat May 18 19:13:42 2013
@@ -58,7 +58,6 @@ import org.apache.axiom.om.impl.builder.
 import org.apache.axiom.om.impl.common.IContainer;
 import org.apache.axiom.om.impl.common.OMDataSourceUtil;
 import org.apache.axiom.util.namespace.MapBasedNamespaceContext;
-import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -159,6 +158,10 @@ final class Navigator extends PullSerial
         return this;
     }
 
+    CharacterDataReader getCharacterDataReader() {
+        return this;
+    }
+
     String getPrefix() {
         if ((currentEvent == START_ELEMENT)
                 || (currentEvent == END_ELEMENT)) {
@@ -275,27 +278,23 @@ final class Navigator extends PullSerial
     }
 
     public void writeTextTo(Writer writer) throws XMLStreamException, IOException {
-        if (parser != null) {
-            XMLStreamReaderUtils.writeTextTo(parser, writer);
-        } else {
-            switch (currentEvent) {
-                case CHARACTERS:
-                case CDATA:
-                case SPACE:
-                    OMText text = (OMText)node;
-                    if (text.isCharacters()) {
-                        writer.write(text.getTextCharacters());
-                    } else {
-                        // TODO: we should cover the binary case in an optimized way
-                        writer.write(text.getText());
-                    }
-                    break;
-                case COMMENT:
-                    writer.write(((OMComment)node).getValue());
-                    break;
-                default:
-                    throw new IllegalStateException();
-            }
+        switch (currentEvent) {
+            case CHARACTERS:
+            case CDATA:
+            case SPACE:
+                OMText text = (OMText)node;
+                if (text.isCharacters()) {
+                    writer.write(text.getTextCharacters());
+                } else {
+                    // TODO: we should cover the binary case in an optimized way
+                    writer.write(text.getText());
+                }
+                break;
+            case COMMENT:
+                writer.write(((OMComment)node).getValue());
+                break;
+            default:
+                throw new IllegalStateException();
         }
     }
 
@@ -697,10 +696,6 @@ final class Navigator extends PullSerial
     }
 
     Object getProperty(String s) throws IllegalArgumentException {
-        // TODO: CharacterDataReader extension needs to be handled in PullSerializer
-        if (CharacterDataReader.PROPERTY.equals(s)) {
-            return this;
-        }
         if (parser != null) {
             return parser.getProperty(s);
         }

Added: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/NullCharacterDataReader.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/NullCharacterDataReader.java?rev=1484163&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/NullCharacterDataReader.java
(added)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/NullCharacterDataReader.java
Sat May 18 19:13:42 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.om.impl.common.serializer.pull;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.ext.stax.CharacterDataReader;
+
+final class NullCharacterDataReader implements CharacterDataReader {
+    static final NullCharacterDataReader INSTANCE = new NullCharacterDataReader();
+    
+    private NullCharacterDataReader() {}
+
+    public void writeTextTo(Writer writer) throws XMLStreamException, IOException {
+        throw new IllegalStateException();
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/NullCharacterDataReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.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/PullSerializer.java?rev=1484163&r1=1484162&r2=1484163&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
Sat May 18 19:13:42 2013
@@ -18,12 +18,16 @@
  */
 package org.apache.axiom.om.impl.common.serializer.pull;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.activation.DataHandler;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.ext.stax.CharacterDataReader;
 import org.apache.axiom.ext.stax.DTDReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
@@ -36,7 +40,7 @@ import org.apache.axiom.util.stax.XMLStr
 /**
  * {@link XMLStreamReader} implementation that generates events from a given Axiom tree.
  */
-public final class PullSerializer extends AbstractXMLStreamReader implements DataHandlerReader,
DTDReader {
+public final class PullSerializer extends AbstractXMLStreamReader implements DataHandlerReader,
DTDReader, CharacterDataReader {
     /**
      * The current state of the serializer.
      */
@@ -142,7 +146,7 @@ public final class PullSerializer extend
         Object value = XMLStreamReaderUtils.processGetProperty(this, name);
         if (value != null) {
             return value;
-        } else if (DTDReader.PROPERTY.equals(name)) {
+        } else if (DTDReader.PROPERTY.equals(name) || CharacterDataReader.PROPERTY.equals(name))
{
             return this;
         } else {
             return state.getProperty(name);
@@ -314,4 +318,8 @@ public final class PullSerializer extend
     public String getSystemId() {
         return state.getDTDReader().getSystemId();
     }
+
+    public void writeTextTo(Writer writer) throws XMLStreamException, IOException {
+        state.getCharacterDataReader().writeTextTo(writer);
+    }
 }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.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/PullSerializerState.java?rev=1484163&r1=1484162&r2=1484163&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
Sat May 18 19:13:42 2013
@@ -24,6 +24,7 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.ext.stax.CharacterDataReader;
 import org.apache.axiom.ext.stax.DTDReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMDataSource;
@@ -60,6 +61,13 @@ abstract class PullSerializerState {
      */
     abstract DataHandlerReader getDataHandlerReader();
     
+    /**
+     * Get the {@link CharacterDataReader} extension.
+     * 
+     * @return the {@link CharacterDataReader} extension; must not be <code>null</code>
+     */
+    abstract CharacterDataReader getCharacterDataReader();
+    
     abstract int getEventType();
 
     abstract boolean hasNext() throws XMLStreamException;

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=1484163&r1=1484162&r2=1484163&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 18 19:13:42 2013
@@ -159,6 +159,8 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.document.TestSetOMDocumentElementNew(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestSetOMDocumentElementNull(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestSetOMDocumentElementReplace(metaFactory));
+        addTest(new org.apache.axiom.ts.om.document.sr.TestCharacterDataReaderFromParser(metaFactory,
true));
+        addTest(new org.apache.axiom.ts.om.document.sr.TestCharacterDataReaderFromParser(metaFactory,
false));
         addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReader(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReaderFromParser(metaFactory,
false, true));
         addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReaderFromParser(metaFactory,
true, true));

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCharacterDataReaderFromParser.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCharacterDataReaderFromParser.java?rev=1484163&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCharacterDataReaderFromParser.java
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCharacterDataReaderFromParser.java
Sat May 18 19:13:42 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.document.sr;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.ext.stax.CharacterDataReader;
+import org.apache.axiom.ext.stax.DTDReader;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the {@link CharacterDataReader} returned by {@link OMContainer#getXMLStreamReader()}
for
+ * an OM tree created by a builder correctly implements the {@link DTDReader} extension.
+ */
+public class TestCharacterDataReaderFromParser extends AxiomTestCase {
+    private final boolean cache;
+    
+    public TestCharacterDataReaderFromParser(OMMetaFactory metaFactory, boolean cache) {
+        super(metaFactory);
+        this.cache = cache;
+        addTestParameter("cache", cache);
+    }
+
+    protected void runTest() throws Throwable {
+        String text = "This is a test for the CharacterDataReader extension";
+        OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
new StringReader("<root>" + text + "</root>")).getDocument();
+        XMLStreamReader reader = doc.getXMLStreamReader(cache);
+        CharacterDataReader cdataReader = (CharacterDataReader)reader.getProperty(CharacterDataReader.PROPERTY);
+        assertNotNull(cdataReader);
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        StringWriter sw = new StringWriter();
+        while (reader.next() == XMLStreamReader.CHARACTERS) {
+            cdataReader.writeTextTo(sw);
+        }
+        assertEquals(text, sw.toString());
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCharacterDataReaderFromParser.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message