Search in sources :

Example 21 with Source

use of javax.xml.transform.Source 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 22 with Source

use of javax.xml.transform.Source 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 23 with Source

use of javax.xml.transform.Source in project tomcat by apache.

the class DefaultServlet method secureXslt.

private Source secureXslt(InputStream is) {
    // Need to filter out any external entities
    Source result = null;
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(secureEntityResolver);
        Document document = builder.parse(is);
        result = new DOMSource(document);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        if (debug > 0) {
            log(e.getMessage(), e);
        }
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    return result;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXException(org.xml.sax.SAXException)

Example 24 with Source

use of javax.xml.transform.Source in project che by eclipse.

the class BuildFileGenerator method documentToString.

/** Convert document to formatted XML string. */
private String documentToString(Document doc) throws TransformerException {
    StringWriter writer = new StringWriter();
    Source source = new DOMSource(doc);
    Result result = new StreamResult(writer);
    TransformerFactory factory = TransformerFactory.newInstance();
    factory.setAttribute("indent-number", "4");
    Transformer transformer = factory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.transform(source, result);
    return writer.toString();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 25 with Source

use of javax.xml.transform.Source in project qi4j-sdk by Qi4j.

the class QuikitServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    try {
        mountPoints = new TreeMap<String, Page>();
        documentFactory = DocumentBuilderFactory.newInstance();
        documentFactory.setNamespaceAware(true);
        ClassLoader cl = getClass().getClassLoader();
        SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        Source[] schemaSources = new Source[2];
        schemaSources[0] = new StreamSource(cl.getResourceAsStream("xhtml1-strict.xsd"));
        schemaSources[1] = new StreamSource(cl.getResourceAsStream("xml.xsd"));
        Schema schema = schemaFactory.newSchema(schemaSources);
        documentFactory.setSchema(schema);
        ApplicationAssembler assembler = createApplicationAssembler(config);
        Energy4Java qi4j = new Energy4Java();
        application = qi4j.newApplication(assembler);
        application.activate();
        Module module = application.findModule("WebLayer", "PagesModule");
        finder = module;
        if (application.mode() == Application.Mode.development) {
            DataInitializer initializer = module.newTransient(DataInitializer.class);
            initializer.initialize();
        }
        Iterable<ServiceReference<Page>> iterable = finder.findServices(Page.class);
        for (ServiceReference<Page> page : iterable) {
            PageMetaInfo pageMetaInfo = page.metaInfo(PageMetaInfo.class);
            String mountPoint = pageMetaInfo.mountPoint();
            mountPoints.put(mountPoint, page.get());
        }
    } catch (Exception e) {
        throw new ServletException("Can not initialize Qi4j.", e);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ServiceReference(org.qi4j.api.service.ServiceReference) ServletException(javax.servlet.ServletException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Module(org.qi4j.api.structure.Module)

Aggregations

Source (javax.xml.transform.Source)238 StreamSource (javax.xml.transform.stream.StreamSource)161 DOMSource (javax.xml.transform.dom.DOMSource)108 Transformer (javax.xml.transform.Transformer)76 StreamResult (javax.xml.transform.stream.StreamResult)74 InputSource (org.xml.sax.InputSource)67 SAXSource (javax.xml.transform.sax.SAXSource)56 StringReader (java.io.StringReader)52 IOException (java.io.IOException)46 TransformerException (javax.xml.transform.TransformerException)45 Result (javax.xml.transform.Result)42 TransformerFactory (javax.xml.transform.TransformerFactory)41 Test (org.junit.Test)39 StringWriter (java.io.StringWriter)35 InputStream (java.io.InputStream)32 SAXException (org.xml.sax.SAXException)32 Schema (javax.xml.validation.Schema)29 Validator (javax.xml.validation.Validator)29 SchemaFactory (javax.xml.validation.SchemaFactory)28 ByteArrayInputStream (java.io.ByteArrayInputStream)26