You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/08/29 08:42:53 UTC

svn commit: r264092 - in /webservices/axis/trunk/java/modules/xml: src/org/apache/axis2/om/impl/llom/OMTextImpl.java src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java test-resources/xml/spaces.xml test/org/apache/axis2/om/SpacesTest.java

Author: chinthaka
Date: Sun Aug 28 23:42:36 2005
New Revision: 264092

URL: http://svn.apache.org/viewcvs?rev=264092&view=rev
Log:
- adding test case for space handling with a sample xml

Added:
    webservices/axis/trunk/java/modules/xml/test-resources/xml/spaces.xml
    webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/SpacesTest.java
Modified:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=264092&r1=264091&r2=264092&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Sun Aug 28 23:42:36 2005
@@ -307,8 +307,10 @@
                 this.serializeStartpart(omOutput);
                 omOutput.writeOptimized(this);
                 omOutput.getXmlStreamWriter().writeEndElement();
-            } else {
+            } else if(this.getType() == OMNode.TEXT_NODE){
                 omOutput.getXmlStreamWriter().writeCharacters(this.getText());
+            }else if(this.getType() == OMNode.CDATA_SECTION_NODE){
+                omOutput.getXmlStreamWriter().writeCData(this.getText());
             }
 
         }

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java?rev=264092&r1=264091&r2=264092&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java Sun Aug 28 23:42:36 2005
@@ -304,4 +304,8 @@
     public OMDocument getDocument() {
         return document;
     }
+
+    public void setDoDebug(boolean doDebug) {
+        this.doDebug = doDebug;
+    }
 }

Added: webservices/axis/trunk/java/modules/xml/test-resources/xml/spaces.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test-resources/xml/spaces.xml?rev=264092&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test-resources/xml/spaces.xml (added)
+++ webservices/axis/trunk/java/modules/xml/test-resources/xml/spaces.xml Sun Aug 28 23:42:36 2005
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<foo>
+    <bar>baz
+        <cheese id="3"/>
+        baz
+        <cheese/>
+        baz
+    </bar>
+    <!--<doc><![CDATA[<foo>]]></doc>-->
+</foo>
\ No newline at end of file

Added: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/SpacesTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/SpacesTest.java?rev=264092&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/SpacesTest.java (added)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/SpacesTest.java Sun Aug 28 23:42:36 2005
@@ -0,0 +1,108 @@
+package org.apache.axis2.om;
+
+import org.apache.axis2.om.impl.OMOutputImpl;
+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 org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.*;
+
+/*
+ * Copyright 2001-2004 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.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public class SpacesTest extends XMLTestCase {
+    private String filePath = "test-resources/xml/spaces.xml";
+
+
+    private OMElement rootElement;
+
+    protected void setUp() throws Exception {
+    }
+
+    public void testCData() throws Exception {
+        checkOMConformance(new FileInputStream(filePath));
+    }
+
+    private void checkOMConformance(InputStream iStream) throws Exception {
+        try {
+            XMLInputFactory factory = XMLInputFactory.newInstance();
+//            factory.setProperty("report-cdata-event", Boolean.TRUE);
+
+            StAXOMBuilder staxOMBuilder = OMXMLBuilderFactory.
+                    createStAXOMBuilder(OMAbstractFactory.getOMFactory(),
+                            factory.createXMLStreamReader(
+                                    iStream));
+            staxOMBuilder.setDoDebug(true);
+            rootElement = staxOMBuilder.getDocumentElement();
+
+            XMLStreamWriter writer;
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            writer = XMLOutputFactory.newInstance().
+                    createXMLStreamWriter(baos);
+
+            ((OMDocument) rootElement.getParent()).serializeWithCache(new OMOutputImpl(writer));
+
+            writer.flush();
+            writer.close();
+
+            System.out.println("XML = " + new String(baos.toByteArray()));
+
+            InputSource resultXML = new InputSource(new InputStreamReader(
+                    new ByteArrayInputStream(baos.toByteArray())));
+
+            Document dom1 = newDocument(new InputSource(new FileInputStream(filePath)));
+            Document dom2 = newDocument(resultXML);
+
+            Diff diff = compareXML(dom1, dom2);
+            assertXMLEqual(diff, true);
+        } catch (XMLStreamException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        } catch (ParserConfigurationException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        } catch (SAXException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        } catch (IOException e) {
+            fail(e.getMessage());
+            throw new Exception(e);
+        }
+    }
+
+    public Document newDocument(InputSource in)
+            throws ParserConfigurationException, SAXException, IOException {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        return db.parse(in);
+    }
+
+
+}