diff options
author | Glen Mazza <gmazza@apache.org> | 2004-02-09 22:04:23 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-02-09 22:04:23 +0000 |
commit | 7c87a773303c50670894145f6f32cdd2eda1c19b (patch) | |
tree | ddc3f5f9dc016bc6e4bf4a4dbc2845f99ec279c6 /examples/embedding/java | |
parent | 0bc8d5b1f7d2f3bd7fa0d482d185075c7d202a94 (diff) | |
download | xmlgraphics-fop-7c87a773303c50670894145f6f32cdd2eda1c19b.tar.gz xmlgraphics-fop-7c87a773303c50670894145f6f32cdd2eda1c19b.zip |
Modification of ExampleXML2PDF to show a Transformer.setParameter() call.
Fix to xsl stylesheet to show '1.0' instead of just '1' for the version number
(fix from Clay Leeds).
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197343 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'examples/embedding/java')
-rw-r--r-- | examples/embedding/java/embedding/ExampleXML2PDF.java | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/examples/embedding/java/embedding/ExampleXML2PDF.java b/examples/embedding/java/embedding/ExampleXML2PDF.java index 9cabadc0c..2c203fe9d 100644 --- a/examples/embedding/java/embedding/ExampleXML2PDF.java +++ b/examples/embedding/java/embedding/ExampleXML2PDF.java @@ -80,52 +80,6 @@ import org.apache.fop.apps.FOPException; public class ExampleXML2PDF { /** - * Converts an XML file to a PDF file using JAXP and FOP. - * @param xml the XML file - * @param xslt the stylesheet file - * @param pdf the target PDF file - * @throws IOException In case of an I/O problem - * @throws FOPException In case of a FOP problem - * @throws TransformerException In case of a XSL transformation problem - */ - public void convertXML2PDF(File xml, File xslt, File pdf) - throws IOException, FOPException, TransformerException { - //Construct driver - Driver driver = new Driver(); - - //Setup logger - Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); - driver.enableLogging(logger); - driver.initialize(); - - //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 { - driver.setOutputStream(out); - - //Setup XSLT - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(new StreamSource(xslt)); - - //Setup input for XSLT transformation - Source src = new StreamSource(xml); - - //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); - } finally { - out.close(); - } - } - - - /** * Main method. * @param args command-line arguments */ @@ -150,8 +104,41 @@ public class ExampleXML2PDF { System.out.println(); System.out.println("Transforming..."); - ExampleXML2PDF app = new ExampleXML2PDF(); - app.convertXML2PDF(xmlfile, xsltfile, pdffile); + //Construct driver + Driver driver = new Driver(); + + //Setup logger + Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); + driver.enableLogging(logger); + driver.initialize(); + + //Setup Renderer (output format) + driver.setRenderer(Driver.RENDER_PDF); + + //Setup output + OutputStream out = new java.io.FileOutputStream(pdffile); + out = new java.io.BufferedOutputStream(out); + try { + driver.setOutputStream(out); + + //Setup XSLT + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(new StreamSource(xsltfile)); + + // set the value of a <param> in the stylesheet + transformer.setParameter("versionParam", "2.0"); + + //Setup input for XSLT transformation + Source src = new StreamSource(xmlfile); + + //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); + } finally { + out.close(); + } System.out.println("Success!"); } catch (Exception e) { |