Search in sources :

Example 76 with TransformerFactory

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

the class XmlUtils method transformer.

private static Transformer transformer(Source xsltSource) throws TransformerConfigurationException {
    TransformerFactory tf = TRANSFORMER_FACTORY.get();
    if (tf == null) {
        tf = TransformerFactory.newInstance();
        TRANSFORMER_FACTORY.set(tf);
    }
    return tf.newTransformer(xsltSource);
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory)

Example 77 with TransformerFactory

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

the class XmlUtils method transformer.

public static Transformer transformer() throws TransformerConfigurationException {
    TransformerFactory tf = TRANSFORMER_FACTORY.get();
    if (tf == null) {
        tf = TransformerFactory.newInstance();
        TRANSFORMER_FACTORY.set(tf);
    }
    return tf.newTransformer();
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory)

Example 78 with TransformerFactory

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

the class DOM2Model method load.

/**
     * Parse a DOM Node with the RDF/XML parser, loading the triples into the
     * associated Model. Known not to work with Java 1.4.1.
     * 
     * @param document
     */
public void load(Node document) {
    Source input = new DOMSource(document);
    // Make a SAXResult object using this handler
    SAXResult output = new SAXResult(this);
    output.setLexicalHandler(this);
    // Run transform
    TransformerFactory xformFactory = TransformerFactory.newInstance();
    try {
        Transformer idTransform = xformFactory.newTransformer();
        idTransform.transform(input, output);
    } catch (FatalParsingErrorException e) {
        // Old code ignored this,
        // given difficult bug report, don't be silent.
        logger.error("Unexpected exception in DOM2Model", e);
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception nrte) {
        throw new JenaException(nrte);
    } finally {
        close();
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) SAXResult(javax.xml.transform.sax.SAXResult) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) SAXParseException(org.xml.sax.SAXParseException) JenaException(org.apache.jena.shared.JenaException)

Example 79 with TransformerFactory

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

the class ExcelToHtmlConverter method main.

/**
     * Java main() interface to interact with {@link ExcelToHtmlConverter}
     * 
     * <p>
     * Usage: ExcelToHtmlConverter infile outfile
     * </p>
     * Where infile is an input .xls file ( Word 97-2007) which will be rendered
     * as HTML into outfile
     * @throws TransformerException 
     * @throws Exception 
     */
public static void main(String[] args) throws IOException, ParserConfigurationException, TransformerException {
    if (args.length < 2) {
        System.err.println("Usage: ExcelToHtmlConverter <inputFile.xls> <saveTo.html>");
        return;
    }
    System.out.println("Converting " + args[0]);
    System.out.println("Saving output to " + args[1]);
    Document doc = ExcelToHtmlConverter.process(new File(args[0]));
    DOMSource domSource = new DOMSource(doc);
    StreamResult streamResult = new StreamResult(new File(args[1]));
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer serializer = tf.newTransformer();
    // TODO set encoding from a command argument
    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    serializer.setOutputProperty(OutputKeys.INDENT, "no");
    serializer.setOutputProperty(OutputKeys.METHOD, "html");
    serializer.transform(domSource, streamResult);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Document(org.w3c.dom.Document) File(java.io.File)

Example 80 with TransformerFactory

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

the class ExcelToFoConverter method main.

/**
     * Java main() interface to interact with {@link ExcelToFoConverter}
     * 
     * <p>
     * Usage: ExcelToHtmlConverter infile outfile
     * </p>
     * Where infile is an input .xls file ( Word 97-2007) which will be rendered
     * as XSL FO into outfile
     */
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println("Usage: ExcelToFoConverter <inputFile.xls> <saveTo.xml>");
        return;
    }
    System.out.println("Converting " + args[0]);
    System.out.println("Saving output to " + args[1]);
    Document doc = ExcelToHtmlConverter.process(new File(args[0]));
    DOMSource domSource = new DOMSource(doc);
    StreamResult streamResult = new StreamResult(new File(args[1]));
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer serializer = tf.newTransformer();
    // TODO set encoding from a command argument
    serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    serializer.setOutputProperty(OutputKeys.INDENT, "no");
    serializer.setOutputProperty(OutputKeys.METHOD, "xml");
    serializer.transform(domSource, streamResult);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

TransformerFactory (javax.xml.transform.TransformerFactory)257 Transformer (javax.xml.transform.Transformer)221 StreamResult (javax.xml.transform.stream.StreamResult)198 DOMSource (javax.xml.transform.dom.DOMSource)157 TransformerException (javax.xml.transform.TransformerException)86 StringWriter (java.io.StringWriter)77 StreamSource (javax.xml.transform.stream.StreamSource)77 Document (org.w3c.dom.Document)67 Source (javax.xml.transform.Source)56 IOException (java.io.IOException)55 File (java.io.File)47 DocumentBuilder (javax.xml.parsers.DocumentBuilder)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)37 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 Element (org.w3c.dom.Element)36 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)35 Result (javax.xml.transform.Result)32 ByteArrayInputStream (java.io.ByteArrayInputStream)29 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)29 StringReader (java.io.StringReader)28