gmazza 2004/07/14 16:01:56 Modified: src/java/org/apache/fop/apps Driver.java src/java/org/apache/fop/servlet FopPrintServlet.java test/java/org/apache/fop BasicDriverTestCase.java Log: Removed the Driver.run() method in favor of JAXP. Revision Changes Path 1.84 +5 -60 xml-fop/src/java/org/apache/fop/apps/Driver.java Index: Driver.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v retrieving revision 1.83 retrieving revision 1.84 diff -u -r1.83 -r1.84 --- Driver.java 13 Jul 2004 05:25:26 -0000 1.83 +++ Driver.java 14 Jul 2004 23:01:56 -0000 1.84 @@ -37,18 +37,11 @@ /** * 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 @@ * 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 @@ 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 @@ * @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 @@ * 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 @@ } /** - * 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> @@ -329,28 +297,5 @@ } catch (IOException e) { 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); } } 1.15 +16 -4 xml-fop/src/java/org/apache/fop/servlet/FopPrintServlet.java Index: FopPrintServlet.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/servlet/FopPrintServlet.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- FopPrintServlet.java 11 Jul 2004 22:55:08 -0000 1.14 +++ FopPrintServlet.java 14 Jul 2004 23:01:56 -0000 1.15 @@ -110,7 +110,7 @@ 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 @@ * @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); 1.8 +1 -33 xml-fop/test/java/org/apache/fop/BasicDriverTestCase.java Index: BasicDriverTestCase.java =================================================================== RCS file: /home/cvs/xml-fop/test/java/org/apache/fop/BasicDriverTestCase.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- BasicDriverTestCase.java 7 Jul 2004 22:16:53 -0000 1.7 +++ BasicDriverTestCase.java 14 Jul 2004 23:01:56 -0000 1.8 @@ -54,38 +54,6 @@ 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();
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]