Search in sources :

Example 21 with TransformerFactory

use of javax.xml.transform.TransformerFactory in project AndroidAsync by koush.

the class DocumentBody method prepare.

private void prepare() {
    if (bout != null)
        return;
    try {
        DOMSource source = new DOMSource(document);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        bout = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(bout, Charsets.UTF_8);
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
        writer.flush();
    } catch (Exception e) {
    }
}
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) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 22 with TransformerFactory

use of javax.xml.transform.TransformerFactory in project jop by jop-devel.

the class XmlBuilder method writeDom.

/**
	 * @param dom
	 * @param s
	 * @throws TransformerFactoryConfigurationError
	 * @throws XmlSerializationException
	 */
public static void writeDom(Document dom, Writer s) throws TransformerFactoryConfigurationError, XmlSerializationException {
    DOMSource domSource = new DOMSource(dom);
    StreamResult streamResult = new StreamResult(s);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer serializer;
    try {
        serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
        serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.it.uu.se/research/group/darts/uppaal/flat-1_1.dtd");
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.transform(domSource, streamResult);
    } catch (Exception e) {
        throw new XmlSerializationException("Error in domToString()", e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 23 with TransformerFactory

use of javax.xml.transform.TransformerFactory in project spring-framework by spring-projects.

the class StaxSourceTests method setUp.

@Before
public void setUp() throws Exception {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformer = transformerFactory.newTransformer();
    inputFactory = XMLInputFactory.newInstance();
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilder = documentBuilderFactory.newDocumentBuilder();
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Before(org.junit.Before)

Example 24 with TransformerFactory

use of javax.xml.transform.TransformerFactory in project camel by apache.

the class TemplatesFactoryTest method testInstantiateAnInstanceOfTemplates.

@Test
public void testInstantiateAnInstanceOfTemplates() throws Exception {
    TemplatesFactory fac = TemplatesFactory.newInstance();
    TransformerFactory factory = new TransformerFactoryImpl();
    factory.setURIResolver(new ClassPathURIResolver(Constants.SCHEMATRON_TEMPLATES_ROOT_DIR, null));
    Templates templates = fac.getTemplates(ClassLoader.getSystemResourceAsStream(rules), factory);
    Assert.assertNotNull(templates);
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) TransformerFactoryImpl(net.sf.saxon.TransformerFactoryImpl) Templates(javax.xml.transform.Templates) Test(org.junit.Test)

Example 25 with TransformerFactory

use of javax.xml.transform.TransformerFactory in project camel by apache.

the class SaxonUriResolverTest method test.

@Test
public void test() throws Exception {
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    Source xsl = fromClasspath(XSL_PATH);
    xsl.setSystemId("classpath:/" + XSL_PATH);
    Source xml = fromString(XML_DATA);
    TransformerFactory factory = new TransformerFactoryImpl();
    Transformer transformer = factory.newTransformer(xsl);
    transformer.setURIResolver(new XsltUriResolver(context(), XSL_PATH));
    transformer.transform(xml, result);
    Assert.assertEquals(XML_RESP, writer.toString());
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) TransformerFactoryImpl(net.sf.saxon.TransformerFactoryImpl) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) XsltUriResolver(org.apache.camel.builder.xml.XsltUriResolver) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

TransformerFactory (javax.xml.transform.TransformerFactory)188 Transformer (javax.xml.transform.Transformer)158 StreamResult (javax.xml.transform.stream.StreamResult)137 DOMSource (javax.xml.transform.dom.DOMSource)113 TransformerException (javax.xml.transform.TransformerException)63 StreamSource (javax.xml.transform.stream.StreamSource)60 StringWriter (java.io.StringWriter)58 Document (org.w3c.dom.Document)53 IOException (java.io.IOException)42 Source (javax.xml.transform.Source)41 DocumentBuilder (javax.xml.parsers.DocumentBuilder)37 File (java.io.File)36 Element (org.w3c.dom.Element)31 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)29 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)27 Result (javax.xml.transform.Result)24 SAXException (org.xml.sax.SAXException)24 StringReader (java.io.StringReader)23 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)23 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20