You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/04/15 21:56:26 UTC

svn commit: r765334 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src: main/java/org/apache/axiom/om/impl/serialize/ test/java/org/apache/axiom/om/impl/serialize/

Author: veithen
Date: Wed Apr 15 19:56:26 2009
New Revision: 765334

URL: http://svn.apache.org/viewvc?rev=765334&view=rev
Log:
StreamingOMSerializer:
* Added more thorough tests.
* Support PROCESSING_INSTRUCTION and SPACE events.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=765334&r1=765333&r2=765334&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java Wed Apr 15 19:56:26 2009
@@ -134,6 +134,7 @@
                     serializeAttributes(reader, writer);
                     break;
                 case CHARACTERS:
+                case SPACE:
                     serializeText(reader, writer);
                     break;
                 case COMMENT:
@@ -142,6 +143,9 @@
                 case CDATA:
                     serializeCData(reader, writer);
                     break;
+                case PROCESSING_INSTRUCTION:
+                    serializeProcessingInstruction(reader, writer);
+                    break;
                 case END_ELEMENT:
                     serializeEndElement(writer);
                     depth--;
@@ -448,6 +452,19 @@
     }
 
     /**
+     * Method serializeProcessingInstruction.
+     *
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeProcessingInstruction(XMLStreamReader reader,
+                                                  XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.writeProcessingInstruction(reader.getPITarget(), reader.getPIData());
+    }
+
+    /**
      * @param reader
      * @param writer
      * @throws XMLStreamException

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java?rev=765334&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java Wed Apr 15 19:56:26 2009
@@ -0,0 +1,68 @@
+/*
+ * 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.serialize;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestSuite;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.xml.sax.InputSource;
+
+public class StreamingOMSerializerTest extends AbstractTestCase {
+    private final String file;
+
+    public StreamingOMSerializerTest(String name, String file) {
+        super(name);
+        this.file = file;
+    }
+
+    protected void runTest() throws Throwable {
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        // Allow CDATA events
+        inputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
+        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+        StreamingOMSerializer serializer = new StreamingOMSerializer();
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out);
+        writer.writeStartDocument();
+        serializer.serialize(inputFactory.createXMLStreamReader(getTestResource(file)), writer, false);
+        writer.writeEndDocument();
+        assertXMLIdentical(compareXML(toDocumentWithoutDTD(getTestResource(file)),
+                toDocumentWithoutDTD(new ByteArrayInputStream(out.toByteArray()))), true);
+    }
+
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite();
+        String[] files = getConformanceTestFiles();
+        for (int i=0; i<files.length; i++) {
+            String file = files[i];
+            int idx = file.lastIndexOf('/');
+            String name = file.substring(idx+1);
+            suite.addTest(new StreamingOMSerializerTest(name, file));
+        }
+        return suite;
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native