You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/07/13 19:17:47 UTC

svn commit: r216193 - in /webservices/axis/trunk/java/modules/xml: ./ src/org/apache/axis2/om/ src/org/apache/axis2/om/impl/llom/ test/org/apache/axis2/om/infoset/

Author: dims
Date: Wed Jul 13 10:17:44 2005
New Revision: 216193

URL: http://svn.apache.org/viewcvs?rev=216193&view=rev
Log:
- Add file i forgot in last pass.
- Add the conformance test (will ignore if directory is missing)


Added:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMComment.java   (with props)
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMDocType.java   (with props)
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java   (with props)
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java   (with props)
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java   (with props)
Modified:
    webservices/axis/trunk/java/modules/xml/project.xml

Modified: webservices/axis/trunk/java/modules/xml/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/project.xml?rev=216193&r1=216192&r2=216193&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/project.xml (original)
+++ webservices/axis/trunk/java/modules/xml/project.xml Wed Jul 13 10:17:44 2005
@@ -103,6 +103,7 @@
             </properties>
             <url>http://dist.codehaus.org/stax/jars/</url>
         </dependency>
+        
         <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
@@ -132,6 +133,17 @@
             </properties>
             <url>http://dist.codehaus.org/stax/jars/</url>
         </dependency>
+        
+        <dependency>
+            <groupId>xmlunit</groupId>
+            <artifactId>xmlunit</artifactId>
+            <version>1.0</version>
+            <properties>
+                <module>true</module>
+            </properties>
+            <url>http://www.ibiblio.org/maven/xmlunit/jars/</url>
+        </dependency>
+
         <dependency>
             <groupId>geronimo-spec</groupId>
             <artifactId>geronimo-spec-javamail</artifactId>
@@ -140,6 +152,7 @@
                 <module>true</module>
             </properties>
         </dependency>
+        
         <dependency>
             <groupId>geronimo-spec</groupId>
             <artifactId>geronimo-spec-activation</artifactId>

Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMComment.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMComment.java?rev=216193&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMComment.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMComment.java Wed Jul 13 10:17:44 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.om;
+
+/**
+ * Interface OMComment
+ */
+public interface OMComment extends OMNode {
+    /**
+     * Returns the value of this comment as defined by XPath 1.0.
+     * @return string
+     */
+    public String getValue();
+
+    /**
+     * Sets the content of this comment to the specified string.
+     * @param text
+     */
+    public void setValue(String text);
+}

Propchange: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMComment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMDocType.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMDocType.java?rev=216193&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMDocType.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMDocType.java Wed Jul 13 10:17:44 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.axis2.om;
+
+/**
+ * Interface OMDocType
+ */
+public interface OMDocType extends OMNode {
+    /**
+     * Returns the value of this DocType
+     * @return string
+     */
+    public String getValue();
+
+    /**
+     * Sets the content of this DocType to the specified string.
+     * @param text
+     */
+    public void setValue(String text);
+}

