use of org.xml.sax.XMLFilter in project tomee by apache.
the class XSLTJaxbProvider method unmarshalFromInputStream.
@Override
protected Object unmarshalFromInputStream(Unmarshaller unmarshaller, InputStream is, Annotation[] anns, MediaType mt) throws JAXBException {
try {
Templates t = createTemplates(getInTemplates(anns, mt), inParamsMap, inProperties);
if (t == null && supportJaxbOnly) {
return super.unmarshalFromInputStream(unmarshaller, is, anns, mt);
}
if (unmarshaller.getClass().getName().contains("eclipse")) {
// eclipse MOXy doesn't work properly with the XMLFilter/Reader thing
// so we need to bounce through a DOM
Source reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
DOMResult dom = new DOMResult();
t.newTransformer().transform(reader, dom);
return unmarshaller.unmarshal(dom.getNode());
}
XMLFilter filter;
try {
filter = factory.newXMLFilter(t);
} catch (TransformerConfigurationException ex) {
TemplatesImpl ti = (TemplatesImpl) t;
filter = factory.newXMLFilter(ti.getTemplates());
trySettingProperties(filter, ti);
}
XMLReader reader = new StaxSource(StaxUtils.createXMLStreamReader(is));
filter.setParent(reader);
SAXSource source = new SAXSource();
source.setXMLReader(filter);
if (systemId != null) {
source.setSystemId(systemId);
}
return unmarshaller.unmarshal(source);
} catch (TransformerException ex) {
LOG.warning("Transformation exception : " + ex.getMessage());
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
Aggregations