org.apache.fop.apps
Class Driver

java.lang.Object
  |
  +--org.apache.fop.apps.Driver
All Implemented Interfaces:
org.apache.avalon.framework.logger.Loggable

public class Driver
extends java.lang.Object
implements org.apache.avalon.framework.logger.Loggable

Primary class that drives overall FOP process.

The simplest way to use this is to instantiate it with the InputSource and OutputStream, then set the renderer desired, and calling run();

Here is an example use of Driver which outputs PDF:

 Driver driver = new Driver(new InputSource (args[0]),
 new FileOutputStream(args[1]));
 driver.setRenderer(RENDER_PDF);
 driver.run();
 
If neccessary, calling classes can call into the lower level methods to setup and render. Methods can be called to set the Renderer to use, the (possibly multiple) ElementMapping(s) to use and the OutputStream to use to output the results of the rendering (where applicable). In the case of the Renderer and ElementMapping(s), the Driver may be supplied either with the object itself, or the name of the class, in which case Driver will instantiate the class itself. The advantage of the latter is it enables runtime determination of Renderer and ElementMapping(s).

Once the Driver is set up, the render method is called. Depending on whether DOM or SAX is being used, the invocation of the method is either render(Document) or buildFOTree(Parser, InputSource) respectively.

A third possibility may be used to build the FO Tree, namely calling getContentHandler() and firing the SAX events yourself.

Once the FO Tree is built, the format() and render() methods may be called in that order.

Here is an example use of Driver which outputs to AWT:

 Driver driver = new Driver();
 driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
 driver.render(parser, fileInputSource(args[0]));
 


Field Summary
static int RENDER_AWT
          Render to a GUI window.
static int RENDER_MIF
          Render to MIF.
static int RENDER_PCL
          Render to PCL.
static int RENDER_PDF
          Render to PDF.
static int RENDER_PRINT
          Render to PRINT.
static int RENDER_PS
          Render to Postscript.
static int RENDER_SVG
          Render to SVG.
static int RENDER_TXT
          Render to Text.
static int RENDER_XML
          Render to XML.
 
Constructor Summary
Driver()
          create a new Driver
Driver(org.xml.sax.InputSource source, java.io.OutputStream stream)
           
 
Method Summary
 void addElementMapping(ElementMapping mapping)
          Add the given element mapping.
 void addElementMapping(java.lang.String mappingClassName)
          add the element mapping with the given class name
 void dumpError(java.lang.Exception e)
          Dumps an error
 org.xml.sax.ContentHandler getContentHandler()
          Returns the tree builder (a SAX ContentHandler).
static java.lang.String getParserClassName()
           
 Renderer getRenderer()
           
 FormattingResults getResults()
          Returns the results of the last rendering process.
 boolean hasData()
           
 void render(org.w3c.dom.Document document)
          Build the formatting object tree using the given DOM Document
 void render(org.xml.sax.XMLReader parser, org.xml.sax.InputSource source)
          Build the formatting object tree using the given SAX Parser and SAX InputSource
 void reset()
          Resets the Driver so it can be reused.
 void run()
          Runs the formatting and renderering process using the previously set inputsource and outputstream
 void setBufferFile(java.io.File bufferFile)
           
 void setErrorDump(boolean dump)
          Set the error dump option
 void setInputSource(org.xml.sax.InputSource source)
          Set the source for the FO document.
 void setLogger(org.apache.log.Logger logger)
           
 void setOutputStream(java.io.OutputStream stream)
          Set the OutputStream to use to output the result of the Renderer (if applicable)
 void setRenderer(int renderer)
          Set the rendering type to use.
 void setRenderer(Renderer renderer)
          Set the Renderer to use
 void setRenderer(java.lang.String rendererClassName)
          Set the class name of the Renderer to use as well as the producer string for those renderers that can make use of it.
 void setRenderer(java.lang.String rendererClassName, java.lang.String version)
          Deprecated. use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) which will use the default producer string.
 void setupDefaultMappings()
          Sets all the element and property list mappings to their default values.
 void setXMLReader(org.xml.sax.XMLReader reader)
          Sets the reader used when reading in the source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RENDER_PDF

public static final int RENDER_PDF
Render to PDF. OutputStream must be set

RENDER_AWT

public static final int RENDER_AWT
Render to a GUI window. No OutputStream neccessary

RENDER_MIF

