diff options
author | Glen Mazza <gmazza@apache.org> | 2004-07-19 05:33:35 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-07-19 05:33:35 +0000 |
commit | af81f828c5b7a480bf9d0674bbfefb9a60524ac5 (patch) | |
tree | fe5043083a7ab19c6c5285c351ebd49b23d9a045 | |
parent | 74955dc126dccccf831748573270d111e5ca5923 (diff) | |
download | xmlgraphics-fop-af81f828c5b7a480bf9d0674bbfefb9a60524ac5.tar.gz xmlgraphics-fop-af81f828c5b7a480bf9d0674bbfefb9a60524ac5.zip |
1.) Driver constructor modified to require RenderType, and setter functions
for RenderType and FOUserAgent removed, to allow for better checking of
a valid Driver object at time of construction. (Also, will reduce need to
validate Driver object should it be a parameter to a method.)
2.) Added validity checking of renderType to FOTreeBuilder as well, in
effect decoupling Driver from FOTreeBuilder (the latter can work on its own
now.)
3.) Updated the various examples and the documentation to indicate the
new API.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197801 13f79535-47bb-0310-9956-ffa450edef68
17 files changed, 123 insertions, 153 deletions
diff --git a/examples/embedding/build.xml b/examples/embedding/build.xml index b5c90ae1f..ec382aceb 100644 --- a/examples/embedding/build.xml +++ b/examples/embedding/build.xml @@ -84,7 +84,16 @@ </classpath> </java> </target> - <target name="example2" depends="compile" description="Runs the XML to FO example"> + <target name="example2" depends="compile" description="Runs the FO to PDF example using a SAXParser"> + <echo message="Running the FO to PDF example using a SAXParser"/> + <java classname="${name}.ExampleFO2PDFUsingSAX" fork="yes"> + <classpath> + <path refid="project.class.path"/> + <pathelement location="${build.dest}"/> + </classpath> + </java> + </target> + <target name="example3" depends="compile" description="Runs the XML to FO example"> <echo message="Running the XML to FO example"/> <java classname="${name}.ExampleXML2FO" fork="yes"> <classpath> @@ -93,7 +102,7 @@ </classpath> </java> </target> - <target name="example3" depends="compile" description="Runs the XML to PDF example"> + <target name="example4" depends="compile" description="Runs the XML to PDF example"> <echo message="Running the XML to PDF example"/> <java classname="${name}.ExampleXML2PDF" fork="yes"> <classpath> @@ -102,7 +111,7 @@ </classpath> </java> </target> - <target name="example4" depends="compile" description="Runs the Object to XML example"> + <target name="example5" depends="compile" description="Runs the Object to XML example"> <echo message="Running the Object to XML example"/> <java classname="${name}.ExampleObj2XML" fork="yes"> <classpath> @@ -111,7 +120,7 @@ </classpath> </java> </target> - <target name="example5" depends="compile" description="Runs the Object to PDF example"> + <target name="example6" depends="compile" description="Runs the Object to PDF example"> <echo message="Running the Object to PDF example"/> <java classname="${name}.ExampleObj2PDF" fork="yes"> <classpath> @@ -120,7 +129,7 @@ </classpath> </java> </target> - <target name="example6" depends="compile" description="Runs the DOM to PDF example"> + <target name="example7" depends="compile" description="Runs the DOM to PDF example"> <echo message="Running the DOM to PDF example"/> <java classname="${name}.ExampleDOM2PDF" fork="yes"> <classpath> @@ -129,7 +138,7 @@ </classpath> </java> </target> - <target name="example7" depends="compile" description="Runs the SVG to PDF example"> + <target name="example8" depends="compile" description="Runs the SVG to PDF example"> <echo message="Running the SVG to PDF example"/> <java classname="${name}.ExampleSVG2PDF" fork="yes"> <classpath> @@ -138,15 +147,6 @@ </classpath> </java> </target> - <target name="example8" depends="compile" description="Runs the FO to PDF example using a SAXParser"> - <echo message="Running the FO to PDF example using a SAXParser"/> - <java classname="${name}.ExampleFO2PDFUsingSAX" fork="yes"> - <classpath> - <path refid="project.class.path"/> - <pathelement location="${build.dest}"/> - </classpath> - </java> - </target> <!-- =================================================================== --> <!-- Clean targets --> <!-- =================================================================== --> diff --git a/examples/embedding/java/embedding/ExampleDOM2PDF.java b/examples/embedding/java/embedding/ExampleDOM2PDF.java index 17f2dfa37..0612178e9 100644 --- a/examples/embedding/java/embedding/ExampleDOM2PDF.java +++ b/examples/embedding/java/embedding/ExampleDOM2PDF.java @@ -61,11 +61,8 @@ public class ExampleDOM2PDF { */ public void convertDOM2PDF(Document xslfoDoc, File pdf) { try { - // Construct driver - Driver driver = new Driver(); - - // Setup Renderer (output format) - driver.setRenderer(Driver.RENDER_PDF); + // Construct driver with desired output format + Driver driver = new Driver(Driver.RENDER_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdf); @@ -90,7 +87,6 @@ public class ExampleDOM2PDF { out.close(); } - System.out.println("Success!"); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); diff --git a/examples/embedding/java/embedding/ExampleFO2PDF.java b/examples/embedding/java/embedding/ExampleFO2PDF.java index bf44f07e1..281bbf02d 100644 --- a/examples/embedding/java/embedding/ExampleFO2PDF.java +++ b/examples/embedding/java/embedding/ExampleFO2PDF.java @@ -55,9 +55,8 @@ public class ExampleFO2PDF { OutputStream out = null; try { - // Construct driver and setup output format - Driver driver = new Driver(); - driver.setRenderer(Driver.RENDER_PDF); + // Construct driver with desired output format + Driver driver = new Driver(Driver.RENDER_PDF); // Setup output stream. Note: Using BufferedOutputStream // for performance reasons (helpful with FileOutputStreams). diff --git a/examples/embedding/java/embedding/ExampleFO2PDFUsingSAX.java b/examples/embedding/java/embedding/ExampleFO2PDFUsingSAX.java index ca949f365..74645c3a4 100644 --- a/examples/embedding/java/embedding/ExampleFO2PDFUsingSAX.java +++ b/examples/embedding/java/embedding/ExampleFO2PDFUsingSAX.java @@ -64,8 +64,7 @@ public class ExampleFO2PDFUsingSAX { try { // Construct driver and setup output format - Driver driver = new Driver(); - driver.setRenderer(Driver.RENDER_PDF); + Driver driver = new Driver(Driver.RENDER_PDF); // Setup output stream. Note: Using BufferedOutputStream // for performance reasons (helpful with FileOutputStreams). @@ -110,7 +109,7 @@ public class ExampleFO2PDFUsingSAX { //Setup input and output files File fofile = new File(baseDir, "xml/fo/helloworld.fo"); - File pdffile = new File(outDir, "ResultFO2PDF.pdf"); + File pdffile = new File(outDir, "ResultFO2PDFUsingSAX.pdf"); System.out.println("Input: XSL-FO (" + fofile + ")"); System.out.println("Output: PDF (" + pdffile + ")"); diff --git a/examples/embedding/java/embedding/ExampleObj2PDF.java b/examples/embedding/java/embedding/ExampleObj2PDF.java index b59a1a9f5..d41c51d9e 100644 --- a/examples/embedding/java/embedding/ExampleObj2PDF.java +++ b/examples/embedding/java/embedding/ExampleObj2PDF.java @@ -55,11 +55,8 @@ public class ExampleObj2PDF { public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf) throws IOException, FOPException, TransformerException { - // Construct driver - Driver driver = new Driver(); - - // Setup Renderer (output format) - driver.setRenderer(Driver.RENDER_PDF); + // Construct driver with desired output format + Driver driver = new Driver(Driver.RENDER_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdf); diff --git a/examples/embedding/java/embedding/ExampleXML2PDF.java b/examples/embedding/java/embedding/ExampleXML2PDF.java index 18747e3e4..a1dea46fe 100644 --- a/examples/embedding/java/embedding/ExampleXML2PDF.java +++ b/examples/embedding/java/embedding/ExampleXML2PDF.java @@ -66,11 +66,8 @@ public class ExampleXML2PDF { System.out.println(); System.out.println("Transforming..."); - // Construct driver - Driver driver = new Driver(); - - // Setup Renderer (output format) - driver.setRenderer(Driver.RENDER_PDF); + // Construct driver with desired output format + Driver driver = new Driver(Driver.RENDER_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdffile); diff --git a/src/documentation/content/xdocs/embedding.xml b/src/documentation/content/xdocs/embedding.xml index 3c729558a..2f6994f45 100644 --- a/src/documentation/content/xdocs/embedding.xml +++ b/src/documentation/content/xdocs/embedding.xml @@ -388,9 +388,11 @@ XML access. This may be easier to understand for people familiar with JAXP. </p> <section id="ExampleFO2PDF"> <title>ExampleFO2PDF.java</title> - <p> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleFO2PDF.java?rev=1.12"> + (current 0.20.5)</fork> <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleFO2PDF.java?rev=HEAD"> - This example</fork> + (future 1.0dev)</fork> demonstrates the basic usage pattern to transform an XSL-FO file to PDF using FOP. </p> @@ -398,9 +400,11 @@ file to PDF using FOP. </section> <section id="ExampleXML2FO"> <title>ExampleXML2FO.java</title> - <p> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleXML2FO.java?rev=1.4"> + (current 0.20.5)</fork> <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleXML2FO.java?rev=HEAD"> - This example</fork> + (future 1.0dev)</fork> has nothing to do with FOP. It is there to show you how an XML file can be converted to XSL-FO using XSLT. The JAXP API is used to do the transformation. Make sure you've got a JAXP-compliant XSLT processor in your @@ -410,9 +414,11 @@ classpath (ex. <fork href="http://xml.apache.org/xalan-j">Xalan</fork>). </section> <section id="ExampleXML2PDF"> <title>ExampleXML2PDF.java</title> - <p> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleXML2PDF.java?rev=1.10"> + (current 0.20.5)</fork> <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleXML2PDF.java?rev=HEAD"> - This example</fork> + (future 1.0dev)</fork> demonstrates how you can convert an arbitrary XML file to PDF using XSLT and XSL-FO/FOP. It is a combination of the first two examples above. The example uses JAXP to transform the XML file to XSL-FO and FOP to @@ -430,9 +436,11 @@ performance is significantly higher with SAX. </section> <section id="ExampleObj2XML"> <title>ExampleObj2XML.java</title> - <p> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleObj2XML.java?rev=1.4"> + (current 0.20.5)</fork> <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleObj2XML.java?rev=HEAD"> - This example</fork> + (future 1.0dev)</fork> is a preparatory example for the next one. It's an example that shows how an arbitrary Java object can be converted to XML. It's an often needed task to do this. Often people create a DOM tree from a Java object and @@ -463,9 +471,11 @@ used. For more detailed information see other resources on JAXP (ex. </section> <section id="ExampleObj2PDF"> <title>ExampleObj2PDF.java</title> - <p> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleObj2PDF.java?rev=1.8"> + (current 0.20.5)</fork> <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleObj2PDF.java?rev=HEAD"> - This example</fork> + (future 1.0dev)</fork> combines the previous and the third to demonstrate how you can transform a Java object to a PDF directly in one smooth run by generating SAX events from the Java object that get fed to an XSL @@ -476,18 +486,21 @@ using FOP as before. </section> <section id="ExampleDOM2PDF"> <title>ExampleDOM2PDF.java</title> - <p> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleDOM2PDF.java?rev=1.9"> + (current 0.20.5)</fork> <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleDOM2PDF.java?rev=HEAD"> - This example</fork> + (future 1.0dev)</fork> has FOP use a DOMSource instead of a StreamSource in order to use a DOM tree as input for an XSL transformation. </p> </section> <section id="ExampleSVG2PDF"> <title>ExampleSVG2PDF.java (PDF Transcoder example)</title> - <p> - <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleSVG2PDF.java?rev=HEAD"> - This example</fork> + <p>This example + <fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleSVG2PDF.java?rev=1.4"> + (current 0.20.5)</fork><fork href="http://cvs.apache.org/viewcvs.cgi/xml-fop/examples/embedding/java/embedding/ExampleSVG2PDF.java?rev=HEAD"> + (future 1.0dev)</fork> shows use of the PDF Transcoder, a sub-application within FOP. It is used to generate a PDF document from an SVG file. </p> diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 353eac05f..72d9185ee 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -28,7 +28,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; - + // FOP import org.apache.fop.fo.Constants; import org.apache.fop.fo.FOTreeBuilder; @@ -41,20 +41,9 @@ import org.apache.fop.fo.FOTreeBuilder; * for samples (these are also available within the distribution in * FOP_DIR\examples\embedding) * <P> - * If necessary, calling classes can call into the lower level - * methods to setup and - * render. Methods within FOUserAgent can be called to set the - * Renderer to use, the (possibly multiple) ElementMapping(s) to - * use and the OutputStream to use to output the results of the - * rendering (where applicable). - * <P> - * Here is an example use of Driver which outputs to AWT: - * - * <PRE> - * Driver driver = new Driver(); - * driver.setRenderer(RENDER_AWT); - * driver.render(parser, fileInputSource(args[0])); - * </PRE> + * Methods within FOUserAgent are available to customize portions of the + * process. Specific Renderer object can be specified, also ElementMappings + * (which determine elements in the FO that can be processed) can be added. */ public class Driver implements Constants { @@ -74,27 +63,49 @@ public class Driver implements Constants { private FOUserAgent foUserAgent = null; /** - * Main constructor for the Driver class. + * Constructor for use with already-created FOUserAgents + * @param renderType the type of renderer to use. Must be one of + * <ul> + * <li>Driver.RENDER_PDF</li> + * <li>Driver.RENDER_AWT</li> + * <li>Driver.RENDER_PRINT</li> + * <li>Driver.RENDER_MIF</li> + * <li>Driver.RENDER_XML</li> + * <li>Driver.RENDER_PCL</li> + * <li>Driver.RENDER_PS</li> + * <li>Driver.RENDER_TXT</li> + * <li>Driver.RENDER_SVG</li> + * <li>Driver.RENDER_RTF</li> + * </ul> + * @param ua FOUserAgent object + * @throws IllegalArgumentException if an unsupported renderer type was requested. */ - public Driver() { - foUserAgent = new FOUserAgent(); - } + public Driver(int renderType, FOUserAgent ua) { + if (renderType == Constants.NOT_SET) { + throw new IllegalArgumentException( + "Desired render type not set."); + } + + if (renderType < Constants.RENDER_MIN_CONST + || renderType > Constants.RENDER_MAX_CONST) { + throw new IllegalArgumentException( + "Invalid render type #" + renderType); + } + + this.renderType = renderType; - /** - * Constructor with FOUserAgent - * Used by CLI, AWTRenderer - */ - public Driver(FOUserAgent ua) { foUserAgent = ua; + if (foUserAgent == null) { + foUserAgent = new FOUserAgent(); + } } /** - * Optionally sets the FOUserAgent instance for FOP to use. The Driver - * class sets up its own FOUserAgent if none is set through this method. - * @param agent FOUserAgent to use + * Constructor that creates a default FOUserAgent + * @see org.apache.fop.apps.Driver#(int, FOUserAgent) */ - public void setUserAgent(FOUserAgent agent) throws FOPException { - foUserAgent = agent; + public Driver(int renderType) { + this(renderType, new FOUserAgent()); } /** @@ -115,33 +126,6 @@ public class Driver implements Constants { } /** - * Method to set the rendering type desired. Must be one of - * <ul> - * <li>Driver.RENDER_PDF</li> - * <li>Driver.RENDER_AWT</li> - * <li>Driver.RENDER_PRINT</li> - * <li>Driver.RENDER_MIF</li> - * <li>Driver.RENDER_XML</li> - * <li>Driver.RENDER_PCL</li> - * <li>Driver.RENDER_PS</li> - * <li>Driver.RENDER_TXT</li> - * <li>Driver.RENDER_SVG</li> - * <li>Driver.RENDER_RTF</li> - * </ul> - * @param renderType the type of renderer to use - * @throws IllegalArgumentException if an unsupported renderer type was requested. - */ - public void setRenderer(int renderType) throws IllegalArgumentException { - if (renderType < RENDER_MIN_CONST || renderType > RENDER_MAX_CONST) { - renderType = NOT_SET; - throw new IllegalArgumentException( - "Invalid render ID#" + renderType); - } - - this.renderType = renderType; - } - - /** * Determines which SAX ContentHandler is appropriate for the renderType. * Structure renderers (e.g. MIF & RTF) each have a specialized * ContentHandler that directly place data into the output stream. Layout diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index d42424fa0..c8e40d1db 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -44,8 +44,7 @@ public class Fop { options = new CommandLineOptions(args); foUserAgent = options.getFOUserAgent(); - Driver driver = new Driver(foUserAgent); - driver.setRenderer(options.getRenderer()); + Driver driver = new Driver(options.getRenderer(), foUserAgent); try { if (options.getOutputFile() != null) { diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index dcb359c24..12f5623d6 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -91,7 +91,7 @@ public class FOTreeBuilder extends DefaultHandler { /** * FOTreeBuilder constructor - * @param render type as defined in Constants class + * @param renderType output type as defined in Constants class * @param foUserAgent in effect for this process * @param stream OutputStream to direct results */ @@ -113,7 +113,13 @@ public class FOTreeBuilder extends DefaultHandler { } else { if (renderType == Constants.NOT_SET) { throw new IllegalStateException( - "Render must be set using setRender(int renderType)"); + "Desired render type not set."); + } + + if (renderType < Constants.RENDER_MIN_CONST + || renderType > Constants.RENDER_MAX_CONST) { + throw new IllegalArgumentException( + "Invalid render ID#" + renderType); } foInputHandler = new AreaTreeHandler(foUserAgent, renderType, diff --git a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java index ef565573b..40f47be64 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java @@ -385,8 +385,7 @@ public class PreviewDialog extends JFrame { private class Reloader extends Thread { public void run() { if (driver == null) { - driver = new Driver(foUserAgent); - driver.setRenderer(Constants.RENDER_AWT); + driver = new Driver(Constants.RENDER_AWT, foUserAgent); } pageLabel.setIcon(null); diff --git a/src/java/org/apache/fop/servlet/FopPrintServlet.java b/src/java/org/apache/fop/servlet/FopPrintServlet.java index e83ce85c6..451dea973 100644 --- a/src/java/org/apache/fop/servlet/FopPrintServlet.java +++ b/src/java/org/apache/fop/servlet/FopPrintServlet.java @@ -138,8 +138,7 @@ public class FopPrintServlet extends HttpServlet { public void renderFO(InputStream foFile, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(); - driver.setRenderer(Driver.RENDER_PRINT); + Driver driver = new Driver(Driver.RENDER_PRINT); // Setup JAXP TransformerFactory factory = TransformerFactory.newInstance(); @@ -170,8 +169,7 @@ public class FopPrintServlet extends HttpServlet { public void renderXML(File xmlfile, File xsltfile, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(); - driver.setRenderer(Driver.RENDER_PRINT); + Driver driver = new Driver(Driver.RENDER_PRINT); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); diff --git a/src/java/org/apache/fop/servlet/FopServlet.java b/src/java/org/apache/fop/servlet/FopServlet.java index 1d4223282..a4da5b21f 100644 --- a/src/java/org/apache/fop/servlet/FopServlet.java +++ b/src/java/org/apache/fop/servlet/FopServlet.java @@ -201,8 +201,7 @@ public class FopServlet extends HttpServlet { throws FOPException, TransformerException { //Setup FOP - Driver driver = new Driver(); - driver.setRenderer(Driver.RENDER_PDF); + Driver driver = new Driver(Driver.RENDER_PDF); //Setup output ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index 165de1cdb..67d25c4d9 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -55,7 +55,7 @@ import org.apache.commons.logging.impl.SimpleLog; public class TestConverter { private boolean failOnly = false; - private boolean outputPDF = false; + private int renderType = Driver.RENDER_XML; private File destdir; private File compare = null; private String baseDir = "./"; @@ -106,7 +106,7 @@ public class TestConverter { if (args[count].equals("-failOnly")) { tc.setFailOnly(true); } else if (args[count].equals("-pdf")) { - tc.setOutputPDF(true); + tc.setRenderType(Driver.RENDER_PDF); } else if (args[count].equals("-d")) { tc.setDebug(true); } else if (args[count].equals("-b")) { @@ -134,11 +134,11 @@ public class TestConverter { } /** - * Controls whether to generate PDF or XML. - * @param pdf If True, PDF is generated, Area Tree XML otherwise. + * Controls output type to generate + * @param renderType fo.Constants output constant (RENDER_PDF, RENDER_XML, etc.) */ - public void setOutputPDF(boolean pdf) { - outputPDF = pdf; + public void setRenderType(int renderType) { + this.renderType = renderType; } /** @@ -305,15 +305,9 @@ public class TestConverter { + xsl)); } - Driver driver = new Driver(); FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(baseURL); - driver.setUserAgent(userAgent); - if (outputPDF) { - driver.setRenderer(Driver.RENDER_PDF); - } else { - driver.setRenderer(Driver.RENDER_XML); - } + Driver driver = new Driver(renderType, userAgent); userAgent.getRendererOptions().put("fineDetail", new Boolean(false)); userAgent.getRendererOptions().put("consistentOutput", new Boolean(true)); @@ -323,8 +317,8 @@ public class TestConverter { if (outname.endsWith(".xml") || outname.endsWith(".pdf")) { outname = outname.substring(0, outname.length() - 4); } - File outputFile = new File(destdir, - outname + (outputPDF ? ".pdf" : ".at.xml")); + File outputFile = new File(destdir, // assuming only RENDER_PDF or RENDER_XML here + outname + ((renderType==Driver.RENDER_PDF) ? ".pdf" : ".at.xml")); outputFile.getParentFile().mkdirs(); OutputStream outStream = new java.io.BufferedOutputStream( diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index 6093c9fd1..255bbb0b9 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -531,11 +531,9 @@ class FOPTaskStarter { } try { - Driver driver = new Driver(); FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(this.baseURL); - driver.setUserAgent(userAgent); - driver.setRenderer(renderer); + Driver driver = new Driver(renderer, userAgent); driver.setOutputStream(out); driver.render(inputHandler); } catch (Exception ex) { diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index 5f722fbc1..fa004e487 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -71,9 +71,8 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { public void testFO2PDFWithDOM() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); + Driver driver = new Driver(Driver.RENDER_PDF); driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_PDF); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -91,10 +90,9 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { public void testFO2PDFWithXMLReader() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); + Driver driver = new Driver(Driver.RENDER_PDF); driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_PDF); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); @@ -111,9 +109,8 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { public void testFO2PDFWithJAXP() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); + Driver driver = new Driver(Driver.RENDER_PDF); driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_PDF); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -131,9 +128,8 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { public void testFO2PSWithJAXP() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); + Driver driver = new Driver(Driver.RENDER_PS); driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_PS); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -151,9 +147,8 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { public void testFO2RTFWithJAXP() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); + Driver driver = new Driver(Driver.RENDER_RTF); driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_RTF); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. @@ -172,9 +167,8 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { File xmlFile = new File(getBaseDir(), "test/xml/1.xml"); File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); + Driver driver = new Driver(Driver.RENDER_PDF); driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_PDF); InputHandler handler = new XSLTInputHandler(xmlFile, xsltFile); driver.render(handler); diff --git a/test/java/org/apache/fop/GenericFOPTestCase.java b/test/java/org/apache/fop/GenericFOPTestCase.java index dc78a3173..85a5a4d44 100644 --- a/test/java/org/apache/fop/GenericFOPTestCase.java +++ b/test/java/org/apache/fop/GenericFOPTestCase.java @@ -118,9 +118,7 @@ public final class GenericFOPTestCase extends TestCase { ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); DigestOutputStream out = new DigestOutputStream(new ByteArrayOutputStream(), outDigest); - Driver driver = new Driver(); - driver.setUserAgent(foUserAgent); - driver.setRenderer(Driver.RENDER_PDF); + Driver driver = new Driver(Driver.RENDER_PDF, foUserAgent); driver.setOutputStream(out); InputSource source = new InputSource(new StringReader(fo)); DigestFilter filter = new DigestFilter("MD5"); |