Search in sources :

Example 1 with StreamException

use of org.apache.axiom.core.stream.StreamException 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;
}
Also used : NamespaceRepairingFilterHandler(org.apache.axiom.core.stream.NamespaceRepairingFilterHandler) XMLStreamException(javax.xml.stream.XMLStreamException) XmlHandler(org.apache.axiom.core.stream.XmlHandler) DocumentElementExtractingFilterHandler(org.apache.axiom.core.stream.DocumentElementExtractingFilterHandler) XsiTypeFilterHandler(org.apache.axiom.om.impl.stream.XsiTypeFilterHandler) OutputStream(java.io.OutputStream) XmlDeclarationRewriterHandler(org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler) XOPEncodingFilterHandler(org.apache.axiom.om.impl.stream.xop.XOPEncodingFilterHandler) Serializer(org.apache.axiom.core.stream.serializer.Serializer) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 2 with StreamException

use of org.apache.axiom.core.stream.StreamException 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;
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) XmlHandlerStreamWriter(org.apache.axiom.core.stream.stax.push.XmlHandlerStreamWriter) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamException(javax.xml.stream.XMLStreamException) XmlHandlerWrapper(org.apache.axiom.core.stream.XmlHandlerWrapper) XmlHandler(org.apache.axiom.core.stream.XmlHandler) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) XmlDeclarationRewriterHandler(org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler) OMContainer(org.apache.axiom.om.OMContainer)

Example 3 with StreamException

use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.

the class StAXPullReader method processDTD.

private void processDTD() throws StreamException {
    DTDReader dtdReader;
    try {
        dtdReader = (DTDReader) parser.getProperty(DTDReader.PROPERTY);
    } catch (IllegalArgumentException ex) {
        dtdReader = null;
    }
    if (dtdReader == null) {
        throw new StreamException("Cannot process DTD events because the XMLStreamReader doesn't support the DTDReader extension");
    }
    String internalSubset = getDTDText();
    // Woodstox returns an empty string if there is no internal subset
    if (internalSubset != null && internalSubset.length() == 0) {
        internalSubset = null;
    }
    handler.processDocumentTypeDeclaration(dtdReader.getRootName(), dtdReader.getPublicId(), dtdReader.getSystemId(), internalSubset);
}
Also used : DTDReader(org.apache.axiom.ext.stax.DTDReader) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 4 with StreamException

use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.

the class XMLStreamWriterHandler method processDocumentTypeDeclaration.

@Override
public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId, String internalSubset) throws StreamException {
    StringWriter sw = new StringWriter();
    Serializer serializer = new Serializer(sw);
    serializer.startFragment();
    serializer.processDocumentTypeDeclaration(rootName, publicId, systemId, internalSubset);
    serializer.completed();
    try {
        writer.writeDTD(sw.toString());
    } catch (XMLStreamException ex) {
        throw new StreamException(ex);
    }
}
Also used : StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) Serializer(org.apache.axiom.core.stream.serializer.Serializer) StreamException(org.apache.axiom.core.stream.StreamException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 5 with StreamException

use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.

the class NamespaceContextPreservationFilterHandler method attributesCompleted.

@Override
public void attributesCompleted() throws StreamException {
    if (!done) {
        try {
            CoreElement current = contextElement;
            while (true) {
                CoreAttribute attr = current.coreGetFirstAttribute();
                while (attr != null) {
                    if (attr instanceof CoreNamespaceDeclaration) {
                        CoreNamespaceDeclaration decl = (CoreNamespaceDeclaration) attr;
                        String prefix = decl.coreGetDeclaredPrefix();
                        if (prefixesAlreadyBound.add(prefix)) {
                            super.processNamespaceDeclaration(prefix, decl.coreGetCharacterData().toString());
                        }
                    }
                    attr = attr.coreGetNextAttribute();
                }
                CoreParentNode parent = current.coreGetParent();
                if (!(parent instanceof CoreElement)) {
                    break;
                }
                current = (CoreElement) parent;
            }
            prefixesAlreadyBound = null;
            done = true;
        } catch (CoreModelException ex) {
            throw new StreamException(ex);
        }
    }
    super.attributesCompleted();
}
Also used : CoreParentNode(org.apache.axiom.core.CoreParentNode) CoreAttribute(org.apache.axiom.core.CoreAttribute) CoreElement(org.apache.axiom.core.CoreElement) CoreModelException(org.apache.axiom.core.CoreModelException) CoreNamespaceDeclaration(org.apache.axiom.core.CoreNamespaceDeclaration) StreamException(org.apache.axiom.core.stream.StreamException)

Aggregations

StreamException (org.apache.axiom.core.stream.StreamException)38 IOException (java.io.IOException)24 SAXException (org.xml.sax.SAXException)9 XMLStreamException (javax.xml.stream.XMLStreamException)6 CoreModelException (org.apache.axiom.core.CoreModelException)3 XmlHandler (org.apache.axiom.core.stream.XmlHandler)3 CoreElement (org.apache.axiom.core.CoreElement)2 Serializer (org.apache.axiom.core.stream.serializer.Serializer)2 XmlDeclarationRewriterHandler (org.apache.axiom.om.impl.stream.XmlDeclarationRewriterHandler)2 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 DataHandler (javax.activation.DataHandler)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 CoreAttribute (org.apache.axiom.core.CoreAttribute)1 CoreNamespaceDeclaration (org.apache.axiom.core.CoreNamespaceDeclaration)1 CoreParentNode (org.apache.axiom.core.CoreParentNode)1 CharacterData (org.apache.axiom.core.stream.CharacterData)1 DocumentElementExtractingFilterHandler (org.apache.axiom.core.stream.DocumentElementExtractingFilterHandler)1 NamespaceRepairingFilterHandler (org.apache.axiom.core.stream.NamespaceRepairingFilterHandler)1