Search in sources :

Example 1 with ReportTransformerException

use of com.buschmais.jqassistant.core.report.api.ReportTransformerException in project jqa-core-framework by buschmais.

the class HtmlReportTransformer method transform.

/**
     *
     /** Transforms the source to an HTML fragment which may be embedded into
     * other documents.
     *
     * @param source
     *            The source.
     * @param target
     *            The target.
     * @param template
     *            The input stream for the template.
     * @throws ReportTransformerException
     *             If transformation fails.
     */
private void transform(Source source, Result target, InputStream template) throws ReportTransformerException {
    Source xsl = new StreamSource(template);
    TransformerFactory transformerFactory;
    Transformer transformer;
    try {
        transformerFactory = TransformerFactory.newInstance();
        transformerFactory.setURIResolver(new URIResolver() {

            @Override
            public Source resolve(String href, String base) throws TransformerException {
                return new StreamSource(HtmlReportTransformer.class.getResourceAsStream(href));
            }
        });
        transformer = transformerFactory.newTransformer(xsl);
    } catch (TransformerConfigurationException e) {
        throw new ReportTransformerException("Cannot get transformer factory.", e);
    }
    try {
        transformer.transform(source, target);
    } catch (TransformerException e) {
        throw new ReportTransformerException("Cannot transform report.", e);
    }
}
Also used : ReportTransformer(com.buschmais.jqassistant.core.report.api.ReportTransformer) ReportTransformerException(com.buschmais.jqassistant.core.report.api.ReportTransformerException) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) ReportTransformerException(com.buschmais.jqassistant.core.report.api.ReportTransformerException)

Aggregations

ReportTransformer (com.buschmais.jqassistant.core.report.api.ReportTransformer)1 ReportTransformerException (com.buschmais.jqassistant.core.report.api.ReportTransformerException)1 StreamSource (javax.xml.transform.stream.StreamSource)1