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