Propchange: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMDocType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java?rev=216193&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java Wed Jul 13 10:17:44 2005
@@ -0,0 +1,111 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.axis2.om.impl.llom;
+
+import org.apache.axis2.om.OMComment;
+import org.apache.axis2.om.OMContainer;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMOutput;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class OMCommentImpl extends OMNodeImpl implements OMComment {
+    protected String value;
+
+    /**
+     * Constructor OMCommentImpl
+     *
+     * @param parentNode
+     * @param contentText
+     */
+    public OMCommentImpl(OMContainer parentNode, String contentText) {
+        super(parentNode);
+        this.value = contentText;
+        nodeType = OMNode.COMMENT_NODE;
+    }
+
+    /**
+     * Constructor OMCommentImpl
+     *
+     * @param parentNode
+     */
+    public OMCommentImpl(OMContainer parentNode) {
+        this(parentNode, null);
+    }
+
+    /**
+     * Serialize the node with caching
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     * @see #serializeWithCache(OMOutput)
+     */
+    public void serializeWithCache(OMOutput omOutput) throws XMLStreamException {
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        writer.writeCharacters("<!--");
+        writer.writeCharacters(this.value);
+        writer.writeCharacters("-->");
+        OMNode nextSibling = this.getNextSibling();
+        if (nextSibling != null) {
+            nextSibling.serializeWithCache(omOutput);
+        }
+    }
+
+    /**
+     * Serialize the node without caching
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     * @see #serialize(OMOutput)
+     */
+    public void serialize(OMOutput omOutput) throws XMLStreamException {
+        serializeWithCache(omOutput);
+    }
+
+    /**
+     * get the value of this comment
+     *
+     * @return string
+     */
+    public String getValue() {
+        return value;
+    }
+
+    /**
+     * set the value of this comment
+     *
+     * @param text
+     */
+    public void setValue(String text) {
+        this.value = text;
+    }
+
+    /**
+     * discard this node
+     *
+     * @throws OMException
+     */
+    public void discard() throws OMException {
+        if (done) {
+            this.detach();
+        } else {
+            builder.discard((OMElement) this.parent);
+        }
+    }
+}

Propchange: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMCommentImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java?rev=216193&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java Wed Jul 13 10:17:44 2005
@@ -0,0 +1,134 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.axis2.om.impl.llom;
+
+import org.apache.axis2.om.OMContainer;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMOutput;
+import org.apache.axis2.om.OMProcessingInstruction;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class OMProcessingInstructionImpl extends OMNodeImpl implements OMProcessingInstruction {
+    protected String target;
+    protected String value;
+
+    /**
+     * Constructor OMProcessingInstructionImpl
+     *
+     * @param parentNode
+     * @param target
+     * @param value
+     */
+    public OMProcessingInstructionImpl(OMContainer parentNode, String target, String value) {
+        super(parentNode);
+        this.target = target;
+        this.value = value;
+        nodeType = OMNode.PI_NODE;
+    }
+
+    /**
+     * Constructor OMProcessingInstructionImpl
+     *
+     * @param parentNode
+     */
+    public OMProcessingInstructionImpl(OMContainer parentNode) {
+        this(parentNode, null, null);
+    }
+
+    /**
+     * Serialize the node with caching
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     * @see #serializeWithCache(OMOutput)
+     */
+    public void serializeWithCache(OMOutput omOutput) throws XMLStreamException {
+        XMLStreamWriter writer = omOutput.getXmlStreamWriter();
+        writer.writeCharacters("<?");
+        writer.writeCharacters(this.target);
+        writer.writeCharacters(" ");
+        writer.writeCharacters(this.value);
+        writer.writeCharacters("?>");
+        OMNode nextSibling = this.getNextSibling();
+        if (nextSibling != null) {
+            nextSibling.serializeWithCache(omOutput);
+        }
+    }
+
+    /**
+     * Serialize the node without caching
+     *
+     * @param omOutput
+     * @throws XMLStreamException
+     * @see #serialize(OMOutput)
+     */
+    public void serialize(OMOutput omOutput) throws XMLStreamException {
+        serializeWithCache(omOutput);
+    }
+
+    /**
+     * get the value of this PI
+     *
+     * @return string
+     */
+    public String getValue() {
+        return value;
+    }
+
+    /**
+     * set the target of this PI
+     *
+     * @param target
+     */
+    public void setTarget(String target) {
+        this.target = target;
+    }
+
+    /**
+     * get the target of this PI
+     *
+     * @return string
+     */
+    public String getTarget() {
+        return target;
+    }
+
+    /**
+     * set the value of this PI
+     *
+     * @param text
+     */
+    public void setValue(String text) {
+        this.value = text;
+    }
+
+    /**
+     * discard this node
+     *
+     * @throws OMException
+     */
+    public void discard() throws OMException {
+        if (done) {
+            this.detach();
+        } else {
+            builder.discard((OMElement) this.parent);
+        }
+    }
+}

