Search in sources :

Example 1 with Detachable

use of org.apache.axiom.om.impl.common.builder.Detachable in project webservices-axiom by apache.

the class BuilderSpec method create.

private static BuilderSpec create(StAXParserConfiguration configuration, InputSource is, boolean makeDetachable) {
    XMLStreamReader reader;
    Detachable detachable;
    Closeable closeable;
    try {
        if (is.getByteStream() != null) {
            String systemId = is.getSystemId();
            String encoding = is.getEncoding();
            InputStream in = is.getByteStream();
            if (makeDetachable) {
                DetachableInputStream detachableInputStream = new DetachableInputStream(in, false);
                in = detachableInputStream;
                detachable = detachableInputStream;
            } else {
                detachable = null;
            }
            if (systemId != null) {
                if (encoding == null) {
                    reader = StAXUtils.createXMLStreamReader(configuration, systemId, in);
                } else {
                    throw new UnsupportedOperationException();
                }
            } else {
                if (encoding == null) {
                    reader = StAXUtils.createXMLStreamReader(configuration, in);
                } else {
                    reader = StAXUtils.createXMLStreamReader(configuration, in, encoding);
                }
            }
            closeable = null;
        } else if (is.getCharacterStream() != null) {
            Reader in = is.getCharacterStream();
            if (makeDetachable) {
                DetachableReader detachableReader = new DetachableReader(in);
                in = detachableReader;
                detachable = detachableReader;
            } else {
                detachable = null;
            }
            reader = StAXUtils.createXMLStreamReader(configuration, in);
            closeable = null;
        } else {
            String systemId = is.getSystemId();
            InputStream in = new URL(systemId).openConnection().getInputStream();
            if (makeDetachable) {
                DetachableInputStream detachableInputStream = new DetachableInputStream(in, true);
                in = detachableInputStream;
                detachable = detachableInputStream;
            } else {
                detachable = null;
            }
            reader = StAXUtils.createXMLStreamReader(configuration, systemId, in);
            closeable = in;
        }
    } catch (XMLStreamException ex) {
        throw new OMException(ex);
    } catch (IOException ex) {
        throw new OMException(ex);
    }
    return new BuilderSpec(new StAXPullInput(reader, true, closeable), detachable);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) Closeable(java.io.Closeable) XMLStreamReader(javax.xml.stream.XMLStreamReader) Reader(java.io.Reader) XMLFragmentStreamReader(org.apache.axiom.util.stax.XMLFragmentStreamReader) IOException(java.io.IOException) URL(java.net.URL) Detachable(org.apache.axiom.om.impl.common.builder.Detachable) XMLStreamException(javax.xml.stream.XMLStreamException) StAXPullInput(org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput) OMException(org.apache.axiom.om.OMException)

Example 2 with Detachable

use of org.apache.axiom.om.impl.common.builder.Detachable in project webservices-axiom by apache.

the class BuilderSpec method from.

static BuilderSpec from(StAXParserConfiguration configuration, final MultipartBody message) {
    Part rootPart = message.getRootPart();
    InputSource is = new InputSource(rootPart.getInputStream(false));
    is.setEncoding(rootPart.getContentType().getParameter("charset"));
    BuilderSpec spec = create(configuration, is, false);
    return new BuilderSpec(new FilteredXmlInput(spec.getInput(), new XOPDecodingFilter(new OMAttachmentAccessor() {

        @Override
        public DataHandler getDataHandler(String contentID) {
            Part part = message.getPart(contentID);
            return part == null ? null : part.getDataHandler();
        }
    })), new Detachable() {

        @Override
        public void detach() {
            message.detach();
        }
    });
}
Also used : OMAttachmentAccessor(org.apache.axiom.om.OMAttachmentAccessor) Detachable(org.apache.axiom.om.impl.common.builder.Detachable) InputSource(org.xml.sax.InputSource) Part(org.apache.axiom.mime.Part) DataHandler(javax.activation.DataHandler) FilteredXmlInput(org.apache.axiom.core.stream.FilteredXmlInput) XOPDecodingFilter(org.apache.axiom.om.impl.stream.xop.XOPDecodingFilter)

Aggregations

Detachable (org.apache.axiom.om.impl.common.builder.Detachable)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 URL (java.net.URL)1 DataHandler (javax.activation.DataHandler)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 FilteredXmlInput (org.apache.axiom.core.stream.FilteredXmlInput)1 Part (org.apache.axiom.mime.Part)1 OMAttachmentAccessor (org.apache.axiom.om.OMAttachmentAccessor)1 OMException (org.apache.axiom.om.OMException)1 StAXPullInput (org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput)1 XOPDecodingFilter (org.apache.axiom.om.impl.stream.xop.XOPDecodingFilter)1 XMLFragmentStreamReader (org.apache.axiom.util.stax.XMLFragmentStreamReader)1 InputSource (org.xml.sax.InputSource)1