use of javax.xml.transform.Result in project bnd by bndtools.
the class Transform method transform.
public static void transform(TransformerFactory transformerFactory, URL xslt, InputStream in, OutputStream out) throws Exception {
if (xslt == null)
throw new IllegalArgumentException("No source template specified");
Templates templates = cache.get(xslt.toURI());
if (templates == null) {
try (InputStream xsltIn = xslt.openStream()) {
templates = transformerFactory.newTemplates(new StreamSource(xsltIn));
cache.put(xslt.toURI(), templates);
}
}
Result xmlResult = new StreamResult(out);
Source xmlSource = new StreamSource(in);
Transformer t = templates.newTransformer();
t.transform(xmlSource, xmlResult);
out.flush();
}
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);
}
}
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);
}
}
use of javax.xml.transform.Result in project opentheso by miledrousset.
the class ApacheFOP method test_basic.
public void test_basic() throws SAXException, IOException, TransformerConfigurationException, TransformerException, ConfigurationException, URISyntaxException {
// Step 1: Construct a FopFactory by specifying a reference to the configuration file
// (reuse if you plan to render multiple documents!)
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.buildFromFile(new File("fop-config.xml"));
URI baseURI = new URI("https://www.testUri.com");
FopFactoryBuilder builder;
builder = new FopFactoryBuilder(baseURI).setConfiguration(cfg);
FopFactory fopFactory = builder.build();
// Step 2: Set up output stream.
// Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("test-fop.pdf")));
try {
// Step 3: Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
// Step 4: Setup JAXP using identity transformer
Source xslt = new StreamSource(new File("skos-alpha.xsl"));
TransformerFactory factory = TransformerFactory.newInstance();
// identity transformer
Transformer transformer = factory.newTransformer(xslt);
// Step 5: Setup input and output for XSLT transformation
// Setup input stream
Source src = new StreamSource(new File("test_unesco.rdf"));
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Step 6: Start XSLT transformation and FOP processing
transformer.transform(src, res);
} finally {
// Clean-up
out.close();
}
}
use of javax.xml.transform.Result in project winery by eclipse.
the class Util method getXMLAsString.
public static String getXMLAsString(Element el) {
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t;
try {
t = tf.newTransformer();
} catch (TransformerConfigurationException e) {
throw new IllegalStateException("Could not instantiate Transformer", e);
}
t.setOutputProperty(OutputKeys.INDENT, "yes");
Source source = new DOMSource(el);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Result target = new StreamResult(os);
try {
t.transform(source, target);
} catch (TransformerException e) {
Util.LOGGER.debug(e.getMessage(), e);
throw new IllegalStateException("Could not transform dom node to string", e);
}
return os.toString();
}
Aggregations