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 2016/02/19 21:08:38 UTC
svn commit: r1731293 - in /webservices/axiom/trunk/aspects:
core-aspects/src/main/java/org/apache/axiom/core/stream/
om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/
om-aspects/src/main/java/org/apache/axiom/om/impl/common/seri...
Author: veithen
Date: Fri Feb 19 20:08:38 2016
New Revision: 1731293
URL: http://svn.apache.org/viewvc?rev=1731293&view=rev
Log:
Clean up SerializerImpl.
Modified:
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/XmlHandler.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java
Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/XmlHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/XmlHandler.java?rev=1731293&r1=1731292&r2=1731293&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/XmlHandler.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/stream/XmlHandler.java Fri Feb 19 20:08:38 2016
@@ -26,12 +26,50 @@ public interface XmlHandler {
void processDocumentTypeDeclaration(String rootName, String publicId,
String systemId, String internalSubset) throws StreamException;
+ /**
+ * Prepare to write an element start tag. A call to this method will be followed by zero or more
+ * calls to {@link #processNamespaceDeclaration(String, String)} and
+ * {@link #processAttribute(String, String, String, String, String)} and a single call to
+ * {@link #attributesCompleted()}.
+ *
+ * @param namespaceURI
+ * the namespace URI of the element; never <code>null</code>
+ * @param localName
+ * the local name of the element; never <code>null</code>
+ * @param prefix
+ * the prefix of the element; never <code>null</code>
+ * @throws StreamException
+ */
void startElement(String namespaceURI, String localName, String prefix) throws StreamException;
void endElement() throws StreamException;
+ /**
+ * Add the given attribute to the element.
+ *
+ * @param namespaceURI
+ * the namespace URI or the attribute; never <code>null</code>
+ * @param localName
+ * the local name of the attribute; never <code>null</code>
+ * @param prefix
+ * the namespace prefix of the attribute; never <code>null</code>
+ * @param value
+ * the value of the attribute; never <code>null</code>
+ * @param type
+ * the attribute type (e.g. <tt>CDATA</tt>); never <code>null</code>
+ * @throws StreamException
+ */
void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException;
+ /**
+ * Add the given namespace declaration to the element.
+ *
+ * @param prefix
+ * the namespace prefix; never <code>null</code>
+ * @param namespaceURI
+ * the namespace URI; never <code>null</code>
+ * @throws StreamException
+ */
void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException;
void attributesCompleted() throws StreamException;
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java?rev=1731293&r1=1731292&r2=1731293&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/SerializerImpl.java Fri Feb 19 20:08:38 2016
@@ -18,19 +18,13 @@
*/
package org.apache.axiom.om.impl.common.serializer.push;
-import javax.activation.DataHandler;
-import javax.xml.stream.XMLStreamWriter;
-
import org.apache.axiom.core.CoreElement;
import org.apache.axiom.core.stream.StreamException;
import org.apache.axiom.core.stream.XmlHandler;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMSerializable;
-import org.apache.axiom.om.impl.intf.TextContent;
public abstract class SerializerImpl implements XmlHandler {
/**
@@ -72,98 +66,5 @@ public abstract class SerializerImpl imp
return handler;
}
- public final void processCharacterData(Object data, boolean ignorable) throws StreamException {
- if (data instanceof TextContent) {
- TextContent textContent = (TextContent)data;
- if (textContent.isBinary()) {
- Object dataHandlerObject = textContent.getDataHandlerObject();
- if (dataHandlerObject instanceof DataHandlerProvider) {
- writeDataHandler((DataHandlerProvider)dataHandlerObject, textContent.getContentID(), textContent.isOptimize());
- } else {
- writeDataHandler(textContent.getDataHandler(), textContent.getContentID(), textContent.isOptimize());
- }
- return;
- }
- }
- writeText(ignorable ? OMNode.SPACE_NODE : OMNode.TEXT_NODE, data.toString());
- }
-
- public final void processCDATASection(String content) throws StreamException {
- writeText(OMNode.CDATA_SECTION_NODE, content.toString());
- }
-
protected abstract boolean isAssociated(String prefix, String namespace) throws StreamException;
-
- public abstract void processDocumentTypeDeclaration(String rootName, String publicId, String systemId, String internalSubset) throws StreamException;
-
- /**
- * Prepare to write an element start tag. A call to this method will be followed by zero or more
- * calls to {@link #processNamespaceDeclaration(String, String)} and
- * {@link #processAttribute(String, String, String, String, String)} and a single call to
- * {@link #attributesCompleted()}.
- *
- * @param namespaceURI
- * the namespace URI of the element; never <code>null</code>
- * @param localName
- * the local name of the element; never <code>null</code>
- * @param prefix
- * the prefix of the element; never <code>null</code>
- * @throws StreamException
- */
- public abstract void startElement(String namespaceURI, String localName, String prefix) throws StreamException;
-
- /**
- * Add the given namespace to the element. The implementation of this method must take the
- * appropriate actions such that the following two conditions are satisfied:
- * <ul>
- * <li>A namespace declaration is written to the output.
- * <li>The namespace binding defined by the parameters is visible in the namespace context of
- * the {@link XMLStreamWriter} that {@link #serializePushOMDataSource(OMDataSource)} passes to
- * {@link OMDataSource#serialize(XMLStreamWriter)} if an {@link OMDataSource} is serialized in
- * the scope of the current element (and of course unless the namespace binding is hidden by a
- * namespace defined on a nested element).
- * </ul>
- *
- * @param prefix
- * the namespace prefix; never <code>null</code>
- * @param namespaceURI
- * the namespace URI; never <code>null</code>
- * @throws StreamException
- */
- public abstract void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException;
-
- /**
- * Add the given attribute to the element.
- *
- * @param namespaceURI
- * the namespace URI or the attribute; never <code>null</code>
- * @param localName
- * the local name of the attribute; never <code>null</code>
- * @param prefix
- * the namespace prefix of the attribute; never <code>null</code>
- * @param value
- * the value of the attribute; never <code>null</code>
- * @param type
- * the attribute type (e.g. <tt>CDATA</tt>); never <code>null</code>
- * @throws StreamException
- */
- public abstract void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException;
-
- public abstract void attributesCompleted() throws StreamException;
-
- public abstract void endElement() throws StreamException;
-
- protected abstract void writeText(int type, String data) throws StreamException;
-
- public abstract void processComment(String data) throws StreamException;
-
- public abstract void processProcessingInstruction(String target, String data) throws StreamException;
-
- public abstract void processEntityReference(String name, String replacementText) throws StreamException;
-
- protected abstract void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize) throws StreamException;
-
- protected abstract void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID, boolean optimize) throws StreamException;
-
- public abstract void endDocument() throws StreamException;
}
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java?rev=1731293&r1=1731292&r2=1731293&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/sax/SAXSerializer.java Fri Feb 19 20:08:38 2016
@@ -25,8 +25,8 @@ import javax.activation.DataHandler;
import org.apache.axiom.core.stream.StreamException;
import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
-import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.impl.common.serializer.push.SerializerImpl;
+import org.apache.axiom.om.impl.intf.TextContent;
import org.apache.axiom.util.base64.Base64EncodingWriterOutputStream;
import org.apache.axiom.util.namespace.ScopedNamespaceContext;
import org.xml.sax.ContentHandler;
@@ -149,24 +149,61 @@ public class SAXSerializer extends Seria
}
}
- public void writeText(int type, String data) throws StreamException {
- char[] ch = data.toCharArray();
+ public void processCharacterData(Object data, boolean ignorable) throws StreamException {
try {
- switch (type) {
- case OMNode.TEXT_NODE:
- contentHandler.characters(ch, 0, ch.length);
- break;
- case OMNode.CDATA_SECTION_NODE:
- if (lexicalHandler != null) {
- lexicalHandler.startCDATA();
- }
- contentHandler.characters(ch, 0, ch.length);
- if (lexicalHandler != null) {
- lexicalHandler.endCDATA();
+ if (ignorable) {
+ char[] ch = data.toString().toCharArray();
+ contentHandler.ignorableWhitespace(ch, 0, ch.length);
+ } else {
+ if (data instanceof TextContent) {
+ TextContent textContent = (TextContent)data;
+ if (textContent.isBinary()) {
+ Object dataHandlerObject = textContent.getDataHandlerObject();
+ DataHandler dataHandler;
+ if (dataHandlerObject instanceof DataHandlerProvider) {
+ try {
+ dataHandler = ((DataHandlerProvider)dataHandlerObject).getDataHandler();
+ } catch (IOException ex) {
+ throw new StreamException(ex);
+ }
+ } else {
+ dataHandler = (DataHandler)dataHandlerObject;
+ }
+ Base64EncodingWriterOutputStream out = new Base64EncodingWriterOutputStream(new ContentHandlerWriter(contentHandler), 4096, true);
+ try {
+ dataHandler.writeTo(out);
+ out.complete();
+ } catch (IOException ex) {
+ Throwable cause = ex.getCause();
+ SAXException saxException;
+ if (cause instanceof SAXException) {
+ saxException = (SAXException)cause;
+ } else {
+ saxException = new SAXException(ex);
+ }
+ throw new StreamException(saxException);
+ }
+ return;
}
- break;
- case OMNode.SPACE_NODE:
- contentHandler.ignorableWhitespace(ch, 0, ch.length);
+ }
+ char[] ch = data.toString().toCharArray();
+ contentHandler.characters(ch, 0, ch.length);
+ }
+ } catch (SAXException ex) {
+ throw new StreamException(ex);
+ }
+ }
+
+ @Override
+ public void processCDATASection(String content) throws StreamException {
+ try {
+ if (lexicalHandler != null) {
+ lexicalHandler.startCDATA();
+ }
+ char[] ch = content.toCharArray();
+ contentHandler.characters(ch, 0, ch.length);
+ if (lexicalHandler != null) {
+ lexicalHandler.endCDATA();
}
} catch (SAXException ex) {
throw new StreamException(ex);
@@ -199,32 +236,6 @@ public class SAXSerializer extends Seria
throw new StreamException(ex);
}
}
-
- public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize) throws StreamException {
- Base64EncodingWriterOutputStream out = new Base64EncodingWriterOutputStream(new ContentHandlerWriter(contentHandler), 4096, true);
- try {
- dataHandler.writeTo(out);
- out.complete();
- } catch (IOException ex) {
- Throwable cause = ex.getCause();
- SAXException saxException;
- if (cause instanceof SAXException) {
- saxException = (SAXException)cause;
- } else {
- saxException = new SAXException(ex);
- }
- throw new StreamException(saxException);
- }
- }
-
- public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID,
- boolean optimize) throws StreamException {
- try {
- writeDataHandler(dataHandlerProvider.getDataHandler(), contentID, optimize);
- } catch (IOException ex) {
- throw new StreamException(ex);
- }
- }
public void endDocument() throws StreamException {
try {
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java?rev=1731293&r1=1731292&r2=1731293&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/serializer/push/stax/StAXSerializer.java Fri Feb 19 20:08:38 2016
@@ -25,14 +25,13 @@ import org.apache.axiom.core.stream.XmlH
import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMSerializable;
import org.apache.axiom.om.impl.common.serializer.push.SerializerImpl;
+import org.apache.axiom.om.impl.intf.TextContent;
import org.apache.axiom.util.stax.XMLStreamWriterUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.activation.DataHandler;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -198,13 +197,32 @@ public class StAXSerializer extends Seri
}
}
- public void writeText(int type, String data) throws StreamException {
+ public void processCharacterData(Object data, boolean ignorable) throws StreamException {
try {
- if (type == OMNode.CDATA_SECTION_NODE) {
- writer.writeCData(data);
- } else {
- writer.writeCharacters(data);
+ if (data instanceof TextContent) {
+ TextContent textContent = (TextContent)data;
+ if (textContent.isBinary()) {
+ Object dataHandlerObject = textContent.getDataHandlerObject();
+ if (dataHandlerObject instanceof DataHandlerProvider) {
+ getDataHandlerWriter().writeDataHandler((DataHandlerProvider)dataHandlerObject, textContent.getContentID(), textContent.isOptimize());
+ } else {
+ getDataHandlerWriter().writeDataHandler(textContent.getDataHandler(), textContent.getContentID(), textContent.isOptimize());
+ }
+ return;
+ }
}
+ writer.writeCharacters(data.toString());
+ } catch (XMLStreamException ex) {
+ throw new StreamException(ex);
+ } catch (IOException ex) {
+ throw new StreamException(ex);
+ }
+ }
+
+ @Override
+ public void processCDATASection(String content) throws StreamException {
+ try {
+ writer.writeCData(content);
} catch (XMLStreamException ex) {
throw new StreamException(ex);
}
@@ -242,26 +260,6 @@ public class StAXSerializer extends Seri
return dataHandlerWriter;
}
- public void writeDataHandler(DataHandler dataHandler, String contentID, boolean optimize) throws StreamException {
- try {
- getDataHandlerWriter().writeDataHandler(dataHandler, contentID, optimize);
- } catch (IOException ex) {
- throw new StreamException("Error while reading data handler", ex);
- } catch (XMLStreamException ex) {
- throw new StreamException(ex);
- }
- }
-
- public void writeDataHandler(DataHandlerProvider dataHandlerProvider, String contentID, boolean optimize) throws StreamException {
- try {
- getDataHandlerWriter().writeDataHandler(dataHandlerProvider, contentID, optimize);
- } catch (IOException ex) {
- throw new StreamException("Error while reading data handler", ex);
- } catch (XMLStreamException ex) {
- throw new StreamException(ex);
- }
- }
-
public void endDocument() throws StreamException {
// TODO: the original StAX serialization code newer called writeEndDocument; this is probably a mistake
}