gmazza 2004/07/15 20:29:57
Modified: examples/embedding/java/embedding ExampleFO2PDF.java
Log:
*Temporary* commit showing how this process works via SAXParserFactory;
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.
Revision Changes Path
1.11 +23 -5 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ExampleFO2PDF.java 14 Jul 2004 22:45:27 -0000 1.10
+++ ExampleFO2PDF.java 16 Jul 2004 03:29:57 -0000 1.11
@@ -21,6 +21,8 @@
// 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.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 @@
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);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]