Propchange: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMProcessingInstructionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java?rev=216193&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java Wed Jul 13 10:17:44 2005
@@ -0,0 +1,143 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.axis2.om.infoset;
+
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMOutput;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLTestCase;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+
+public class XMLConformanceTest extends XMLTestCase {
+    private static int successCount = 0;
+    private static int parsedCount = 0;
+    private static int fileCount = 0;
+
+    public XMLConformanceTest(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+    }
+
+    public void testXMLConformance() throws Exception {
+        //The 'testSuiteDirectory' value can also be a specific file location
+        //value, needn't necessarily be a directory
+        File testSuiteDirectory = new File("test-resources/XMLSuite/xmlconf");
+        if(testSuiteDirectory.exists()) {
+            ProcessDir(testSuiteDirectory);
+            System.out.println("File count is " + fileCount);
+            System.out.println("Parsed count is " + parsedCount +
+                    ". This is just partial success");
+            System.out.println("Complete success count is " + successCount);
+        } else {
+            System.out.println("Skipping W3C XMLSuite test");
+        }
+    }
+
+    public void ProcessDir(File dir) throws Exception {
+        if (dir.isDirectory()) {
+            //process all children
+            String[] children = dir.list();
+            for (int i = 0; i < children.length; i++) {
+                File child = (new File(dir, children[i]));
+                ProcessDir(child);
+            }
+        } else { //meaning you got a file
+            //check if it's xml file
+            String absPath = dir.getAbsolutePath();
+            if (absPath.endsWith(".xml")) {
+                //process it
+                testSingleFileConformance(absPath);
+                fileCount++;
+            } else {
+                //ignore non .xml files
+            }
+        }
+    }
+
+    public void testSingleFileConformance(String absolutePath)
+            throws Exception {
+        OMElement rootElement;
+        //fileCount++;
+        //get a stax om builder
+        try {
+            StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.
+                    createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+                            XMLInputFactory.newInstance().createXMLStreamReader(
+                                    new FileInputStream(absolutePath), "UTF-8"));
+            rootElement = staxOMBuilder.getDocumentElement();
+        } catch (Exception e) {
+            System.err.println("Exception trying to get hold of rootElement: "
+                    + e.getMessage());
+            System.err.println("in file: " + absolutePath + "\n");
+            return;
+        }
+        //we will write output into the file named TempOutputFile.txt in
+        //current directory
+        String tempFile = "TempOutputFile.txt";
+        XMLStreamWriter writer;
+        try {
+            writer = XMLOutputFactory.newInstance().
+                    createXMLStreamWriter(new FileOutputStream(tempFile));
+            rootElement.serializeWithCache(new OMOutput(writer));
+        } catch (XMLStreamException e) {
+            System.err.println(
+                    "Error in creating XMLStreamWriter to write parsed xml into");
+            return;
+        } catch (Exception e) {
+            System.err.println("Exception while serializing: " +
+                    e.getMessage());
+            System.err.println("in file: " + absolutePath + "\n");
+            return;
+        }
+        writer.flush();
+        writer.close();
+        parsedCount++;
+        //Comparing the equality of the TempOutputFile.txt and the input xml is due
+        Diff diff;
+        try {
+            diff = compareXML(new FileReader(absolutePath), new FileReader(
+                    "TempOutputFile.txt"));
+        } catch (Exception e) {
+            System.out.println("" +
+                    "Error comparing original and generated files for: " +
+                    absolutePath);
+            System.out.println("Error message is: " + e.getMessage());
+            return;
+        }
+        try {
+            assertXMLEqual(diff, true);
+            successCount++;
+        } catch (Error e) {
+            System.out.println("XMLEquality failed for file: " + absolutePath);
+        }
+    }
+
+    public void tearDown() {
+    }
+}

Propchange: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/infoset/XMLConformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native