use of javax.xml.transform.sax.SAXResult in project webservices-axiom by apache.
the class TestGetSAXResult method runTest.
@Override
protected void runTest() throws Throwable {
TransformerFactory transformerFactory = xsltImplementation.newTransformerFactory();
StreamSource source = new StreamSource(file.getUrl().toString());
OMDocument document = metaFactory.getOMFactory().createOMDocument();
SAXResult result = document.getSAXResult();
transformerFactory.newTransformer().transform(source, result);
assertAbout(xml()).that(xml(OMDocument.class, document)).ignoringWhitespaceInPrologAndEpilog().ignoringRedundantNamespaceDeclarations().expandingEntityReferences().hasSameContentAs(file.getUrl());
}
use of javax.xml.transform.sax.SAXResult in project webservices-axiom by apache.
the class XSLTImplementation method supportsLexicalHandlerWithStreamSource.
/**
* Determine if an identity transformation from a {@link StreamSource} to a {@link SAXResult}
* will generate events defined by {@link LexicalHandler}.
*
* @return <code>true</code> if the XSLT implementation will invoke the methods on the
* {@link LexicalHandler} set on the {@link SAXResult}, <code>false</code> otherwise
*/
public final synchronized boolean supportsLexicalHandlerWithStreamSource() {
if (supportsLexicalHandlerWithStreamSource == null) {
StreamSource source = new StreamSource(new StringReader("<!DOCTYPE root><root><![CDATA[test]]></root>"));
TestContentHandler handler = new TestContentHandler();
SAXResult result = new SAXResult(handler);
result.setLexicalHandler(handler);
try {
newTransformerFactory().newTransformer().transform(source, result);
} catch (TransformerException ex) {
throw new RuntimeException(ex);
}
supportsLexicalHandlerWithStreamSource = handler.getLexicalEventsReceived() == 4;
}
return supportsLexicalHandlerWithStreamSource;
}
use of javax.xml.transform.sax.SAXResult 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();
}
}
Aggregations