use of org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler in project webservices-axiom by apache.
the class MTOMXMLStreamWriterImpl method getOutputStream.
@Override
public OutputStream getOutputStream() throws XMLStreamException {
OutputStream outputStream;
XmlHandler handler = getHandler();
// Remove wrappers that can be safely removed
while (handler instanceof DocumentElementExtractingFilterHandler || handler instanceof NamespaceRepairingFilterHandler || handler instanceof XsiTypeFilterHandler || handler instanceof XmlDeclarationRewriterHandler || handler instanceof XOPEncodingFilterHandler) {
handler = ((XmlHandlerWrapper) handler).getParent();
}
if (handler instanceof Serializer) {
try {
outputStream = ((Serializer) handler).getOutputStream();
} catch (StreamException ex) {
throw new XMLStreamException(ex);
}
} else {
outputStream = null;
}
if (log.isDebugEnabled()) {
if (outputStream == null) {
log.debug("Direct access to the output stream is not available.");
} else {
log.debug("Returning access to the output stream: " + outputStream);
}
}
return outputStream;
}
use of org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler in project webservices-axiom by apache.
the class PushOMDataSourceReader method proceed.
@Override
public boolean proceed() throws StreamException {
// TODO: we might want to unwrap the NamespaceRepairingFilter (and some other filters) here
XmlHandler handler = this.handler;
OMOutputFormat format = null;
XmlHandler current = handler;
while (current instanceof XmlHandlerWrapper) {
if (current instanceof XmlDeclarationRewriterHandler) {
format = ((XmlDeclarationRewriterHandler) current).getFormat();
break;
}
current = ((XmlHandlerWrapper) current).getParent();
}
if (format == null) {
// This is for the OMSourcedElement expansion case
format = new OMOutputFormat();
format.setDoOptimize(true);
handler = new PushOMDataSourceXOPHandler(handler);
}
try {
XMLStreamWriter writer = new XmlHandlerStreamWriter(handler, null, AxiomXMLStreamWriterExtensionFactory.INSTANCE);
// Seed the namespace context with the namespace context from the parent
OMContainer parent = root.getParent();
if (parent instanceof OMElement) {
for (Iterator<OMNamespace> it = ((OMElement) parent).getNamespacesInScope(); it.hasNext(); ) {
OMNamespace ns = it.next();
writer.setPrefix(ns.getPrefix(), ns.getNamespaceURI());
}
}
handler.startFragment();
dataSource.serialize(new MTOMXMLStreamWriterImpl(new PushOMDataSourceStreamWriter(writer), format));
handler.completed();
} catch (XMLStreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof StreamException) {
throw (StreamException) cause;
} else {
throw new StreamException(ex);
}
}
return true;
}
Aggregations