Search in sources :

Example 21 with StreamSource

use of javax.xml.transform.stream.StreamSource in project camel by apache.

the class JmsXMLRouteTest method testLondonWithFileStreamAsDefault.

@Test
public void testLondonWithFileStreamAsDefault() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:london");
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("James");
    Source source = new StreamSource(new FileInputStream(TEST_LONDON));
    assertNotNull(source);
    template.sendBody("direct:default", source);
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StringSource(org.apache.camel.StringSource) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 22 with StreamSource

use of javax.xml.transform.stream.StreamSource in project camel by apache.

the class JmsXMLRouteTest method testTampaWithFileStreamAsDefault.

@Test
public void testTampaWithFileStreamAsDefault() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:tampa");
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("Hiram");
    Source source = new StreamSource(new FileInputStream(TEST_TAMPA));
    assertNotNull(source);
    template.sendBody("direct:default", source);
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StringSource(org.apache.camel.StringSource) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 23 with StreamSource

use of javax.xml.transform.stream.StreamSource in project camel by apache.

the class JmsXMLRouteTest method testTampaWithFileStreamAsObject.

@Test
public void testTampaWithFileStreamAsObject() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:tampa");
    mock.expectedMessageCount(1);
    mock.message(0).body(String.class).contains("Hiram");
    Source source = new StreamSource(new FileInputStream(TEST_TAMPA));
    assertNotNull(source);
    template.sendBody("direct:object", source);
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StringSource(org.apache.camel.StringSource) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 24 with StreamSource

use of javax.xml.transform.stream.StreamSource in project camel by apache.

the class XmlFixture method transform.

protected static Document transform(Document aDocument, String aResourcePath) throws Exception {
    TransformerFactory tf = TransformerFactory.newInstance();
    InputStream in = XmlFixture.class.getResourceAsStream(aResourcePath);
    Source src = new StreamSource(in);
    src.setSystemId(XmlFixture.class.getResource(aResourcePath).toExternalForm());
    Transformer t = tf.newTransformer(src);
    DOMResult result = new DOMResult();
    t.transform(new DOMSource(aDocument), result);
    return (Document) result.getNode();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 25 with StreamSource

use of javax.xml.transform.stream.StreamSource in project tomcat by apache.

the class DefaultServlet method findXsltSource.

/**
     * Return a Source for the xsl template (if possible).
     * @param directory The directory to search
     * @return the source for the specified directory
     * @throws IOException an IO error occurred
     */
protected Source findXsltSource(WebResource directory) throws IOException {
    if (localXsltFile != null) {
        WebResource resource = resources.getResource(directory.getWebappPath() + localXsltFile);
        if (resource.isFile()) {
            InputStream is = resource.getInputStream();
            if (is != null) {
                if (Globals.IS_SECURITY_ENABLED) {
                    return secureXslt(is);
                } else {
                    return new StreamSource(is);
                }
            }
        }
        if (debug > 10) {
            log("localXsltFile '" + localXsltFile + "' not found");
        }
    }
    if (contextXsltFile != null) {
        InputStream is = getServletContext().getResourceAsStream(contextXsltFile);
        if (is != null) {
            if (Globals.IS_SECURITY_ENABLED) {
                return secureXslt(is);
            } else {
                return new StreamSource(is);
            }
        }
        if (debug > 10)
            log("contextXsltFile '" + contextXsltFile + "' not found");
    }
    /*  Open and read in file in one fell swoop to reduce chance
         *  chance of leaving handle open.
         */
    if (globalXsltFile != null) {
        File f = validateGlobalXsltFile();
        if (f != null) {
            try (FileInputStream fis = new FileInputStream(f)) {
                byte[] b = new byte[(int) f.length()];
                /* danger! */
                fis.read(b);
                return new StreamSource(new ByteArrayInputStream(b));
            }
        }
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) WebResource(org.apache.catalina.WebResource) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

StreamSource (javax.xml.transform.stream.StreamSource)338 Source (javax.xml.transform.Source)115 StringReader (java.io.StringReader)101 StreamResult (javax.xml.transform.stream.StreamResult)85 Transformer (javax.xml.transform.Transformer)74 Test (org.junit.Test)73 InputStream (java.io.InputStream)68 TransformerFactory (javax.xml.transform.TransformerFactory)58 ByteArrayInputStream (java.io.ByteArrayInputStream)56 IOException (java.io.IOException)52 DOMSource (javax.xml.transform.dom.DOMSource)49 TransformerException (javax.xml.transform.TransformerException)48 StringWriter (java.io.StringWriter)45 SchemaFactory (javax.xml.validation.SchemaFactory)44 InputSource (org.xml.sax.InputSource)44 Schema (javax.xml.validation.Schema)43 SAXException (org.xml.sax.SAXException)42 SAXSource (javax.xml.transform.sax.SAXSource)33 Validator (javax.xml.validation.Validator)31 File (java.io.File)27