public static final int RENDER_MIF
Render to MIF. OutputStream must be set

RENDER_XML

public static final int RENDER_XML
Render to XML. OutputStream must be set

RENDER_PRINT

public static final int RENDER_PRINT
Render to PRINT. No OutputStream neccessary

RENDER_PCL

public static final int RENDER_PCL
Render to PCL. OutputStream must be set

RENDER_PS

public static final int RENDER_PS
Render to Postscript. OutputStream must be set

RENDER_TXT

public static final int RENDER_TXT
Render to Text. OutputStream must be set

RENDER_SVG

public static final int RENDER_SVG
Render to SVG. OutputStream must be set
Constructor Detail

Driver

public Driver()
create a new Driver

Driver

public Driver(org.xml.sax.InputSource source,
              java.io.OutputStream stream)
Method Detail

getParserClassName

public static final java.lang.String getParserClassName()

setLogger

public void setLogger(org.apache.log.Logger logger)
Specified by:
setLogger in interface org.apache.avalon.framework.logger.Loggable

reset

public void reset()
Resets the Driver so it can be reused. Property and element mappings are reset to defaults. The output stream is cleared. The renderer is cleared.

getResults

public FormattingResults getResults()
Returns the results of the last rendering process. Information includes the total number of pages generated and the number of pages per page-sequence.

hasData

public boolean hasData()

setErrorDump

public void setErrorDump(boolean dump)
Set the error dump option
Parameters:
dump - if true, full stacks will be reported to the error log

setOutputStream

public void setOutputStream(java.io.OutputStream stream)
Set the OutputStream to use to output the result of the Renderer (if applicable)
Parameters:
stream - the stream to output the result of rendering to

setInputSource

public void setInputSource(org.xml.sax.InputSource source)
Set the source for the FO document. This can be a normal SAX InputSource, or an DocumentInputSource containing a DOM document.
See Also:
DocumentInputSource

setXMLReader

public void setXMLReader(org.xml.sax.XMLReader reader)
Sets the reader used when reading in the source. If not set, this defaults to a basic SAX parser.

setupDefaultMappings

public void setupDefaultMappings()
Sets all the element and property list mappings to their default values.

setRenderer

public void setRenderer(int renderer)
                 throws java.lang.IllegalArgumentException
Set the rendering type to use. Must be one of
Parameters:
renderer - the type of renderer to use

setRenderer

public void setRenderer(Renderer renderer)
Set the Renderer to use
Parameters:
renderer - the renderer instance to use

getRenderer

public Renderer getRenderer()

setRenderer

public void setRenderer(java.lang.String rendererClassName,
                        java.lang.String version)
Deprecated. use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) which will use the default producer string.

See Also:
setRenderer(int), setRenderer(Renderer)

setRenderer

public void setRenderer(java.lang.String rendererClassName)
                 throws java.lang.IllegalArgumentException
Set the class name of the Renderer to use as well as the producer string for those renderers that can make use of it.
Parameters:
rendererClassName - classname of the renderer to use such as "org.apache.fop.render.pdf.PDFRenderer"
Throws:
java.lang.IllegalArgumentException - if the classname was invalid.
See Also:
setRenderer(int)

addElementMapping

public void addElementMapping(ElementMapping mapping)
Add the given element mapping. An element mapping maps element names to Java classes.
Parameters:
mapping - the element mappingto add

addElementMapping

public void addElementMapping(java.lang.String mappingClassName)
                       throws java.lang.IllegalArgumentException
add the element mapping with the given class name

getContentHandler

public org.xml.sax.ContentHandler getContentHandler()
Returns the tree builder (a SAX ContentHandler). Used in situations where SAX is used but not via a FOP-invoked SAX parser. A good example is an XSLT engine that fires SAX events but isn't a SAX Parser itself.

render

public void render(org.xml.sax.XMLReader parser,
                   org.xml.sax.InputSource source)
            throws FOPException
Build the formatting object tree using the given SAX Parser and SAX InputSource

render

public void render(org.w3c.dom.Document document)
            throws FOPException
Build the formatting object tree using the given DOM Document

dumpError

public void dumpError(java.lang.Exception e)
Dumps an error

setBufferFile

public void setBufferFile(java.io.File bufferFile)

run

public void run()
         throws java.io.IOException,
                FOPException
Runs the formatting and renderering process using the previously set inputsource and outputstream


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.