From 3bcfed2d9b7e68e4bfcf6738bf5c9a28063d59d5 Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sat, 24 Jul 2004 05:47:45 +0000 Subject: [PATCH] Combined the apps.Driver class into apps.Fop. (195 LOC total.) Primary benefit is to make Fop self-documenting in external code, also none of the API ideas called for retention of the Driver class (even if there were different ideas for its replacement). Let's try this for a few weeks, if it confuses people too much (or when the API starts to grow again) we can bring back Driver, possibly under a different name, apps.FopProcess, perhaps. See also: http://marc.theaimsgroup.com/?l=fop-dev&m=108947697611032&w=2 http://marc.theaimsgroup.com/?l=fop-dev&m=108966015504506&w=2 http://marc.theaimsgroup.com/?l=fop-dev&m=108942673103344&w=2 http://marc.theaimsgroup.com/?l=fop-dev&m=108958756030147&w=2 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197827 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/embedding/ExampleDOM2PDF.java | 10 +- .../java/embedding/ExampleFO2PDF.java | 10 +- .../ExampleFO2PDFUsingSAXParser.java | 10 +- .../java/embedding/ExampleObj2PDF.java | 10 +- .../java/embedding/ExampleXML2PDF.java | 10 +- .../apache/fop/apps/CommandLineOptions.java | 20 +-- src/java/org/apache/fop/apps/Driver.java | 132 ------------------ .../org/apache/fop/apps/FOFileHandler.java | 10 +- src/java/org/apache/fop/apps/Fop.java | 112 +++++++++++++-- .../org/apache/fop/apps/InputHandler.java | 6 +- .../org/apache/fop/apps/XSLTInputHandler.java | 10 +- src/java/org/apache/fop/fo/Constants.java | 2 +- .../fop/render/awt/viewer/PreviewDialog.java | 12 +- .../apache/fop/servlet/FopPrintServlet.java | 10 +- .../org/apache/fop/servlet/FopServlet.java | 8 +- .../org/apache/fop/tools/TestConverter.java | 16 +-- .../org/apache/fop/tools/anttasks/Fop.java | 37 ++--- .../org/apache/fop/BasicDriverTestCase.java | 42 +++--- .../org/apache/fop/GenericFOPTestCase.java | 8 +- 19 files changed, 215 insertions(+), 260 deletions(-) delete mode 100644 src/java/org/apache/fop/apps/Driver.java diff --git a/examples/embedding/java/embedding/ExampleDOM2PDF.java b/examples/embedding/java/embedding/ExampleDOM2PDF.java index 372ff274a..783c7a7ad 100644 --- a/examples/embedding/java/embedding/ExampleDOM2PDF.java +++ b/examples/embedding/java/embedding/ExampleDOM2PDF.java @@ -40,7 +40,7 @@ import org.w3c.dom.Node; import org.w3c.dom.Text; // FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; /** @@ -61,15 +61,15 @@ public class ExampleDOM2PDF { */ public void convertDOM2PDF(Document xslfoDoc, File pdf) { try { - // Construct driver with desired output format - Driver driver = new Driver(Driver.RENDER_PDF); + // Construct fop with desired output format + Fop fop = new Fop(Fop.RENDER_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdf); out = new java.io.BufferedOutputStream(out); try { - driver.setOutputStream(out); + fop.setOutputStream(out); // Setup Identity Transformer TransformerFactory factory = TransformerFactory.newInstance(); @@ -79,7 +79,7 @@ public class ExampleDOM2PDF { Source src = new DOMSource(xslfoDoc); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); diff --git a/examples/embedding/java/embedding/ExampleFO2PDF.java b/examples/embedding/java/embedding/ExampleFO2PDF.java index 2cac20729..388cdcaf4 100644 --- a/examples/embedding/java/embedding/ExampleFO2PDF.java +++ b/examples/embedding/java/embedding/ExampleFO2PDF.java @@ -35,7 +35,7 @@ import javax.xml.transform.sax.SAXResult; // FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; /** @@ -55,14 +55,14 @@ public class ExampleFO2PDF { OutputStream out = null; try { - // Construct driver with desired output format - Driver driver = new Driver(Driver.RENDER_PDF); + // Construct fop with desired output format + Fop fop = new Fop(Fop.RENDER_PDF); // Setup output stream. Note: Using BufferedOutputStream // for performance reasons (helpful with FileOutputStreams). out = new FileOutputStream(pdf); out = new BufferedOutputStream(out); - driver.setOutputStream(out); + fop.setOutputStream(out); // Setup JAXP using identity transformer TransformerFactory factory = TransformerFactory.newInstance(); @@ -72,7 +72,7 @@ public class ExampleFO2PDF { Source src = new StreamSource(fo); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); diff --git a/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java b/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java index de152b125..612f78974 100644 --- a/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java +++ b/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java @@ -36,7 +36,7 @@ import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.SAXException; // FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; /** @@ -63,14 +63,14 @@ public class ExampleFO2PDFUsingSAXParser { OutputStream out = null; try { - // Construct driver and setup output format - Driver driver = new Driver(Driver.RENDER_PDF); + // Construct fop and setup output format + Fop fop = new Fop(Fop.RENDER_PDF); // Setup output stream. Note: Using BufferedOutputStream // for performance reasons (helpful with FileOutputStreams). out = new FileOutputStream(pdf); out = new BufferedOutputStream(out); - driver.setOutputStream(out); + fop.setOutputStream(out); // Setup SAX parser // throws FactoryConfigurationError @@ -81,7 +81,7 @@ public class ExampleFO2PDFUsingSAXParser { // Obtain FOP's DefaultHandler // throws FOPException - DefaultHandler dh = driver.getDefaultHandler(); + DefaultHandler dh = fop.getDefaultHandler(); // Start parsing and FOP processing // throws SAXException, IOException diff --git a/examples/embedding/java/embedding/ExampleObj2PDF.java b/examples/embedding/java/embedding/ExampleObj2PDF.java index e68bc69c8..ba3b99f77 100644 --- a/examples/embedding/java/embedding/ExampleObj2PDF.java +++ b/examples/embedding/java/embedding/ExampleObj2PDF.java @@ -33,7 +33,7 @@ import javax.xml.transform.stream.StreamSource; import javax.xml.transform.sax.SAXResult; // FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; import embedding.model.ProjectTeam; @@ -55,14 +55,14 @@ public class ExampleObj2PDF { public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf) throws IOException, FOPException, TransformerException { - // Construct driver with desired output format - Driver driver = new Driver(Driver.RENDER_PDF); + // Construct fop with desired output format + Fop fop = new Fop(Fop.RENDER_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdf); out = new java.io.BufferedOutputStream(out); try { - driver.setOutputStream(out); + fop.setOutputStream(out); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); @@ -72,7 +72,7 @@ public class ExampleObj2PDF { Source src = team.getSourceForProjectTeam(); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); diff --git a/examples/embedding/java/embedding/ExampleXML2PDF.java b/examples/embedding/java/embedding/ExampleXML2PDF.java index fa99b843e..3f82b3e94 100644 --- a/examples/embedding/java/embedding/ExampleXML2PDF.java +++ b/examples/embedding/java/embedding/ExampleXML2PDF.java @@ -32,7 +32,7 @@ import javax.xml.transform.stream.StreamSource; import javax.xml.transform.sax.SAXResult; //FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; /** @@ -66,15 +66,15 @@ public class ExampleXML2PDF { System.out.println(); System.out.println("Transforming..."); - // Construct driver with desired output format - Driver driver = new Driver(Driver.RENDER_PDF); + // Construct fop with desired output format + Fop fop = new Fop(Fop.RENDER_PDF); // Setup output OutputStream out = new java.io.FileOutputStream(pdffile); out = new java.io.BufferedOutputStream(out); try { - driver.setOutputStream(out); + fop.setOutputStream(out); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); @@ -87,7 +87,7 @@ public class ExampleXML2PDF { Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); diff --git a/src/java/org/apache/fop/apps/CommandLineOptions.java b/src/java/org/apache/fop/apps/CommandLineOptions.java index 7e448632d..e26e767be 100644 --- a/src/java/org/apache/fop/apps/CommandLineOptions.java +++ b/src/java/org/apache/fop/apps/CommandLineOptions.java @@ -453,31 +453,23 @@ public class CommandLineOptions implements Constants { * @return the type chosen renderer * @throws FOPException for invalid output modes */ - public int getRenderer() throws FOPException { + protected int getRenderer() throws FOPException { switch (outputmode) { - case NOT_SET: - throw new FOPException("Renderer has not been set!"); case RENDER_PDF: - return Driver.RENDER_PDF; case RENDER_AWT: - return Driver.RENDER_AWT; case RENDER_MIF: - return Driver.RENDER_MIF; case RENDER_PRINT: - return Driver.RENDER_PRINT; case RENDER_PCL: - return Driver.RENDER_PCL; case RENDER_PS: - return Driver.RENDER_PS; case RENDER_TXT: - return Driver.RENDER_TXT; case RENDER_SVG: - return Driver.RENDER_SVG; + case RENDER_RTF: + return outputmode; case RENDER_XML: foUserAgent.getRendererOptions().put("fineDetail", isCoarseAreaXml()); - return Driver.RENDER_XML; - case RENDER_RTF: - return Driver.RENDER_RTF; + return RENDER_XML; + case NOT_SET: + throw new FOPException("Renderer has not been set!"); default: throw new FOPException("Invalid Renderer setting!"); } diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java deleted file mode 100644 index aa939e1c9..000000000 --- a/src/java/org/apache/fop/apps/Driver.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.apps; - -// Java -import java.io.OutputStream; - -// XML -import org.xml.sax.helpers.DefaultHandler; - -// FOP -import org.apache.fop.fo.Constants; -import org.apache.fop.fo.FOTreeBuilder; - -/** - * Primary class that drives the overall FOP process. - *

