Save This Page
Home » fop-0.95beta-src » org.apache » fop » apps » [javadoc | source]
org.apache.fop.apps
public class: Driver [javadoc | source]
java.lang.Object
   org.apache.fop.apps.Driver
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 render(Parser, InputSource) respectively.

A third possibility is to call getContentHandler() and firing the SAX events yourself.

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
public static final  int RENDER_PDF    Render to PDF. OutputStream must be set 
public static final  int RENDER_AWT    Render to a GUI window. No OutputStream neccessary 
public static final  int RENDER_MIF    Render to MIF. OutputStream must be set 
public static final  int RENDER_XML    Render to XML. OutputStream must be set 
public static final  int RENDER_PRINT    Render to PRINT. No OutputStream neccessary 
public static final  int RENDER_PCL    Render to PCL. OutputStream must be set 
public static final  int RENDER_PS    Render to Postscript. OutputStream must be set 
public static final  int RENDER_TXT    Render to Text. OutputStream must be set 
public static final  int RENDER_SVG    Render to SVG. OutputStream must be set 
Constructor:
 public Driver() 
 public Driver(InputSource source,
    OutputStream stream) 
Method from org.apache.fop.apps.Driver Summary:
addElementMapping,   addElementMapping,   dumpError,   getContentHandler,   getParserClassName,   getRenderer,   getResults,   hasData,   render,   render,   reset,   run,   setErrorDump,   setInputSource,   setLogger,   setOutputStream,   setRenderer,   setRenderer,   setRenderer,   setRenderer,   setXMLReader,   setupDefaultMappings
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.fop.apps.Driver Detail:
 public  void addElementMapping(ElementMapping mapping) 
    Add the given element mapping. An element mapping maps element names to Java classes.
 public  void addElementMapping(String mappingClassName) throws IllegalArgumentException 
    add the element mapping with the given class name
 public  void dumpError(Exception e) 
    Dumps an error
 public 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.
 public static final String getParserClassName() 
 public Renderer getRenderer() 
 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.
 public boolean hasData() 
 public synchronized  void render(Document document) throws FOPException 
    Build the formatting object tree using the given DOM Document
 public synchronized  void render(XMLReader parser,
    InputSource source) throws FOPException 
    Build the formatting object tree using the given SAX Parser and SAX InputSource
 public synchronized  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.
 public synchronized  void run() throws IOException, FOPException 
    Runs the formatting and renderering process using the previously set inputsource and outputstream
 public  void setErrorDump(boolean dump) 
    Set the error dump option
 public  void setInputSource(InputSource source) 
    Set the source for the FO document. This can be a normal SAX InputSource, or an DocumentInputSource containing a DOM document.
 public  void setLogger(Logger logger) 
 public  void setOutputStream(OutputStream stream) 
    Set the OutputStream to use to output the result of the Renderer (if applicable)
 public  void setRenderer(int renderer) throws IllegalArgumentException 
    Set the rendering type to use. Must be one of
    • RENDER_PDF
    • RENDER_AWT
    • RENDER_MIF
    • RENDER_XML
    • RENDER_PCL
    • RENDER_PS
    • RENDER_TXT
    • RENDER_SVG
 public  void setRenderer(Renderer renderer) 
    Set the Renderer to use
 public  void setRenderer(String rendererClassName) throws 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.
 public  void setRenderer(String rendererClassName,
    String version) 
Deprecated! use - renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) which will use the default producer string.

 public  void setXMLReader(XMLReader reader) 
    Sets the reader used when reading in the source. If not set, this defaults to a basic SAX parser.
 public  void setupDefaultMappings() 
    Sets all the element and property list mappings to their default values.