printUsage();
throw e;
}
+
+ foUserAgent.setInputHandler(createInputHandler());
}
/**
throw new FOPException("No output file specified");
}
+ if ((outputmode == AWT_OUTPUT || outputmode == PRINT_OUTPUT) && outfile != null) {
+ throw new FOPException("Output file may not be specified " +
+ "for AWT or PRINT output");
+ }
+
if (inputmode == XSLT_INPUT) {
// check whether xml *and* xslt file have been set
if (xmlfile == null) {
}
/**
- * Get the input handler.
- * @return the input handler
- * @throws FOPException if creating the InputHandler fails
+ * Create an InputHandler object based on command-line parameters
+ * @return a new InputHandler instance
+ * @throws IllegalStateException if invalid/missing parameters
*/
- public InputHandler getInputHandler() throws FOPException {
+ private InputHandler createInputHandler() throws IllegalArgumentException {
switch (inputmode) {
- case FO_INPUT:
- return new FOFileHandler(fofile);
- case XSLT_INPUT:
- return new XSLTInputHandler(xmlfile, xsltfile, xsltParams);
- default:
- throw new FOPException("Invalid inputmode setting!");
+ case FO_INPUT:
+ return new FOFileHandler(fofile);
+ case XSLT_INPUT:
+ return new XSLTInputHandler(xmlfile, xsltfile, xsltParams);
+ default:
+ throw new IllegalArgumentException("Error creating InputHandler object.");
}
}
setRenderer("org.apache.fop.render.pdf.PDFRenderer");
break;
case RENDER_AWT:
- throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT");
+ setRenderer("org.apache.fop.render.awt.AWTRenderer");
+ break;
case RENDER_PRINT:
setRenderer("org.apache.fop.render.awt.AWTPrintRenderer");
break;
this.renderer = renderer;
}
- /**
- * Returns the currently active renderer.
- * @return the renderer
- */
- public Renderer getRenderer() {
- return renderer;
- }
-
/**
* Set the class name of the Renderer to use as well as the
* producer string for those renderers that can make use of it.
private PDFEncryptionParams pdfEncryptionParams;
private float px2mm = 0.35277777777777777778f; //72dpi (=25.4/dpi)
private HashMap rendererOptions = new java.util.HashMap();
-
+ private InputHandler inputHandler = null;
+
+
/** Producer: Metadata element for the system/software that produces
* the document. (Some renderers can store this in the document.)
*/
*/
protected Date creationDate = null;
+ /**
+ * Sets the InputHandler object for this process
+ * @param inputHandler holding input file name information
+ */
+ public void setInputHandler(InputHandler inputHandler) {
+ this.inputHandler = inputHandler;
+ }
+
+ /**
+ * Returns the apps.InputHandler object created during command-line
+ * processing
+ * @return InputHandler object
+ */
+ public InputHandler getInputHandler() {
+ return inputHandler;
+ }
+
/**
* Sets the producer of the document.
* @param producer source of document
*/
public static void main(String[] args) {
CommandLineOptions options = null;
- InputHandler inputHandler = null;
+ FOUserAgent foUserAgent = null;
BufferedOutputStream bos = null;
try {
Driver driver = new Driver();
options = new CommandLineOptions(args);
- driver.setUserAgent(options.getFOUserAgent());
- inputHandler = options.getInputHandler();
+ foUserAgent = options.getFOUserAgent();
+ driver.setUserAgent(foUserAgent);
+ driver.setRenderer(options.getRenderer());
try {
- if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) {
- driver.setRenderer(new AWTRenderer(inputHandler));
- } else {
- driver.setRenderer(options.getRenderer());
-
- if (options.getOutputFile() != null) {
- bos = new BufferedOutputStream(new FileOutputStream(
- options.getOutputFile()));
- driver.setOutputStream(bos);
- }
- }
-
- driver.render(inputHandler);
- } finally {
- if (bos != null) {
- bos.close();
+ if (options.getOutputFile() != null) {
+ bos = new BufferedOutputStream(new FileOutputStream(
+ options.getOutputFile()));
+ driver.setOutputStream(bos);
}
- }
+ driver.render(foUserAgent.getInputHandler());
+ } finally {
+ if (bos != null) {
+ bos.close();
+ }
+ }
// System.exit(0) called to close AWT/SVG-created threads, if any.
// AWTRenderer closes with window shutdown, so exit() should not
* name, value, ...) for XSL stylesheet
* @throws FOPException if initializing the Transformer fails
*/
- public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) throws FOPException {
+ public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) {
this.xmlSource = new StreamSource(xmlfile);
this.xsltSource = new StreamSource(xsltfile);
try {
* @param xmlfile XML file
* @param xsltfile XSLT file
* @throws FOPException if initializing the Transformer fails
- * @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(File xmlfile, File xsltfile) throws FOPException {
+ public XSLTInputHandler(File xmlfile, File xsltfile) {
this.xmlSource = new StreamSource(xmlfile);
this.xsltSource = new StreamSource(xsltfile);
try {
* @param xmlURL XML URL
* @param xsltURL XSLT URL
* @throws FOPException if initializing the Transformer fails
- * @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(String xmlURL, String xsltURL) throws FOPException {
+ public XSLTInputHandler(String xmlURL, String xsltURL) {
this.xmlSource = new StreamSource(xmlURL);
this.xsltSource = new StreamSource(xsltURL);
}
* @param xmlSource XML InputSource
* @param xsltSource XSLT InputSource
* @throws FOPException if initializing the Transformer fails
- * @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource)
- throws FOPException {
+ public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource) {
this.xmlSource = new StreamSource(xmlSource.getByteStream(),
xmlSource.getSystemId());
this.xsltSource = new StreamSource(xsltSource.getByteStream(),
import java.awt.Rectangle;
+// XML
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FOTreeVisitor;
import org.apache.fop.fo.FObj;
-import org.xml.sax.Attributes;
/**
* This is an abstract base class for pagination regions
regionId = id;
}
+ /**
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ * XSL/FOP Content Model: empty
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
+ invalidChildError(loc, nsURI, localName);
+ }
+
/**
* @see org.apache.fop.fo.FObj#addProperties
*/
// XML
import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
// FOP
import org.apache.fop.datatypes.ColorType;
super(parent, Region.BODY_CODE);
}
- /**
- * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
- * XSL/FOP Content Model: empty
- */
- protected void validateChildNode(Locator loc, String nsURI, String localName) {
- invalidChildError(loc, nsURI, localName);
- }
-
/**
* @see org.apache.fop.fo.pagination.Region#getViewportRectangle(FODimension)
*/
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.InputHandler;
import org.apache.fop.area.Area;
import org.apache.fop.area.Page;
/** Font configuration */
protected FontInfo fontInfo;
- /**
- The InputHandler associated with this Renderer.
- Sent to the PreviewDialog for document reloading.
- */
- private InputHandler inputHandler;
-
/**
* The resource bundle used for AWT messages.
*/
*/
protected PreviewDialog frame;
- public AWTRenderer(InputHandler handler) {
- inputHandler = handler;
+ public AWTRenderer() {
translator = new Translator();
- createPreviewDialog(inputHandler);
}
- public AWTRenderer() {
- translator = new Translator();
- createPreviewDialog(null);
+ public void setUserAgent(FOUserAgent foUserAgent) {
+ super.setUserAgent(foUserAgent);
+ createPreviewDialog(foUserAgent.getInputHandler());
}
/**
import org.apache.commons.logging.Log;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.XSLTInputHandler;
-import org.apache.fop.render.awt.AWTPrintRenderer;
import org.xml.sax.InputSource;
/**
HttpServletResponse response) throws ServletException {
try {
Driver driver = new Driver(foFile, null);
- AWTPrintRenderer renderer = new AWTPrintRenderer();
-
- driver.setRenderer(renderer);
+ driver.setRenderer(Driver.RENDER_PRINT);
driver.run();
reportOK (response);
HttpServletResponse response) throws ServletException {
try {
Driver driver = new Driver();
- AWTPrintRenderer renderer = new AWTPrintRenderer();
-
- driver.setRenderer(renderer);
+ driver.setRenderer(Driver.RENDER_PRINT);
driver.render(input.getParser(), input.getInputSource());
reportOK (response);
import org.xml.sax.InputSource;
-import org.apache.commons.logging.impl.NoOpLog;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.InputHandler;
*/
public class BasicDriverTestCase extends AbstractFOPTestCase {
- private NoOpLog logger = new NoOpLog();
-
/**
* @see junit.framework.TestCase#TestCase(String)
*/
new InputSource(foFile.toURL().toExternalForm()),
baout);
- driver.setLogger(this.logger);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
assertTrue("Generated PDF has zero length", baout.size() > 0);
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setInputSource(new InputSource(foFile.toURL().toExternalForm()));
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_PDF);
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_PDF);
driver.render(loadDocument(foFile));
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_PDF);
SAXParserFactory factory = SAXParserFactory.newInstance();
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_PDF);
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_PS);
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_RTF);
File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
Driver driver = new Driver();
- driver.setLogger(this.logger);
driver.setOutputStream(baout);
driver.setRenderer(Driver.RENDER_PDF);
import junit.framework.TestSuite;
import org.apache.fop.apps.Driver;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.pdf.PDFRenderer;
import org.apache.fop.util.DigestFilter;
import org.xml.sax.InputSource;
private void renderPDF(String fo, String digestIn, String digestOut)
throws Exception {
PDFRenderer renderer = new PDFRenderer();
- renderer.setCreationDate(new Date(10000));
+ FOUserAgent foUserAgent = new FOUserAgent();
+ foUserAgent.setCreationDate(new Date(10000));
+ renderer.setUserAgent(foUserAgent);
MessageDigest outDigest = MessageDigest.getInstance("MD5");
ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
DigestOutputStream out =