Search in sources :

Example 6 with XMLFilter

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);
    }
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) SAXSource(javax.xml.transform.sax.SAXSource) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) StaxSource(org.apache.cxf.staxutils.StaxSource) XMLFilter(org.xml.sax.XMLFilter) Templates(javax.xml.transform.Templates) StaxSource(org.apache.cxf.staxutils.StaxSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) XMLReader(org.xml.sax.XMLReader) TransformerException(javax.xml.transform.TransformerException)

Aggregations

XMLFilter (org.xml.sax.XMLFilter)6 SAXSource (javax.xml.transform.sax.SAXSource)5 StreamSource (javax.xml.transform.stream.StreamSource)3 XMLReader (org.xml.sax.XMLReader)3 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 Source (javax.xml.transform.Source)2 Templates (javax.xml.transform.Templates)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 DOMResult (javax.xml.transform.dom.DOMResult)2 StaxSource (org.apache.cxf.staxutils.StaxSource)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 IOException (java.io.IOException)1 ValidationEvent (javax.xml.bind.ValidationEvent)1 ValidationEventHandler (javax.xml.bind.ValidationEventHandler)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 Test (org.junit.Test)1