You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2013/03/23 23:00:51 UTC
svn commit: r1460240 - in /webservices/axiom/trunk/modules:
axiom-api/src/main/java/org/apache/axiom/om/impl/builder/
axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/
axiom-testsuite/src/main/java/org/apache/axiom/ts...
Author: veithen
Date: Sat Mar 23 22:00:51 2013
New Revision: 1460240
URL: http://svn.apache.org/r1460240
Log:
OMDataSource to SAX serialization (push mode): complete coverage of all XMLStreamWriter methods allowed by OMDataSource#serialize(XMLStreamWriter).
Added:
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteAttributeAutoPrefixScenario.java (with props)
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteCharactersCharArrayScenario.java (with props)
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteEntityRefScenario.java (with props)
Modified:
webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/ContentHandlerXMLStreamWriter.java
webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/PushOMDataSourceScenario.java
Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1460240&r1=1460239&r2=1460240&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Sat Mar 23 22:00:51 2013
@@ -381,6 +381,7 @@ public class SAXOMBuilder extends Defaul
}
public void skippedEntity(String name) throws SAXException {
+ factory.createOMEntityReference(target, name, null, true);
}
public void startEntity(String name) throws SAXException {
Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/ContentHandlerXMLStreamWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/ContentHandlerXMLStreamWriter.java?rev=1460240&r1=1460239&r2=1460240&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/ContentHandlerXMLStreamWriter.java (original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/ContentHandlerXMLStreamWriter.java Sat Mar 23 22:00:51 2013
@@ -150,6 +150,10 @@ final class ContentHandlerXMLStreamWrite
helper.addAttribute(normalize(prefix), normalize(namespaceURI), localName, "CDATA", value);
}
+ public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
+ helper.addAttribute(internalGetPrefix(namespaceURI), normalize(namespaceURI), localName, "CDATA", value);
+ }
+
public void writeAttribute(String localName, String value) throws XMLStreamException {
helper.addAttribute("", "", localName, "CDATA", value);
}
@@ -174,16 +178,20 @@ final class ContentHandlerXMLStreamWrite
}
}
- public void writeCharacters(String text) throws XMLStreamException {
+ public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
finishStartElementIfNecessary();
try {
- char[] ch = text.toCharArray();
- contentHandler.characters(ch, 0, ch.length);
+ contentHandler.characters(text, start, len);
} catch (SAXException ex) {
throw new SAXExceptionWrapper(ex);
}
}
+ public void writeCharacters(String text) throws XMLStreamException {
+ char[] ch = text.toCharArray();
+ writeCharacters(ch, 0, ch.length);
+ }
+
public void writeCData(String data) throws XMLStreamException {
finishStartElementIfNecessary();
try {
@@ -243,6 +251,15 @@ final class ContentHandlerXMLStreamWrite
}
}
+ public void writeEntityRef(String name) throws XMLStreamException {
+ finishStartElementIfNecessary();
+ try {
+ contentHandler.skippedEntity(name);
+ } catch (SAXException ex) {
+ throw new SAXExceptionWrapper(ex);
+ }
+ }
+
public void flush() throws XMLStreamException {
}
@@ -254,17 +271,6 @@ final class ContentHandlerXMLStreamWrite
throw new UnsupportedOperationException();
}
- public void writeAttribute(String namespaceURI, String localName, String value)
- throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException();
- }
-
public void writeDTD(String dtd) throws XMLStreamException {
// TODO
throw new UnsupportedOperationException();
@@ -280,11 +286,6 @@ final class ContentHandlerXMLStreamWrite
throw new UnsupportedOperationException();
}
- public void writeEntityRef(String name) throws XMLStreamException {
- // TODO
- throw new UnsupportedOperationException();
- }
-
public void writeStartDocument() throws XMLStreamException {
// TODO
throw new UnsupportedOperationException();
Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/PushOMDataSourceScenario.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/PushOMDataSourceScenario.java?rev=1460240&r1=1460239&r2=1460240&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/PushOMDataSourceScenario.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/PushOMDataSourceScenario.java Sat Mar 23 22:00:51 2013
@@ -36,13 +36,16 @@ import org.apache.axiom.testutils.suite.
public interface PushOMDataSourceScenario extends Dimension {
PushOMDataSourceScenario[] INSTANCES = {
new GetNamespaceContextScenario(),
+ new WriteAttributeAutoPrefixScenario(),
new WriteAttributeNoNamespaceScenario(),
new WriteCDataScenario(),
+ new WriteCharactersCharArrayScenario(),
new WriteCommentScenario(),
new WriteDataHandlerScenario(),
new WriteDataHandlerProviderScenario(),
new WriteEmptyElementScenario(),
new WriteEmptyElementAutoPrefixScenario(),
+ new WriteEntityRefScenario(),
new WriteNamespaceScenario("", ""),
new WriteNamespaceScenario("", "urn:test"),
new WriteNamespaceScenario("p", "urn:test"),
Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteAttributeAutoPrefixScenario.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteAttributeAutoPrefixScenario.java?rev=1460240&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteAttributeAutoPrefixScenario.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteAttributeAutoPrefixScenario.java Sat Mar 23 22:00:51 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.sourcedelement.push;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.testutils.suite.MatrixTestCase;
+import org.junit.Assert;
+
+/**
+ * Scenario that lets {@link XMLStreamWriter#writeAttribute(String, String, String)} automatically
+ * select an appropriate prefix.
+ */
+public class WriteAttributeAutoPrefixScenario implements PushOMDataSourceScenario {
+ public void addTestParameters(MatrixTestCase testCase) {
+ testCase.addTestParameter("scenario", "writeAttributeAutoPrefix");
+ }
+
+ public Map getNamespaceContext() {
+ return Collections.EMPTY_MAP;
+ }
+
+ public void serialize(XMLStreamWriter writer, Map testContext) throws XMLStreamException {
+ writer.writeStartElement(null, "root", null);
+ writer.writeNamespace("p", "urn:test");
+ writer.setPrefix("p", "urn:test");
+ writer.writeAttribute("urn:test", "attr", "value");
+ writer.writeEndElement();
+ }
+
+ public void validate(OMElement element, boolean dataHandlersPreserved, Map testContext) throws Throwable {
+ Iterator it = element.getAllAttributes();
+ Assert.assertTrue(it.hasNext());
+ OMAttribute attr = (OMAttribute)it.next();
+ Assert.assertEquals("p", attr.getPrefix());
+ Assert.assertEquals("urn:test", attr.getNamespaceURI());
+ Assert.assertEquals("attr", attr.getLocalName());
+ Assert.assertEquals("value", attr.getAttributeValue());
+ }
+}
Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteAttributeAutoPrefixScenario.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteCharactersCharArrayScenario.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteCharactersCharArrayScenario.java?rev=1460240&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteCharactersCharArrayScenario.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteCharactersCharArrayScenario.java Sat Mar 23 22:00:51 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.sourcedelement.push;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.testutils.suite.MatrixTestCase;
+import org.junit.Assert;
+
+/**
+ * Scenario that uses {@link XMLStreamWriter#writeCharacters(char[], int, int)}.
+ */
+public class WriteCharactersCharArrayScenario implements PushOMDataSourceScenario {
+ public void addTestParameters(MatrixTestCase testCase) {
+ testCase.addTestParameter("scenario", "writeCharactersCharArray");
+ }
+
+ public Map getNamespaceContext() {
+ return Collections.EMPTY_MAP;
+ }
+
+ public void serialize(XMLStreamWriter writer, Map testContext) throws XMLStreamException {
+ writer.writeStartElement(null, "root", null);
+ char[] ch = new char[6];
+ "test".getChars(0, 4, ch, 0);
+ writer.writeCharacters(ch, 0, 4);
+ "case".getChars(0, 4, ch, 2);
+ writer.writeCharacters(ch, 2, 4);
+ writer.writeEndElement();
+ }
+
+ public void validate(OMElement element, boolean dataHandlersPreserved, Map testContext) {
+ OMNode child = element.getFirstOMChild();
+ Assert.assertTrue(child instanceof OMText);
+ Assert.assertEquals("test", ((OMText)child).getText());
+ child = child.getNextOMSibling();
+ Assert.assertTrue(child instanceof OMText);
+ Assert.assertEquals("case", ((OMText)child).getText());
+ Assert.assertNull(child.getNextOMSibling());
+ }
+}
Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteCharactersCharArrayScenario.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteEntityRefScenario.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteEntityRefScenario.java?rev=1460240&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteEntityRefScenario.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteEntityRefScenario.java Sat Mar 23 22:00:51 2013
@@ -0,0 +1,58 @@
+/*
+ * 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.sourcedelement.push;
+
+import java.util.Collections;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMEntityReference;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.testutils.suite.MatrixTestCase;
+import org.junit.Assert;
+
+/**
+ * Scenario that uses {@link XMLStreamWriter#writeEntityRef(String)}.
+ */
+public class WriteEntityRefScenario implements PushOMDataSourceScenario {
+ public void addTestParameters(MatrixTestCase testCase) {
+ testCase.addTestParameter("scenario", "writeEntityRef");
+ }
+
+ public Map getNamespaceContext() {
+ return Collections.EMPTY_MAP;
+ }
+
+ public void serialize(XMLStreamWriter writer, Map testContext) throws XMLStreamException {
+ writer.writeStartElement(null, "root", null);
+ writer.writeEntityRef("test");
+ writer.writeEndElement();
+ }
+
+ public void validate(OMElement element, boolean dataHandlersPreserved, Map testContext) {
+ OMNode child = element.getFirstOMChild();
+ Assert.assertTrue(child instanceof OMEntityReference);
+ OMEntityReference entref = (OMEntityReference)child;
+ Assert.assertEquals("test", entref.getName());
+ Assert.assertNull(entref.getReplacementText());
+ }
+}
Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/push/WriteEntityRefScenario.java
------------------------------------------------------------------------------
svn:eol-style = native