Search in sources :

Example 66 with Result

use of javax.xml.transform.Result in project ddf by codice.

the class XMLUtils method format.

/**
     * Formats XML into a String
     *
     * @param sourceXml           to transform a given Source
     * @param transformProperties settings for transformer
     * @return XML string
     */
public static String format(Source sourceXml, TransformerProperties transformProperties) {
    Writer buffer = new StringWriter();
    Result streamResult = new StreamResult(buffer);
    transformation(sourceXml, transformProperties, streamResult);
    return buffer.toString();
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) Writer(java.io.Writer) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 67 with Result

use of javax.xml.transform.Result in project dhis2-core by dhis2.

the class DefaultHelpManager method getHelpItems.

@Override
public void getHelpItems(OutputStream out, Locale locale) {
    try {
        ClassPathResource classPathResource = resolveHelpFileResource(locale);
        Source source = new StreamSource(classPathResource.getInputStream(), ENCODING_UTF8);
        Result result = new StreamResult(out);
        getTransformer("helpitems_stylesheet.xsl").transform(source, result);
    } catch (Exception ex) {
        throw new RuntimeException("Failed to get help content", ex);
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) ClassPathResource(org.springframework.core.io.ClassPathResource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 68 with Result

use of javax.xml.transform.Result in project dhis2-core by dhis2.

the class DefaultHelpManager method getHelpContent.

// -------------------------------------------------------------------------
// HelpManager implementation
// -------------------------------------------------------------------------
@Override
public void getHelpContent(OutputStream out, String id, Locale locale) {
    try {
        ClassPathResource classPathResource = resolveHelpFileResource(locale);
        Source source = new StreamSource(classPathResource.getInputStream(), ENCODING_UTF8);
        Result result = new StreamResult(out);
        Transformer transformer = getTransformer("help_stylesheet.xsl");
        transformer.setParameter("sectionId", id);
        transformer.transform(source, result);
    } catch (Exception ex) {
        throw new RuntimeException("Failed to get help content", ex);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) ClassPathResource(org.springframework.core.io.ClassPathResource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Aggregations

Result (javax.xml.transform.Result)68 StreamResult (javax.xml.transform.stream.StreamResult)60 Source (javax.xml.transform.Source)42 Transformer (javax.xml.transform.Transformer)42 DOMSource (javax.xml.transform.dom.DOMSource)33 TransformerFactory (javax.xml.transform.TransformerFactory)25 StringWriter (java.io.StringWriter)21 StreamSource (javax.xml.transform.stream.StreamSource)19 IOException (java.io.IOException)18 TransformerException (javax.xml.transform.TransformerException)17 SAXResult (javax.xml.transform.sax.SAXResult)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 File (java.io.File)11 Document (org.w3c.dom.Document)11 InputSource (org.xml.sax.InputSource)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)9 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)9 DOMResult (javax.xml.transform.dom.DOMResult)9 SAXException (org.xml.sax.SAXException)9