diff options
author | Glen Mazza <gmazza@apache.org> | 2004-07-14 22:42:29 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-07-14 22:42:29 +0000 |
commit | a60f0d8086dbb4f82c4bc056b49df00ef02c6406 (patch) | |
tree | 95361d265586b019e7f106450b4242da1358f263 /examples/embedding | |
parent | 1d2d04c5f06a89fcd333543547a9d4ecc3929e35 (diff) | |
download | xmlgraphics-fop-a60f0d8086dbb4f82c4bc056b49df00ef02c6406.tar.gz xmlgraphics-fop-a60f0d8086dbb4f82c4bc056b49df00ef02c6406.zip |
Updated FO->PDF example to use JAXP.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197788 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'examples/embedding')
-rw-r--r-- | examples/embedding/java/embedding/ExampleFO2PDF.java | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/examples/embedding/java/embedding/ExampleFO2PDF.java b/examples/embedding/java/embedding/ExampleFO2PDF.java index 9238c36ae..939803e0d 100644 --- a/examples/embedding/java/embedding/ExampleFO2PDF.java +++ b/examples/embedding/java/embedding/ExampleFO2PDF.java @@ -24,8 +24,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -// SAX -import org.xml.sax.InputSource; +//JAXP +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.Source; +import javax.xml.transform.Result; +import javax.xml.transform.stream.StreamSource; +import javax.xml.transform.sax.SAXResult; // FOP import org.apache.fop.apps.Driver; @@ -45,28 +50,34 @@ public class ExampleFO2PDF { */ public void convertFO2PDF(File fo, File pdf) throws IOException, FOPException { - // Construct driver - Driver driver = new Driver(); + OutputStream out = null; - // Setup Renderer (output format) - driver.setRenderer(Driver.RENDER_PDF); - - // Setup output - OutputStream out = new java.io.FileOutputStream(pdf); - out = new java.io.BufferedOutputStream(out); try { + // Construct driver and setup output format + Driver driver = new Driver(); + driver.setRenderer(Driver.RENDER_PDF); + + // Setup output + out = new java.io.FileOutputStream(pdf); + out = new java.io.BufferedOutputStream(out); driver.setOutputStream(out); - //Setup input - InputStream in = new java.io.FileInputStream(fo); - try { - driver.setInputSource(new InputSource(in)); + // Setup JAXP using identity transformer + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); // identity transformer + + // Setup input for XSLT transformation + Source src = new StreamSource(fo); - //Process FO - driver.run(); - } finally { - in.close(); - } + // Resulting SAX events (the generated FO) must be piped through to FOP + Result res = new SAXResult(driver.getContentHandler()); + + // Start XSLT transformation and FOP processing + transformer.transform(src, res); + + } catch (Exception e) { + e.printStackTrace(System.err); + System.exit(-1); } finally { out.close(); } |