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);
}
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);
}
}
}
Aggregations