Search in sources :

Example 1 with StAXPullInput

use of org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput 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 StAXPullInput

use of org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput in project webservices-axiom by apache.

the class BuilderSpec method from.

static BuilderSpec from(StAXParserConfiguration configuration, Source source) {
    if (source instanceof SAXSource) {
        return from((SAXSource) source, true);
    } else if (source instanceof DOMSource) {
        return from(((DOMSource) source).getNode(), true);
    } else if (source instanceof StreamSource) {
        StreamSource streamSource = (StreamSource) source;
        InputSource is = new InputSource();
        is.setByteStream(streamSource.getInputStream());
        is.setCharacterStream(streamSource.getReader());
        is.setPublicId(streamSource.getPublicId());
        is.setSystemId(streamSource.getSystemId());
        return from(configuration, is);
    } else if (source instanceof StAXSource) {
        return from(((StAXSource) source).getXMLStreamReader());
    } else {
        try {
            return new BuilderSpec(new FilteredXmlInput(new StAXPullInput(StAXUtils.getXMLInputFactory().createXMLStreamReader(source), true, null), NamespaceRepairingFilter.DEFAULT), null);
        } catch (XMLStreamException ex) {
            throw new OMException(ex);
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) XMLStreamException(javax.xml.stream.XMLStreamException) StAXPullInput(org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput) StreamSource(javax.xml.transform.stream.StreamSource) StAXSource(javax.xml.transform.stax.StAXSource) FilteredXmlInput(org.apache.axiom.core.stream.FilteredXmlInput) OMException(org.apache.axiom.om.OMException)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)2 OMException (org.apache.axiom.om.OMException)2 StAXPullInput (org.apache.axiom.om.impl.stream.stax.pull.StAXPullInput)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 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 DOMSource (javax.xml.transform.dom.DOMSource)1 SAXSource (javax.xml.transform.sax.SAXSource)1 StAXSource (javax.xml.transform.stax.StAXSource)1 StreamSource (javax.xml.transform.stream.StreamSource)1 FilteredXmlInput (org.apache.axiom.core.stream.FilteredXmlInput)1 Detachable (org.apache.axiom.om.impl.common.builder.Detachable)1 XMLFragmentStreamReader (org.apache.axiom.util.stax.XMLFragmentStreamReader)1 InputSource (org.xml.sax.InputSource)1