diff options
author | Glen Mazza <gmazza@apache.org> | 2004-07-14 23:01:56 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-07-14 23:01:56 +0000 |
commit | 333b61994a635ba451b5ffbd73a6eaafdca5fdab (patch) | |
tree | 85977580b08d254f2084c0b9ee82f26752d2cc7a | |
parent | 3bb5fd04ea7df8db773c5e8f75aecdb788f509fa (diff) | |
download | xmlgraphics-fop-333b61994a635ba451b5ffbd73a6eaafdca5fdab.tar.gz xmlgraphics-fop-333b61994a635ba451b5ffbd73a6eaafdca5fdab.zip |
Removed the Driver.run() method in favor of JAXP.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197790 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/apps/Driver.java | 65 | ||||
-rw-r--r-- | src/java/org/apache/fop/servlet/FopPrintServlet.java | 20 | ||||
-rw-r--r-- | test/java/org/apache/fop/BasicDriverTestCase.java | 32 |
3 files changed, 21 insertions, 96 deletions
diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 2a765c74e..97715b25a 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -37,18 +37,11 @@ import org.apache.fop.render.awt.AWTRenderer; /** * Primary class that drives overall FOP process. * <P> - * The simplest way to use this is to instantiate it with the - * InputSource and OutputStream, then set the renderer desired, and - * calling run(); + * 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) * <P> - * Here is an example use of Driver which outputs PDF: - * - * <PRE> - * Driver driver = new Driver(new InputSource (args[0]), - * new FileOutputStream(args[1])); - * driver.setRenderer(RENDER_PDF); - * driver.run(); - * </PRE> * If necessary, calling classes can call into the lower level * methods to setup and * render. Methods within FOUserAgent can be called to set the @@ -64,15 +57,6 @@ import org.apache.fop.render.awt.AWTRenderer; * is called. The invocation of the method is * render(Parser, InputSource). * <P> - * A third possibility may be used to build the FO Tree, namely - * calling getContentHandler() and firing the SAX events yourself. - * This will work either for DOM Tree input or SAX. See the embed - * examples on the FOP web page for more details or in the - * examples\embedding directory of the main distribution for more details. - * <P> - * Once the FO Tree is built, the format() and render() methods may be - * called in that order. - * <P> * Here is an example use of Driver which outputs to AWT: * * <PRE> @@ -94,11 +78,6 @@ public class Driver implements Constants { private int renderType = NOT_SET; /** - * the source of the FO file - */ - private InputSource source; - - /** * the stream to use to output the results of the renderer */ private OutputStream stream; @@ -130,9 +109,8 @@ public class Driver implements Constants { * @param source InputSource to take the XSL-FO input from * @param stream Target output stream */ - public Driver(InputSource source, OutputStream stream) { + public Driver(OutputStream stream) { this(); - this.source = source; this.stream = stream; } @@ -159,7 +137,6 @@ public class Driver implements Constants { * The output stream is cleared. The renderer is cleared. */ public synchronized void reset() { - source = null; stream = null; if (treeBuilder != null) { treeBuilder.reset(); @@ -206,15 +183,6 @@ public class Driver implements Constants { } /** - * Set the source for the FO document. This can be a normal SAX - * InputSource, or an DocumentInputSource containing a DOM document. - * @see DocumentInputSource - */ - public void setInputSource(InputSource source) { - this.source = source; - } - - /** * Method to set the rendering type desired. Must be one of * <ul> * <li>Driver.RENDER_PDF</li> @@ -330,27 +298,4 @@ public class Driver implements Constants { throw new FOPException(e); } } - - /** - * Runs the formatting and rendering process using the previously set - * parser, input source, renderer and output stream. - * If no parser was set, get a default SAX parser. - * @throws IOException in case of IO errors. - * @throws FOPException if anything else goes wrong. - */ - public synchronized void run() throws IOException, FOPException { - if (!isInitialized()) { - initialize(); - } - - if (renderType == NOT_SET) { - renderType = RENDER_PDF; - } - - if (source == null) { - throw new FOPException("InputSource is not set."); - } - - render(FOFileHandler.createParser(), source); - } } diff --git a/src/java/org/apache/fop/servlet/FopPrintServlet.java b/src/java/org/apache/fop/servlet/FopPrintServlet.java index 301a70242..e83ce85c6 100644 --- a/src/java/org/apache/fop/servlet/FopPrintServlet.java +++ b/src/java/org/apache/fop/servlet/FopPrintServlet.java @@ -110,7 +110,7 @@ public class FopPrintServlet extends HttpServlet { if (foParam != null) { InputStream file = new java.io.FileInputStream(foParam); - renderFO(new InputSource(file), response); + renderFO(file, response); } else if ((xmlParam != null) && (xsltParam != null)) { renderXML(new File(xmlParam), new File(xsltParam), response); } else { @@ -135,13 +135,25 @@ public class FopPrintServlet extends HttpServlet { * @param response Response to write to * @throws ServletException In case of a problem */ - public void renderFO(InputSource foFile, + public void renderFO(InputStream foFile, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(foFile, null); + Driver driver = new Driver(); driver.setRenderer(Driver.RENDER_PRINT); - driver.run(); + // Setup JAXP + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); //identity transformer + + // Setup input for XSLT transformation + Source src = new StreamSource(foFile); + + // 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); + reportOK (response); } catch (Exception ex) { throw new ServletException(ex); diff --git a/test/java/org/apache/fop/BasicDriverTestCase.java b/test/java/org/apache/fop/BasicDriverTestCase.java index d591d6602..5f722fbc1 100644 --- a/test/java/org/apache/fop/BasicDriverTestCase.java +++ b/test/java/org/apache/fop/BasicDriverTestCase.java @@ -54,38 +54,6 @@ public class BasicDriverTestCase extends AbstractFOPTestCase { super(name); } - /** - * Tests Driver with its special constructor for FO-->PDF conversion. - * @throws Exception if anything fails - */ - public void testFO2PDFWithConstructorSetup() throws Exception { - File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver( - new InputSource(foFile.toURL().toExternalForm()), - baout); - - driver.setRenderer(Driver.RENDER_PDF); - driver.run(); - assertTrue("Generated PDF has zero length", baout.size() > 0); - } - - /** - * Tests Driver with InputSource and OutputStream. - * @throws Exception if anything fails - */ - public void testFO2PDFWithInputSource() throws Exception { - File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo"); - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - Driver driver = new Driver(); - - driver.setInputSource(new InputSource(foFile.toURL().toExternalForm())); - driver.setOutputStream(baout); - driver.setRenderer(Driver.RENDER_PDF); - driver.run(); - assertTrue("Generated PDF has zero length", baout.size() > 0); - } - private Document loadDocument(File foFile) throws TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); |