// 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;
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;
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);