ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1483068 - in /webservices/axiom/trunk/modules: axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ axiom-tests/src/test/resources/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/...
Date Wed, 15 May 2013 20:20:04 GMT
Author: veithen
Date: Wed May 15 20:20:03 2013
New Revision: 1483068

URL: http://svn.apache.org/r1483068
Log:
AXIOM-452: Ensure that the XMLStreamReader returned by getXMLStreamReader correctly implements
the DTDReader extension.

Added:
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReader.java
  (with props)
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReaderFromParser.java
  (with props)
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/package.html
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/resources/web_w_dtd.xml
      - copied unchanged from r1481967, webservices/axiom/trunk/modules/axiom-tests/src/test/resources/web_w_dtd.xml
Removed:
    webservices/axiom/trunk/modules/axiom-tests/src/test/resources/web_w_dtd.xml
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

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=1483068&r1=1483067&r2=1483068&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
Wed May 15 20:20:03 2013
@@ -24,12 +24,13 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.util.StreamReaderDelegate;
 
+import org.apache.axiom.ext.stax.DTDReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMDataSource;
 import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 
-final class StreamSwitch extends StreamReaderDelegate implements DataHandlerReader {
+final class StreamSwitch extends StreamReaderDelegate implements DataHandlerReader, DTDReader
{
     /**
      * Indicates if an OMSourcedElement with an OMDataSource should
      * be considered as an interior node or a leaf node.
@@ -37,15 +38,26 @@ final class StreamSwitch extends StreamR
     private boolean isDataSourceALeaf;
 
     /**
-     * The {@link DataHandlerReader} extension of the underlying parser, or <code>null</code>
-     * if the parser doesn't support this extension.
+     * The {@link DataHandlerReader} extension of the parent, or <code>null</code>
if the parser
+     * doesn't support this extension.
      */
     private DataHandlerReader dataHandlerReader;
+    
+    /**
+     * The {@link DTDReader} extension of the parent, or <code>null</code> if
the parser doesn't
+     * support this extension.
+     */
+    private DTDReader dtdReader;
 
     public void setParent(XMLStreamReader reader) {
         super.setParent(reader);
         dataHandlerReader =
                 reader == null ? null : XMLStreamReaderUtils.getDataHandlerReader(reader);
+        try {
+            dtdReader = (DTDReader)reader.getProperty(DTDReader.PROPERTY);
+        } catch (IllegalArgumentException ex) {
+            dtdReader = null;
+        }
     }
 
     OMDataSource getDataSource() {
@@ -128,6 +140,8 @@ final class StreamSwitch extends StreamR
         Object value = XMLStreamReaderUtils.processGetProperty(this, name);
         if (value != null) {
             return value;
+        } else if (DTDReader.PROPERTY.equals(name)) {
+            return this;
         } else {
             return super.getProperty(name);
         }
@@ -180,4 +194,28 @@ final class StreamSwitch extends StreamR
             throw new IllegalStateException();
         }
     }
+
+    public String getRootName() {
+        if (dtdReader != null) {
+            return dtdReader.getRootName();
+        } else {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    public String getPublicId() {
+        if (dtdReader != null) {
+            return dtdReader.getPublicId();
+        } else {
+            throw new UnsupportedOperationException();
+        }
+    }
+
+    public String getSystemId() {
+        if (dtdReader != null) {
+            return dtdReader.getSystemId();
+        } else {
+            throw new UnsupportedOperationException();
+        }
+    }
 }

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=1483068&r1=1483067&r2=1483068&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
Wed May 15 20:20:03 2013
@@ -35,6 +35,7 @@ import javax.xml.stream.XMLStreamExcepti
 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;
 import org.apache.axiom.om.OMAttribute;
@@ -67,7 +68,7 @@ import org.apache.commons.logging.LogFac
  * Class used internally by {@link OMStAXWrapper}.
  */
 class SwitchingWrapper extends AbstractXMLStreamReader
-    implements DataHandlerReader, CharacterDataReader, XMLStreamConstants {
+    implements DataHandlerReader, CharacterDataReader, DTDReader, XMLStreamConstants {
     
     private static final Log log = LogFactory.getLog(SwitchingWrapper.class);
     
@@ -849,7 +850,7 @@ class SwitchingWrapper extends AbstractX
         if (value != null) {
             return value;
         }
-        if (CharacterDataReader.PROPERTY.equals(s)) {
+        if (CharacterDataReader.PROPERTY.equals(s) || DTDReader.PROPERTY.equals(s)) {
             return this;
         }
         if (parser != null) {
@@ -1021,6 +1022,38 @@ class SwitchingWrapper extends AbstractX
     /*
      *
      * ################################################################
+     * DTDReader extension methods
+     * ################################################################
+     *
+     */
+
+    public String getRootName() {
+        if (currentEvent == DTD) {
+            return ((OMDocType)node).getRootName();
+        } else {
+            throw new IllegalStateException();
+        }
+    }
+
+    public String getPublicId() {
+        if (currentEvent == DTD) {
+            return ((OMDocType)node).getPublicId();
+        } else {
+            throw new IllegalStateException();
+        }
+    }
+
+    public String getSystemId() {
+        if (currentEvent == DTD) {
+            return ((OMDocType)node).getSystemId();
+        } else {
+            throw new IllegalStateException();
+        }
+    }
+
+    /*
+     *
+     * ################################################################
      * Generator methods for the OMNodes returned by the navigator
      * ################################################################
      *

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=1483068&r1=1483067&r2=1483068&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
Wed May 15 20:20:03 2013
@@ -159,6 +159,10 @@ 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.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));
+        addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReaderFromParser(metaFactory,
false, false));
         addTest(new org.apache.axiom.ts.om.element.TestAddAttributeAlreadyOwnedByElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestAddAttributeAlreadyOwnedByOtherElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestAddAttributeFromOMAttributeMultiple(metaFactory));

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReader.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReader.java?rev=1483068&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReader.java
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReader.java
Wed May 15 20:20:03 2013
@@ -0,0 +1,55 @@
+/*
+ * 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 javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.ext.stax.DTDReader;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the {@link XMLStreamReader} returned by {@link OMContainer#getXMLStreamReader()}
for a
+ * programmatically created OM tree correctly implements the {@link DTDReader} extension.
+ */
+public class TestDTDReader extends AxiomTestCase {
+    public TestDTDReader(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMDocument document = factory.createOMDocument();
+        factory.createOMDocType(document, "root", "-//MY//DTD", "my.dtd", "<!ELEMENT root
(#PCDATA)>");
+        factory.createOMElement("root", null, document);
+        XMLStreamReader reader = document.getXMLStreamReader();
+        // Note that according to the specification of the DTDReader interface, it is
+        // allowed to look up the extension before reaching the DTD event.
+        DTDReader dtdReader = (DTDReader)reader.getProperty(DTDReader.PROPERTY);
+        assertNotNull(dtdReader);
+        assertEquals(XMLStreamReader.DTD, reader.next());
+        assertEquals("root", dtdReader.getRootName());
+        assertEquals("-//MY//DTD", dtdReader.getPublicId());
+        assertEquals("my.dtd", dtdReader.getSystemId());
+        assertEquals("<!ELEMENT root (#PCDATA)>", reader.getText());
+    }
+}

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

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReaderFromParser.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReaderFromParser.java?rev=1483068&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReaderFromParser.java
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestDTDReaderFromParser.java
Wed May 15 20:20:03 2013
@@ -0,0 +1,66 @@
+/*
+ * 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 javax.xml.stream.XMLStreamReader;
+
+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.om.util.StAXParserConfiguration;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the {@link XMLStreamReader} returned by {@link OMContainer#getXMLStreamReader()}
for
+ * an OM tree created by a builder correctly implements the {@link DTDReader} extension.
+ */
+public class TestDTDReaderFromParser extends AxiomTestCase {
+    private final boolean build;
+    private final boolean cache;
+    
+    public TestDTDReaderFromParser(OMMetaFactory metaFactory, boolean build, boolean cache)
{
+        super(metaFactory);
+        this.build = build;
+        this.cache = cache;
+        addTestParameter("build", build);
+        addTestParameter("cache", cache);
+    }
+
+    protected void runTest() throws Throwable {
+        OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
+                StAXParserConfiguration.STANDALONE,
+                TestDTDReaderFromParser.class.getResourceAsStream("/web_w_dtd.xml")).getDocument();
+        if (build) {
+            doc.build();
+        }
+        XMLStreamReader reader = doc.getXMLStreamReader(cache);
+        // Note that according to the specification of the DTDReader interface, it is
+        // allowed to look up the extension before reaching the DTD event.
+        DTDReader dtdReader = (DTDReader)reader.getProperty(DTDReader.PROPERTY);
+        assertNotNull(dtdReader);
+        while (reader.next() != XMLStreamReader.DTD) {
+            // Just loop
+        }
+        assertEquals("web-app", dtdReader.getRootName());
+        assertEquals("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", dtdReader.getPublicId());
+        assertEquals("http://java.sun.com/dtd/web-app_2_3.dtd", dtdReader.getSystemId());
+    }
+}

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

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/package.html
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/package.html?rev=1483068&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/package.html
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/package.html
Wed May 15 20:20:03 2013
@@ -0,0 +1,24 @@
+<!--
+  ~ 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.
+  -->
+<html>
+<body>
+Contains test cases that validate the behavior of specific {@link javax.xml.stream.XMLStreamReader}
methods
+on the instance returned by {@link org.apache.axiom.om.OMContainer#getXMLStreamReader(boolean)}.
+</body>
+</html>
\ No newline at end of file



Mime
View raw message