gmazza 2004/07/19 15:46:14 Modified: examples/embedding build.xml examples/embedding/java/embedding ExampleDOM2PDF.java ExampleFO2PDF.java ExampleObj2PDF.java ExampleXML2PDF.java src/java/org/apache/fop/apps Driver.java src/java/org/apache/fop/servlet FopPrintServlet.java FopServlet.java test/java/org/apache/fop BasicDriverTestCase.java Added: examples/embedding/java/embedding ExampleFO2PDFUsingSAXParser.java Removed: examples/embedding/java/embedding ExampleFO2PDFUsingSAX.java Log: 1.) Moved exclusively to Simon's DefaultHandler object for both Transformer and SAXParser usage. DefaultHandler implements the ContentHandler interface so it can be used where the latter was previously used, also it provides more functionality. [1] 2.) Updated the examples and internal code accordingly. 3.) Renamed ExampleFO2PDFUsingSAX to ...Parser to avoid confusion (both use SAX.) [1] http://www.cafeconleche.org/books/xmljava/chapters/ch06s03.html#d0e8440 Revision Changes Path 1.9 +1 -1 xml-fop/examples/embedding/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-fop/examples/embedding/build.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- build.xml 19 Jul 2004 05:33:33 -0000 1.8 +++ build.xml 19 Jul 2004 22:46:13 -0000 1.9 @@ -86,7 +86,7 @@ </target> <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"> + <java classname="${name}.ExampleFO2PDFUsingSAXParser" fork="yes"> <classpath> <path refid="project.class.path"/> <pathelement location="${build.dest}"/> 1.11 +2 -2 xml-fop/examples/embedding/java/embedding/ExampleDOM2PDF.java Index: ExampleDOM2PDF.java =================================================================== RCS file: /home/cvs/xml-fop/examples/embedding/java/embedding/ExampleDOM2PDF.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ExampleDOM2PDF.java 19 Jul 2004 05:33:33 -0000 1.10 +++ ExampleDOM2PDF.java 19 Jul 2004 22:46:14 -0000 1.11 @@ -79,7 +79,7 @@ Source src = new DOMSource(xslfoDoc); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); 1.14 +1 -1 xml-fop/examples/embedding/java/embedding/ExampleFO2PDF.java Index: ExampleFO2PDF.java =================================================================== RCS file: /home/cvs/xml-fop/examples/embedding/java/embedding/ExampleFO2PDF.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ExampleFO2PDF.java 19 Jul 2004 05:33:33 -0000 1.13 +++ ExampleFO2PDF.java 19 Jul 2004 22:46:14 -0000 1.14 @@ -72,7 +72,7 @@ Source src = new StreamSource(fo); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); 1.10 +1 -1 xml-fop/examples/embedding/java/embedding/ExampleObj2PDF.java Index: ExampleObj2PDF.java =================================================================== RCS file: /home/cvs/xml-fop/examples/embedding/java/embedding/ExampleObj2PDF.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ExampleObj2PDF.java 19 Jul 2004 05:33:33 -0000 1.9 +++ ExampleObj2PDF.java 19 Jul 2004 22:46:14 -0000 1.10 @@ -72,7 +72,7 @@ Source src = team.getSourceForProjectTeam(); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); 1.12 +1 -1 xml-fop/examples/embedding/java/embedding/ExampleXML2PDF.java Index: ExampleXML2PDF.java =================================================================== RCS file: /home/cvs/xml-fop/examples/embedding/java/embedding/ExampleXML2PDF.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ExampleXML2PDF.java 19 Jul 2004 05:33:33 -0000 1.11 +++ ExampleXML2PDF.java 19 Jul 2004 22:46:14 -0000 1.12 @@ -87,7 +87,7 @@ Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); 1.1 xml-fop/examples/embedding/java/embedding/ExampleFO2PDFUsingSAXParser.java Index: ExampleFO2PDFUsingSAXParser.java =================================================================== /* * 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: ExampleFO2PDFUsingSAXParser.java,v 1.1 2004/07/19 22:46:14 gmazza Exp $ */ package embedding; // Java import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; //JAXP import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.SAXParser; import javax.xml.parsers.ParserConfigurationException; //SAX import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.SAXException; // FOP import org.apache.fop.apps.Driver; import org.apache.fop.apps.FOPException; /** * This class demonstrates the conversion of an FO file to PDF using FOP. * It uses a SAXParser with FOP as the DefaultHandler */ public class ExampleFO2PDFUsingSAXParser { /** * Converts an FO file to a PDF file using FOP * @param fo the FO file * @param pdf the target PDF file * @throws FactoryConfigurationError * @throws ParserConfigurationException * @throws SAXException * @throws IOException In case of an I/O problem * @throws FOPException In case of a FOP problem */ public void convertFO2PDF(File fo, File pdf) throws FactoryConfigurationError, ParserConfigurationException, FOPException, SAXException, IOException { OutputStream out = null; try { // Construct driver and setup output format Driver driver = new Driver(Driver.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); // Setup SAX parser // throws FactoryConfigurationError SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); // throws ParserConfigurationException SAXParser parser = factory.newSAXParser(); // Obtain FOP's DefaultHandler // throws FOPException DefaultHandler dh = driver.getDefaultHandler(); // Start parsing and FOP processing // throws SAXException, IOException parser.parse(fo, dh); } finally { out.close(); } } /** * Main method. * @param args command-line arguments */ public static void main(String[] args) { try { System.out.println("FOP ExampleFO2PDFUsingSAXParser\n"); System.out.println("Preparing..."); //Setup directories File baseDir = new File("."); File outDir = new File(baseDir, "out"); outDir.mkdirs(); //Setup input and output files File fofile = new File(baseDir, "xml/fo/helloworld.fo"); File pdffile = new File(outDir, "ResultFO2PDFUsingSAXParser.pdf"); System.out.println("Input: XSL-FO (" + fofile + ")"); System.out.println("Output: PDF (" + pdffile + ")"); System.out.println(); System.out.println("Transforming..."); ExampleFO2PDFUsingSAXParser app = new ExampleFO2PDFUsingSAXParser(); app.convertFO2PDF(fofile, pdffile); System.out.println("Success!"); } catch (Exception e) { e.printStackTrace(System.err); System.exit(-1); } } } 1.91 +9 -12 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.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- Driver.java 19 Jul 2004 05:33:34 -0000 1.90 +++ Driver.java 19 Jul 2004 22:46:14 -0000 1.91 @@ -23,7 +23,6 @@ import java.io.OutputStream; // XML -import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; @@ -126,11 +125,13 @@ } /** - * 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 - * renderers (e.g. PDF & PostScript) use a ContentHandler that builds an FO - * Tree. + * 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 */ @@ -138,10 +139,6 @@ return new FOTreeBuilder(renderType, foUserAgent, stream); } - public ContentHandler getContentHandler() throws FOPException { - return getDefaultHandler(); - } - /** * Render the FO document read by a SAX Parser from an InputHandler * @param inputHandler the input handler containing the source and @@ -167,7 +164,7 @@ */ public synchronized void render(XMLReader parser, InputSource source) throws FOPException { - parser.setContentHandler(getContentHandler()); + parser.setContentHandler(getDefaultHandler()); try { /** 1.17 +2 -2 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- FopPrintServlet.java 19 Jul 2004 05:33:34 -0000 1.16 +++ FopPrintServlet.java 19 Jul 2004 22:46:14 -0000 1.17 @@ -148,7 +148,7 @@ Source src = new StreamSource(foFile); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); @@ -179,7 +179,7 @@ Source src = new StreamSource(xmlfile); // Resulting SAX events (the generated FO) must be piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); 1.10 +1 -1 xml-fop/src/java/org/apache/fop/servlet/FopServlet.java Index: FopServlet.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/servlet/FopServlet.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- FopServlet.java 19 Jul 2004 05:33:34 -0000 1.9 +++ FopServlet.java 19 Jul 2004 22:46:14 -0000 1.10 @@ -208,7 +208,7 @@ driver.setOutputStream(out); //Make sure the XSL transformation's result is piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); //Start the transformation and rendering process transformer.transform(src, res); 1.10 +5 -5 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BasicDriverTestCase.java 19 Jul 2004 05:33:35 -0000 1.9 +++ BasicDriverTestCase.java 19 Jul 2004 22:46:14 -0000 1.10 @@ -77,7 +77,7 @@ TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new DOMSource(loadDocument(foFile)); - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated PostScript has zero length", baout.size() > 0); @@ -115,7 +115,7 @@ TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated PDF has zero length", baout.size() > 0); @@ -134,7 +134,7 @@ TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated PostScript has zero length", baout.size() > 0); @@ -153,7 +153,7 @@ TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); //Identity transf. Source src = new StreamSource(foFile); - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(driver.getDefaultHandler()); transformer.transform(src, res); assertTrue("Generated RTF has zero length", baout.size() > 0);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]