Search in sources :

Example 61 with StreamResult

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

the class ConsumerEndpointMappingResponseHandlingRouteTest method testAction.

@Test
public void testAction() throws Exception {
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    webServiceTemplate.sendSourceAndReceiveToResult(getDefaultRequestSource(), new ActionCallback("http://www.webserviceX.NET/GetQuote"), result);
    assertNotNull(result);
    TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) SoapActionCallback(org.springframework.ws.soap.client.core.SoapActionCallback) ActionCallback(org.springframework.ws.soap.addressing.client.ActionCallback) Test(org.junit.Test)

Example 62 with StreamResult

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

the class AbstractWSATests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    // initialize beans for catching results
    webServiceTemplate = applicationContext.getBean("webServiceTemplate", WebServiceTemplate.class);
    newReply = getMandatoryBean(OutputChannelReceiver.class, "replyReceiver");
    response = getMandatoryBean(OutputChannelReceiver.class, "responseReceiver");
    // sample data
    source = new StreamSource(new StringReader(xmlBody));
    result = new StreamResult(new StringWriter());
    // reset from previous test
    response.clear();
    newReply.clear();
    requestInputAction = null;
}
Also used : OutputChannelReceiver(org.apache.camel.component.spring.ws.utils.OutputChannelReceiver) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Before(org.junit.Before)

Example 63 with StreamResult

use of javax.xml.transform.stream.StreamResult in project liquibase by liquibase.

the class DefaultXmlWriter method write.

@Override
public void write(Document doc, OutputStream outputStream) throws IOException {
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        try {
            factory.setAttribute("indent-number", 4);
        } catch (Exception e) {
            //guess we can't set it, that's ok
            ;
        }
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.ENCODING, LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
        //need to nest outputStreamWriter to get around JDK 5 bug.  See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6296446
        OutputStreamWriter writer = new OutputStreamWriter(outputStream, LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
        transformer.transform(new DOMSource(doc), new StreamResult(writer));
        writer.flush();
        writer.close();
    } catch (TransformerException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 64 with StreamResult

use of javax.xml.transform.stream.StreamResult in project CoreNLP by stanfordnlp.

the class Ssurgeon method writeToString.

public static String writeToString(SsurgeonPattern pattern) {
    try {
        List<SsurgeonPattern> patterns = new LinkedList<>();
        patterns.add(pattern);
        Document domDoc = createPatternXMLDoc(patterns);
        if (domDoc != null) {
            Transformer tformer = TransformerFactory.newInstance().newTransformer();
            tformer.setOutputProperty(OutputKeys.INDENT, "yes");
            StringWriter sw = new StringWriter();
            tformer.transform(new DOMSource(domDoc), new StreamResult(sw));
            return sw.toString();
        } else {
            log.warning("Was not able to create XML document for pattern list.");
        }
    } catch (Exception e) {
        log.info("Error in writeToString, could not process pattern=" + pattern);
        log.info(e);
        return null;
    }
    return "";
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Document(org.w3c.dom.Document)

Example 65 with StreamResult

use of javax.xml.transform.stream.StreamResult in project bazel by bazelbuild.

the class XmlOutputFormatter method createPostFactoStreamCallback.

@Override
public OutputFormatterCallback<Target> createPostFactoStreamCallback(final OutputStream out, final QueryOptions options) {
    return new OutputFormatterCallback<Target>() {

        private Document doc;

        private Element queryElem;

        @Override
        public void start() {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                doc = factory.newDocumentBuilder().newDocument();
            } catch (ParserConfigurationException e) {
                // This shouldn't be possible: all the configuration is hard-coded.
                throw new IllegalStateException("XML output failed", e);
            }
            doc.setXmlVersion("1.1");
            queryElem = doc.createElement("query");
            queryElem.setAttribute("version", "2");
            doc.appendChild(queryElem);
        }

        @Override
        public void processOutput(Iterable<Target> partialResult) throws IOException, InterruptedException {
            for (Target target : partialResult) {
                queryElem.appendChild(createTargetElement(doc, target));
            }
        }

        @Override
        public void close(boolean failFast) throws IOException {
            if (!failFast) {
                try {
                    Transformer transformer = TransformerFactory.newInstance().newTransformer();
                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                    transformer.transform(new DOMSource(doc), new StreamResult(out));
                } catch (TransformerFactoryConfigurationError | TransformerException e) {
                    // This shouldn't be possible: all the configuration is hard-coded.
                    throw new IllegalStateException("XML output failed", e);
                }
            }
        }
    };
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) SynchronizedDelegatingOutputFormatterCallback(com.google.devtools.build.lib.query2.engine.SynchronizedDelegatingOutputFormatterCallback) ThreadSafeOutputFormatterCallback(com.google.devtools.build.lib.query2.engine.ThreadSafeOutputFormatterCallback) OutputFormatterCallback(com.google.devtools.build.lib.query2.engine.OutputFormatterCallback) Document(org.w3c.dom.Document) FakeSubincludeTarget(com.google.devtools.build.lib.query2.FakeSubincludeTarget) Target(com.google.devtools.build.lib.packages.Target) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

StreamResult (javax.xml.transform.stream.StreamResult)448 Transformer (javax.xml.transform.Transformer)267 DOMSource (javax.xml.transform.dom.DOMSource)234 StringWriter (java.io.StringWriter)206 TransformerFactory (javax.xml.transform.TransformerFactory)138 TransformerException (javax.xml.transform.TransformerException)125 Document (org.w3c.dom.Document)103 IOException (java.io.IOException)94 StreamSource (javax.xml.transform.stream.StreamSource)88 Source (javax.xml.transform.Source)74 Test (org.junit.Test)73 DocumentBuilder (javax.xml.parsers.DocumentBuilder)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)64 Element (org.w3c.dom.Element)59 File (java.io.File)58 Result (javax.xml.transform.Result)57 StringReader (java.io.StringReader)56 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)53 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)50 ByteArrayInputStream (java.io.ByteArrayInputStream)44