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/05/24 07:29:27 UTC
svn commit: r1745310 - in
/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax:
MTOMXMLStreamWriterImpl.java XmlHandlerStreamWriter.java
Author: veithen
Date: Tue May 24 07:29:27 2016
New Revision: 1745310
URL: http://svn.apache.org/viewvc?rev=1745310&view=rev
Log:
Get the XmlHandler by unwrapping the XMLStreamWriter.
Modified:
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/MTOMXMLStreamWriterImpl.java
webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/XmlHandlerStreamWriter.java
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/MTOMXMLStreamWriterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/MTOMXMLStreamWriterImpl.java?rev=1745310&r1=1745309&r2=1745310&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/MTOMXMLStreamWriterImpl.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/MTOMXMLStreamWriterImpl.java Tue May 24 07:29:27 2016
@@ -34,7 +34,6 @@ import org.apache.axiom.attachments.life
import org.apache.axiom.core.stream.StreamException;
import org.apache.axiom.core.stream.XmlHandler;
import org.apache.axiom.core.stream.serializer.Serializer;
-import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.OMText;
@@ -45,7 +44,6 @@ import org.apache.axiom.om.impl.stream.x
import org.apache.axiom.om.util.CommonUtils;
import org.apache.axiom.om.util.XMLStreamWriterFilter;
import org.apache.axiom.util.io.IOUtils;
-import org.apache.axiom.util.stax.XMLStreamWriterUtils;
import org.apache.axiom.util.stax.xop.ContentIDGenerator;
import org.apache.axiom.util.stax.xop.OptimizationPolicy;
import org.apache.commons.logging.Log;
@@ -78,7 +76,6 @@ public class MTOMXMLStreamWriterImpl ext
private List<Part> otherParts = new LinkedList<Part>();
private OMOutputFormat format;
private final OptimizationPolicy optimizationPolicy;
- private final XmlHandler handler;
// State variables
private boolean isEndDocument = false; // has endElement been called
@@ -95,7 +92,6 @@ public class MTOMXMLStreamWriterImpl ext
}
this.format = format;
optimizationPolicy = new OptimizationPolicyImpl(format);
- handler = null;
}
public MTOMXMLStreamWriterImpl(XMLStreamWriter xmlWriter) {
@@ -157,6 +153,7 @@ public class MTOMXMLStreamWriterImpl ext
Serializer serializer = new Serializer(rootPartOutputStream, encoding);
+ XmlHandler handler;
if (format.isOptimized()) {
ContentIDGenerator contentIDGenerator = new ContentIDGenerator() {
public String generateContentID(String existingContentID) {
@@ -205,6 +202,25 @@ public class MTOMXMLStreamWriterImpl ext
}
}
+ /**
+ * Get the {@link XmlHandler} events are serialized to.
+ *
+ * @return the {@link XmlHandler} or {@code null} if the {@link XMLStreamWriter} is not
+ * connected to a {@link XmlHandler} (e.g. because the {@link XMLStreamWriter} is user
+ * supplied)
+ */
+ private XmlHandler getHandler() {
+ XMLStreamWriter writer = xmlWriter;
+ while (writer instanceof XMLStreamWriterFilter) {
+ writer = ((XMLStreamWriterFilter)writer).getDelegate();
+ }
+ if (writer instanceof XmlHandlerStreamWriter) {
+ return ((XmlHandlerStreamWriter)writer).getHandler();
+ } else {
+ return null;
+ }
+ }
+
public void writeStartElement(String string) throws XMLStreamException {
xmlWriter.writeStartElement(string);
depth++;
@@ -265,10 +281,13 @@ public class MTOMXMLStreamWriterImpl ext
if (format.isOptimized() && !isComplete & (isEndDocument || depth == 0)) {
log.debug("The XML writing is completed. Now the attachments are written");
isComplete = true;
- try {
- handler.completed();
- } catch (StreamException ex) {
- throw new XMLStreamException(ex);
+ XmlHandler handler = getHandler();
+ if (handler != null) {
+ try {
+ handler.completed();
+ } catch (StreamException ex) {
+ throw new XMLStreamException(ex);
+ }
}
}
}
@@ -476,7 +495,7 @@ public class MTOMXMLStreamWriterImpl ext
}
OutputStream outputStream;
- XmlHandler handler = this.handler;
+ XmlHandler handler = getHandler();
// Remove the XOPEncodingFilterHandler wrapper if necessary
if (handler instanceof XOPEncodingFilterHandler) {
handler = ((XOPEncodingFilterHandler)handler).getParent();
Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/XmlHandlerStreamWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/XmlHandlerStreamWriter.java?rev=1745310&r1=1745309&r2=1745310&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/XmlHandlerStreamWriter.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/stax/XmlHandlerStreamWriter.java Tue May 24 07:29:27 2016
@@ -43,6 +43,10 @@ public class XmlHandlerStreamWriter exte
this.serializer = serializer;
}
+ public XmlHandler getHandler() {
+ return handler;
+ }
+
private static String normalize(String s) {
return s == null ? "" : s;
}