]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
*Temporary* commit showing how this process works via SAXParserFactory;
authorGlen Mazza <gmazza@apache.org>
Fri, 16 Jul 2004 03:29:57 +0000 (03:29 +0000)
committerGlen Mazza <gmazza@apache.org>
Fri, 16 Jul 2004 03:29:57 +0000 (03:29 +0000)
including just for future reference should we get a question on this class
or wish to document this method on our web pages in the future.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197792 13f79535-47bb-0310-9956-ffa450edef68

examples/embedding/java/embedding/ExampleFO2PDF.java

index b92e79abd471de3c78f8f4669b9a11bb56ae7750..d86e13b27ee6047b67d631d2143c8e0b65f2b224 100644 (file)
@@ -21,6 +21,8 @@ package embedding;
 // Java
 import java.io.File;
 import java.io.IOException;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 
@@ -30,7 +32,11 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.Source;
 import javax.xml.transform.Result;
 import javax.xml.transform.stream.StreamSource;
+import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.sax.SAXResult;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+
 
 // FOP
 import org.apache.fop.apps.Driver;
@@ -57,23 +63,35 @@ public class ExampleFO2PDF {
             Driver driver = new Driver();
             driver.setRenderer(Driver.RENDER_PDF);
     
-            // Setup output
+            // Setup output stream
+            // For performance, also buffering output stream.
+            // Note: buffering recommended for FileOutputStreams
+            // but not for ByteArrayOutputStreams.
             out = new java.io.FileOutputStream(pdf);
+            out = new java.io.BufferedOutputStream(out);
             driver.setOutputStream(out);
 
+            InputSource src = new InputSource(new FileInputStream(fo));
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            factory.setNamespaceAware(true);
+            XMLReader parser = factory.newSAXParser().getXMLReader();
+            parser.setContentHandler(driver.getContentHandler());
+            parser.parse(src);
+
+/*
+            // Setup input stream
+            Source src = new StreamSource(fo);
+
             // Setup JAXP using identity transformer
             TransformerFactory factory = TransformerFactory.newInstance();
             Transformer transformer = factory.newTransformer(); // identity transformer
             
-            // Setup input for XSLT transformation
-            Source src = new StreamSource(fo);
-            
             // 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);
-
+*/
         } catch (Exception e) {
             e.printStackTrace(System.err);
             System.exit(-1);