Search in sources :

Example 66 with SAXSource

use of javax.xml.transform.sax.SAXSource in project jersey by jersey.

the class AbstractJaxbProviderTest method abstractJaxbProviderDoesNotReadExternalDtds.

@Test
public void abstractJaxbProviderDoesNotReadExternalDtds() throws Exception {
    SAXParserFactory spf = injectionManager.getInstance(SAXParserFactory.class);
    String url = "file:///no-such-file";
    String s = "<!DOCTYPE x SYSTEM '" + url + "'><x/>";
    SAXSource saxSource = AbstractJaxbProvider.getSAXSource(spf, new ByteArrayInputStream(s.getBytes("us-ascii")));
    TransformerFactory.newInstance().newTransformer().transform(saxSource, new StreamResult(new ByteArrayOutputStream()));
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 67 with SAXSource

use of javax.xml.transform.sax.SAXSource in project jersey by jersey.

the class SourceProviderTest method saxSourceReaderDoesNotReadExternalDtds.

@Test
public void saxSourceReaderDoesNotReadExternalDtds() throws Exception {
    SourceProvider.SaxSourceReader reader = injectionManager.getInstance(SourceProvider.SaxSourceReader.class);
    InputStream entityStream = new ByteArrayInputStream("<!DOCTYPE x SYSTEM 'file:///no-such-file'> <rootObject/>".getBytes("us-ascii"));
    SAXSource ss = reader.readFrom(null, null, null, null, null, entityStream);
    TransformerFactory.newInstance().newTransformer().transform(ss, new StreamResult(new ByteArrayOutputStream()));
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SourceProvider(org.glassfish.jersey.message.internal.SourceProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 68 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class JcloudsBlobStoreProducerTest method testBlobStorePutWithStreamAndGet.

@Test
public void testBlobStorePutWithStreamAndGet() throws InterruptedException, TransformerException {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
    Exchange exchange = new DefaultExchange(context);
    StreamCache streamCache = StreamCacheConverter.convertToStreamCache(new SAXSource(new InputSource(inputStream)), exchange);
    template.sendBody("direct:put-and-get", streamCache);
    Object result = template.requestBodyAndHeader("direct:put-and-get", null, JcloudsConstants.OPERATION, JcloudsConstants.GET, String.class);
    assertEquals(MESSAGE, result);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCache(org.apache.camel.StreamCache) Test(org.junit.Test)

Example 69 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class SchematronProcessor method validate.

/**
     * Validates the given XML for given Rules.
     *
     * @param xml
     * @return
     */
public String validate(final String xml) {
    try {
        final Source source = new SAXSource(reader, new InputSource(IOUtils.toInputStream(xml)));
        final StringWriter writer = new StringWriter();
        templates.newTransformer().transform(source, new StreamResult(writer));
        return writer.toString();
    } catch (TransformerException e) {
        logger.error(e.getMessage());
        throw new SchematronValidationException("Failed to apply Schematron validation transform", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SchematronValidationException(org.apache.camel.component.schematron.exception.SchematronValidationException) SAXSource(javax.xml.transform.sax.SAXSource) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException)

Example 70 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class XmlConverterTest method testToSaxSourceByCustomSource.

public void testToSaxSourceByCustomSource() throws Exception {
    XmlConverter conv = new XmlConverter();
    Source dummy = new Source() {

        public String getSystemId() {
            return null;
        }

        public void setSystemId(String s) {
        }
    };
    SAXSource out = conv.toSAXSource(dummy, null);
    assertNull(out);
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) StAXSource(javax.xml.transform.stax.StAXSource) BytesSource(org.apache.camel.BytesSource)

Aggregations

SAXSource (javax.xml.transform.sax.SAXSource)111 InputSource (org.xml.sax.InputSource)81 XMLReader (org.xml.sax.XMLReader)38 Source (javax.xml.transform.Source)28 StreamSource (javax.xml.transform.stream.StreamSource)28 DOMSource (javax.xml.transform.dom.DOMSource)27 SAXException (org.xml.sax.SAXException)26 TransformerException (javax.xml.transform.TransformerException)24 SAXParserFactory (javax.xml.parsers.SAXParserFactory)20 Unmarshaller (javax.xml.bind.Unmarshaller)17 SAXParser (javax.xml.parsers.SAXParser)17 Transformer (javax.xml.transform.Transformer)17 StreamResult (javax.xml.transform.stream.StreamResult)16 Test (org.junit.Test)16 StringReader (java.io.StringReader)15 IOException (java.io.IOException)14 JAXBContext (javax.xml.bind.JAXBContext)14 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)11 ValidationEvent (javax.xml.bind.ValidationEvent)10