- * JAXP is the standard method of embedding FOP in Java programs. - * Please check our embedding page (http://xml.apache.org/fop/embedding.html) - * for samples (these are also available within the distribution in - * FOP_DIR\examples\embedding) - *

- * 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 { - - /** - * the render type code given by setRender - */ - private int renderType = NOT_SET; - - /** - * the stream to use to output the results of the renderer - */ - private OutputStream stream = null; - - /** - * The system resources that FOP will use - */ - private FOUserAgent foUserAgent = null; - - /** - * Constructor for use with already-created FOUserAgents - * @param renderType the type of renderer to use. Must be one of - *

- * @param ua FOUserAgent object - * @throws IllegalArgumentException if an unsupported renderer type was requested. - */ - public Driver(int renderType, FOUserAgent ua) { - if (renderType < Constants.RENDER_MIN_CONST - || renderType > Constants.RENDER_MAX_CONST) { - throw new IllegalArgumentException( - "Invalid render type #" + renderType); - } - - this.renderType = renderType; - - foUserAgent = ua; - if (foUserAgent == null) { - foUserAgent = new FOUserAgent(); - } - } - - /** - * Constructor that creates a default FOUserAgent - * @see org.apache.fop.apps.Driver#(int, FOUserAgent) - */ - public Driver(int renderType) { - this(renderType, new FOUserAgent()); - } - - /** - * Get the FOUserAgent instance for this process - * @return the user agent - */ - public FOUserAgent getUserAgent() { - return foUserAgent; - } - - /** - * Set the OutputStream to use to output the result of the Render - * (if applicable) - * @param stream the stream to output the result of rendering to - */ - public void setOutputStream(OutputStream stream) { - this.stream = stream; - } - - /** - * Returns a DefaultHandler object used to generate the document. - * Note this object implements the ContentHandler interface. - * For processing with a Transformer object, this DefaultHandler object - * can be used in the SAXResult constructor. - * Alternatively, for processing with a SAXParser, this object can be - * used as the DefaultHandler argument to its parse() methods. - * - * @return a SAX DefaultHandler for handling the SAX events. - * @throws FOPException if setting up the DefaultHandler fails - */ - public DefaultHandler getDefaultHandler() throws FOPException { - return new FOTreeBuilder(renderType, foUserAgent, stream); - } -} diff --git a/src/java/org/apache/fop/apps/FOFileHandler.java b/src/java/org/apache/fop/apps/FOFileHandler.java index dbf8a6fb1..30bc4195c 100644 --- a/src/java/org/apache/fop/apps/FOFileHandler.java +++ b/src/java/org/apache/fop/apps/FOFileHandler.java @@ -76,13 +76,13 @@ public class FOFileHandler extends InputHandler { } /** - * @see org.apache.fop.apps.InputHandler#render(Driver) + * @see org.apache.fop.apps.InputHandler#render(Fop) */ - public void render(Driver driver) throws FOPException { + public void render(Fop fop) throws FOPException { // temporary until baseURL removed from inputHandler objects - if (driver.getUserAgent().getBaseURL() == null) { - driver.getUserAgent().setBaseURL(getBaseURL()); + if (fop.getUserAgent().getBaseURL() == null) { + fop.getUserAgent().setBaseURL(getBaseURL()); } try { @@ -94,7 +94,7 @@ public class FOFileHandler extends InputHandler { Source src = new SAXSource(getInputSource()); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index dfdf2e6fb..a80647f0d 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -21,15 +21,112 @@ package org.apache.fop.apps; // Java import java.io.BufferedOutputStream; import java.io.FileOutputStream; +import java.io.OutputStream; -// FOP -import org.apache.fop.render.awt.AWTRenderer; +// XML +import org.xml.sax.helpers.DefaultHandler; +// FOP +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FOTreeBuilder; /** - * The main application class for the FOP command line interface (CLI). + * Primary class that activates the FOP process for both command line + * and embedded usage. + *

+ * JAXP is the standard method of embedding FOP in Java programs. + * Please check our embedding page (http://xml.apache.org/fop/embedding.html) + * for samples (these are also available within the distribution in + * FOP_DIR\examples\embedding) + *

+ * Methods within FOUserAgent are available to customize portions of the + * process. For example, a specific Renderer object can be specified, + * also ElementMappings which determine elements in the FO that can be + * processed) can be added. */ -public class Fop { +public class Fop implements Constants { + + // desired output type: RENDER_PDF, RENDER_PS, etc. + private int renderType = NOT_SET; + + // output stream to send results to + private OutputStream stream = null; + + // FOUserAgent object to set processing options + private FOUserAgent foUserAgent = null; + + /** + * Constructor for use with already-created FOUserAgents + * @param renderType the type of renderer to use. Must be one of + *

+ * @param ua FOUserAgent object + * @throws IllegalArgumentException if an unsupported renderer type was requested. + */ + public Fop(int renderType, FOUserAgent ua) { + if (renderType < Constants.RENDER_MIN_CONST + || renderType > Constants.RENDER_MAX_CONST) { + throw new IllegalArgumentException( + "Invalid render type #" + renderType); + } + + this.renderType = renderType; + + foUserAgent = ua; + if (foUserAgent == null) { + foUserAgent = new FOUserAgent(); + } + } + + /** + * Constructor that creates a default FOUserAgent + * @see org.apache.fop.apps.Fop#(int, FOUserAgent) + */ + public Fop(int renderType) { + this(renderType, new FOUserAgent()); + } + + /** + * Get the FOUserAgent instance for this process + * @return the user agent + */ + public FOUserAgent getUserAgent() { + return foUserAgent; + } + + /** + * Set the OutputStream to use to output the result of the Render + * (if applicable) + * @param stream the stream to output the result of rendering to + */ + public void setOutputStream(OutputStream stream) { + this.stream = stream; + } + + /** + * Returns a DefaultHandler object used to generate the document. + * Note this object implements the ContentHandler interface. + * For processing with a Transformer object, this DefaultHandler object + * can be used in the SAXResult constructor. + * Alternatively, for processing with a SAXParser, this object can be + * used as the DefaultHandler argument to its parse() methods. + * + * @return a SAX DefaultHandler for handling the SAX events. + * @throws FOPException if setting up the DefaultHandler fails + */ + public DefaultHandler getDefaultHandler() throws FOPException { + return new FOTreeBuilder(renderType, foUserAgent, stream); + } /** * The main routine for the command line interface @@ -44,15 +141,15 @@ public class Fop { options = new CommandLineOptions(args); foUserAgent = options.getFOUserAgent(); - Driver driver = new Driver(options.getRenderer(), foUserAgent); + Fop fop = new Fop(options.getRenderer(), foUserAgent); try { if (options.getOutputFile() != null) { bos = new BufferedOutputStream(new FileOutputStream( options.getOutputFile())); - driver.setOutputStream(bos); + fop.setOutputStream(bos); } - foUserAgent.getInputHandler().render(driver); + foUserAgent.getInputHandler().render(fop); } finally { if (bos != null) { bos.close(); @@ -96,4 +193,3 @@ public class Fop { return "1.0dev"; } } - diff --git a/src/java/org/apache/fop/apps/InputHandler.java b/src/java/org/apache/fop/apps/InputHandler.java index a457a268b..a172ec443 100644 --- a/src/java/org/apache/fop/apps/InputHandler.java +++ b/src/java/org/apache/fop/apps/InputHandler.java @@ -44,11 +44,11 @@ public abstract class InputHandler { } /** - * Generate a document, given an initialized Driver object - * @param driver -- Driver object + * Generate a document, given an initialized Fop object + * @param fop -- Fop object * @throws FOPException in case of an error during processing */ - public void render(Driver driver) throws FOPException {} + public void render(Fop fop) throws FOPException {} /** * Creates an InputSource from a URL. diff --git a/src/java/org/apache/fop/apps/XSLTInputHandler.java b/src/java/org/apache/fop/apps/XSLTInputHandler.java index a8bedf260..243181ac1 100644 --- a/src/java/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/java/org/apache/fop/apps/XSLTInputHandler.java @@ -105,14 +105,14 @@ public class XSLTInputHandler extends InputHandler { } /** - * @see org.apache.fop.apps.InputHandler#render(Driver) + * @see org.apache.fop.apps.InputHandler#render(Fop) */ - public void render(Driver driver) + public void render(Fop fop) throws FOPException { // temporary until baseURL removed from inputHandler objects - if (driver.getUserAgent().getBaseURL() == null) { - driver.getUserAgent().setBaseURL(getBaseURL()); + if (fop.getUserAgent().getBaseURL() == null) { + fop.getUserAgent().setBaseURL(getBaseURL()); } try { @@ -129,7 +129,7 @@ public class XSLTInputHandler extends InputHandler { } // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(xmlSource, res); diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java index e8915b4eb..496776b1f 100644 --- a/src/java/org/apache/fop/fo/Constants.java +++ b/src/java/org/apache/fop/fo/Constants.java @@ -22,7 +22,7 @@ package org.apache.fop.fo; public interface Constants { /* These constants are used by apps.CommandLineOptions and - apps.Driver to describe the input (either .FO or .XML/.XSL) + apps.Fop to describe the input (either .FO or .XML/.XSL) and desired output (PDF, PS, AWT, etc.) of the document */ /** render constants for bounds checking */ 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 6eb868269..21218d3e5 100644 --- a/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java +++ b/src/java/org/apache/fop/render/awt/viewer/PreviewDialog.java @@ -48,7 +48,7 @@ import java.awt.print.PrinterJob; import java.awt.print.PrinterException; //FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.Constants; @@ -69,8 +69,8 @@ public class PreviewDialog extends JFrame { protected AWTRenderer renderer; /** The FOUserAgent associated with this window */ protected FOUserAgent foUserAgent; - /** The Driver used for refreshing/reloading the view */ - protected Driver driver; + /** The Fop object used for refreshing/reloading the view */ + protected Fop fop; private int currentPage = 0; private int pageCount = 0; @@ -384,8 +384,8 @@ public class PreviewDialog extends JFrame { */ private class Reloader extends Thread { public void run() { - if (driver == null) { - driver = new Driver(Constants.RENDER_AWT, foUserAgent); + if (fop == null) { + fop = new Fop(Constants.RENDER_AWT, foUserAgent); } pageLabel.setIcon(null); @@ -394,7 +394,7 @@ public class PreviewDialog extends JFrame { try { setStatus(translator.getString("Status.Build.FO.tree")); - foUserAgent.getInputHandler().render(driver); + foUserAgent.getInputHandler().render(fop); setStatus(translator.getString("Status.Show")); } catch (FOPException e) { reportException(e); diff --git a/src/java/org/apache/fop/servlet/FopPrintServlet.java b/src/java/org/apache/fop/servlet/FopPrintServlet.java index 55a868214..699aef012 100644 --- a/src/java/org/apache/fop/servlet/FopPrintServlet.java +++ b/src/java/org/apache/fop/servlet/FopPrintServlet.java @@ -37,7 +37,7 @@ import javax.xml.transform.stream.StreamSource; // XML import org.apache.commons.logging.impl.SimpleLog; import org.apache.commons.logging.Log; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.xml.sax.InputSource; //Java @@ -138,7 +138,7 @@ public class FopPrintServlet extends HttpServlet { public void renderFO(InputStream foFile, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(Driver.RENDER_PRINT); + Fop fop = new Fop(Fop.RENDER_PRINT); // Setup JAXP TransformerFactory factory = TransformerFactory.newInstance(); @@ -148,7 +148,7 @@ public class FopPrintServlet extends HttpServlet { Source src = new StreamSource(foFile); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); @@ -169,7 +169,7 @@ public class FopPrintServlet extends HttpServlet { public void renderXML(File xmlfile, File xsltfile, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(Driver.RENDER_PRINT); + Fop fop = new Fop(Fop.RENDER_PRINT); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); @@ -179,7 +179,7 @@ public class FopPrintServlet extends HttpServlet { Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); diff --git a/src/java/org/apache/fop/servlet/FopServlet.java b/src/java/org/apache/fop/servlet/FopServlet.java index 6a626786d..ca04bd486 100644 --- a/src/java/org/apache/fop/servlet/FopServlet.java +++ b/src/java/org/apache/fop/servlet/FopServlet.java @@ -38,7 +38,7 @@ import org.apache.commons.logging.impl.SimpleLog; import org.apache.commons.logging.Log; //FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOPException; /** @@ -201,14 +201,14 @@ public class FopServlet extends HttpServlet { throws FOPException, TransformerException { //Setup FOP - Driver driver = new Driver(Driver.RENDER_PDF); + Fop fop = new Fop(Fop.RENDER_PDF); //Setup output ByteArrayOutputStream out = new ByteArrayOutputStream(); - driver.setOutputStream(out); + fop.setOutputStream(out); //Make sure the XSL transformation's result is piped through to FOP - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); //Start the transformation and rendering process transformer.transform(src, res); diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index 5469e06ad..3b331b489 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -26,7 +26,7 @@ import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOFileHandler; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.InputHandler; @@ -49,13 +49,11 @@ import org.apache.commons.logging.impl.SimpleLog; * versions of FOP or the pdf can be view for manual checking and * pdf rendering. * - * Modified by Mark Lillywhite mark-fop@inomial.com to use the new Driver - * interface. */ public class TestConverter { private boolean failOnly = false; - private int renderType = Driver.RENDER_XML; + private int renderType = Fop.RENDER_XML; private File destdir; private File compare = null; private String baseDir = "./"; @@ -106,7 +104,7 @@ public class TestConverter { if (args[count].equals("-failOnly")) { tc.setFailOnly(true); } else if (args[count].equals("-pdf")) { - tc.setRenderType(Driver.RENDER_PDF); + tc.setRenderType(Fop.RENDER_PDF); } else if (args[count].equals("-d")) { tc.setDebug(true); } else if (args[count].equals("-b")) { @@ -307,7 +305,7 @@ public class TestConverter { FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(baseURL); - Driver driver = new Driver(renderType, userAgent); + Fop fop = new Fop(renderType, userAgent); userAgent.getRendererOptions().put("fineDetail", new Boolean(false)); userAgent.getRendererOptions().put("consistentOutput", new Boolean(true)); @@ -318,15 +316,15 @@ public class TestConverter { outname = outname.substring(0, outname.length() - 4); } File outputFile = new File(destdir, // assuming only RENDER_PDF or RENDER_XML here - outname + ((renderType==Driver.RENDER_PDF) ? ".pdf" : ".at.xml")); + outname + ((renderType==Fop.RENDER_PDF) ? ".pdf" : ".at.xml")); outputFile.getParentFile().mkdirs(); OutputStream outStream = new java.io.BufferedOutputStream( new java.io.FileOutputStream(outputFile)); - driver.setOutputStream(outStream); + fop.setOutputStream(outStream); logger.debug("ddir:" + destdir + " on:" + outputFile.getName()); - inputHandler.render(driver); + inputHandler.render(fop); outStream.close(); // check difference diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index 9c641ba08..633b37b1d 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -36,7 +36,7 @@ import java.util.List; // FOP import org.apache.fop.apps.InputHandler; import org.apache.fop.apps.FOFileHandler; -import org.apache.fop.apps.Driver; +import org.apache.fop.fo.Constants; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; @@ -334,27 +334,27 @@ class FOPTaskStarter { if ((format == null) || format.equalsIgnoreCase("application/pdf") || format.equalsIgnoreCase("pdf")) { - return Driver.RENDER_PDF; + return Constants.RENDER_PDF; } else if (format.equalsIgnoreCase("application/postscript") || format.equalsIgnoreCase("ps")) { - return Driver.RENDER_PS; + return Constants.RENDER_PS; } else if (format.equalsIgnoreCase("application/vnd.mif") || format.equalsIgnoreCase("mif")) { - return Driver.RENDER_MIF; + return Constants.RENDER_MIF; } else if (format.equalsIgnoreCase("application/msword") || format.equalsIgnoreCase("application/rtf") || format.equalsIgnoreCase("rtf")) { - return Driver.RENDER_RTF; + return Constants.RENDER_RTF; } else if (format.equalsIgnoreCase("application/vnd.hp-PCL") || format.equalsIgnoreCase("pcl")) { - return Driver.RENDER_PCL; + return Constants.RENDER_PCL; } else if (format.equalsIgnoreCase("text/plain") || format.equalsIgnoreCase("txt")) { - return Driver.RENDER_TXT; + return Constants.RENDER_TXT; } else if (format.equalsIgnoreCase("text/xml") || format.equalsIgnoreCase("at") || format.equalsIgnoreCase("xml")) { - return Driver.RENDER_XML; + return Constants.RENDER_XML; } else { String err = "Couldn't determine renderer to use: " + format; throw new BuildException(err); @@ -363,19 +363,19 @@ class FOPTaskStarter { private String determineExtension(int renderer) { switch (renderer) { - case Driver.RENDER_PDF: + case Constants.RENDER_PDF: return ".pdf"; - case Driver.RENDER_PS: + case Constants.RENDER_PS: return ".ps"; - case Driver.RENDER_MIF: + case Constants.RENDER_MIF: return ".mif"; - case Driver.RENDER_RTF: + case Constants.RENDER_RTF: return ".rtf"; - case Driver.RENDER_PCL: + case Constants.RENDER_PCL: return ".pcl"; - case Driver.RENDER_TXT: + case Constants.RENDER_TXT: return ".txt"; - case Driver.RENDER_XML: + case Constants.RENDER_XML: return ".xml"; default: String err = "Unknown renderer: " + renderer; @@ -533,9 +533,10 @@ class FOPTaskStarter { try { FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(this.baseURL); - Driver driver = new Driver(renderer, userAgent); - driver.setOutputStream(out); - inputHandler.render(driver); + org.apache.fop.apps.Fop fop = + new org.apache.fop.apps.Fop(renderer, userAgent); + fop.setOutputStream(out); + inputHandler.render(fop); } catch (Exception ex) { throw new BuildException(ex); } finally { diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index 2a4f4ce00..48c8678da 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -35,13 +35,13 @@ import javax.xml.transform.stream.StreamSource; import org.xml.sax.InputSource; import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.InputHandler; import org.apache.fop.apps.XSLTInputHandler; import org.w3c.dom.Document; /** - * Basic runtime test for the old Driver class. It is used to verify that + * Basic runtime test for the old Fop class. It is used to verify that * nothing obvious is broken after compiling. * @author Jeremias Maerki */ @@ -71,88 +71,88 @@ 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.RENDER_PDF); - driver.setOutputStream(baout); + Fop fop = new Fop(Fop.RENDER_PDF); + fop.setOutputStream(baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new DOMSource(loadDocument(foFile)); - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated PostScript has zero length", baout.size() > 0); } /** - * Tests Driver with JAXP and OutputStream generating PDF. + * Tests Fop with JAXP and OutputStream generating PDF. * @throws Exception if anything fails */ public void testFO2PDFWithJAXP() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(Driver.RENDER_PDF); - driver.setOutputStream(baout); + Fop fop = new Fop(Fop.RENDER_PDF); + fop.setOutputStream(baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated PDF has zero length", baout.size() > 0); } /** - * Tests Driver with JAXP and OutputStream generating PostScript. + * Tests Fop with JAXP and OutputStream generating PostScript. * @throws Exception if anything fails */ public void testFO2PSWithJAXP() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(Driver.RENDER_PS); - driver.setOutputStream(baout); + Fop fop = new Fop(Fop.RENDER_PS); + fop.setOutputStream(baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated PostScript has zero length", baout.size() > 0); } /** - * Tests Driver with JAXP and OutputStream generating RTF. + * Tests Fop with JAXP and OutputStream generating RTF. * @throws Exception if anything fails */ public void testFO2RTFWithJAXP() throws Exception { File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(Driver.RENDER_RTF); - driver.setOutputStream(baout); + Fop fop = new Fop(Fop.RENDER_RTF); + fop.setOutputStream(baout); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); - Result res = new SAXResult(driver.getDefaultHandler()); + Result res = new SAXResult(fop.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated RTF has zero length", baout.size() > 0); } /** - * Tests Driver with XsltInputHandler and OutputStream. + * Tests Fop with XsltInputHandler and OutputStream. * @throws Exception if anything fails */ public void testFO2PDFWithXSLTInputHandler() throws Exception { 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.RENDER_PDF); - driver.setOutputStream(baout); + Fop fop = new Fop(Fop.RENDER_PDF); + fop.setOutputStream(baout); InputHandler handler = new XSLTInputHandler(xmlFile, xsltFile); - handler.render(driver); + handler.render(fop); assertTrue("Generated PDF has zero length", baout.size() > 0); } diff --git a/test/java/org/apache/fop/GenericFOPTestCase.java b/test/java/org/apache/fop/GenericFOPTestCase.java index 39803329f..69e9e15b0 100644 --- a/test/java/org/apache/fop/GenericFOPTestCase.java +++ b/test/java/org/apache/fop/GenericFOPTestCase.java @@ -30,7 +30,7 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Fop; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.render.pdf.PDFRenderer; import org.apache.fop.util.DigestFilter; @@ -118,12 +118,12 @@ public final class GenericFOPTestCase extends TestCase { ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); DigestOutputStream out = new DigestOutputStream(new ByteArrayOutputStream(), outDigest); - Driver driver = new Driver(Driver.RENDER_PDF, foUserAgent); - driver.setOutputStream(out); + Fop fop = new Fop(Fop.RENDER_PDF, foUserAgent); + fop.setOutputStream(out); InputSource source = new InputSource(new StringReader(fo)); DigestFilter filter = new DigestFilter("MD5"); filter.setParent(parserFactory.newSAXParser().getXMLReader()); - filter.setContentHandler(driver.getDefaultHandler()); + filter.setContentHandler(fop.getDefaultHandler()); filter.parse(source); String digestInActual = digestToString(filter.getDigestValue()); if (!digestIn.equals(digestInActual)) { -- 2.39.5