Search in sources :

Example 1 with XmlTransformerFactory

use of com.adaptris.util.text.xml.XmlTransformerFactory in project interlok by adaptris.

the class XmlTransformerTest method testTransform_InputStreamOutputStream.

@Test
public void testTransform_InputStreamOutputStream() throws Exception {
    XmlTransformerFactory factory = new XsltTransformerFactory();
    XmlTransformer transform = factory.configure(new XmlTransformer());
    String xsl = backslashToSlash(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL));
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    try (InputStream in = m1.getInputStream();
        OutputStream out = m1.getOutputStream()) {
        transform.transform(factory.createTransformer(xsl), in, out, xsl);
    }
}
Also used : XmlTransformer(com.adaptris.util.text.xml.XmlTransformer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) XmlTransformerFactory(com.adaptris.util.text.xml.XmlTransformerFactory) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) Test(org.junit.Test)

Example 2 with XmlTransformerFactory

use of com.adaptris.util.text.xml.XmlTransformerFactory in project interlok by adaptris.

the class XmlTransformerTest method testTransform_ReaderWriter.

@Test
public void testTransform_ReaderWriter() throws Exception {
    XmlTransformerFactory factory = new XsltTransformerFactory();
    XmlTransformer transform = new XmlTransformer();
    String xsl = backslashToSlash(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL));
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    try (Reader in = m1.getReader();
        Writer out = m1.getWriter()) {
        transform.transform(factory.createTransformer(xsl), in, out, xsl);
    }
}
Also used : XmlTransformer(com.adaptris.util.text.xml.XmlTransformer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XmlTransformerFactory(com.adaptris.util.text.xml.XmlTransformerFactory) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) Reader(java.io.Reader) Writer(java.io.Writer) Test(org.junit.Test)

Example 3 with XmlTransformerFactory

use of com.adaptris.util.text.xml.XmlTransformerFactory in project interlok by adaptris.

the class XmlTransformerTest method testTransform.

@Test
public void testTransform() throws Exception {
    XmlTransformerFactory factory = new XsltTransformerFactory();
    XmlTransformer transform = factory.configure(new XmlTransformer());
    transform.registerBuilder(DocumentBuilderFactoryBuilder.newInstance());
    String xsl = backslashToSlash(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL));
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    try (InputStream in = m1.getInputStream();
        OutputStream out = m1.getOutputStream()) {
        StreamResult output = new StreamResult(out);
        StreamSource input = new StreamSource(in);
        transform.transform(factory.createTransformer(xsl), input, output, xsl, new HashMap<>(System.getProperties()));
    }
    AdaptrisMessage m2 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    try (InputStream in = m2.getInputStream();
        OutputStream out = m2.getOutputStream()) {
        StreamResult output = new StreamResult(out);
        StreamSource input = new StreamSource(in);
        transform.transform(factory.createTransformer(xsl), input, output, xsl);
    }
}
Also used : XmlTransformer(com.adaptris.util.text.xml.XmlTransformer) StreamResult(javax.xml.transform.stream.StreamResult) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) StreamSource(javax.xml.transform.stream.StreamSource) XmlTransformerFactory(com.adaptris.util.text.xml.XmlTransformerFactory) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 XmlTransformer (com.adaptris.util.text.xml.XmlTransformer)3 XmlTransformerFactory (com.adaptris.util.text.xml.XmlTransformerFactory)3 XsltTransformerFactory (com.adaptris.util.text.xml.XsltTransformerFactory)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Reader (java.io.Reader)1 Writer (java.io.Writer)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1