org.apache.fop.apps
Class Driver


public class Driver

Primary class that drives overall FOP process.

Once this class is instantiated, methods are called to set the Renderer to use, the (possibly multiple) ElementMapping(s) to use and the PrintWriter 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 buildFOTree method is called. Depending on whether DOM or SAX is being used, the invocation of the method is either buildFOTree(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 from CommandLine.java:

Driver driver = new Driver();
driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version);
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
driver.setOutputStream(new FileOutputStream(args[1]));
driver.buildFOTree(parser, fileInputSource(args[0]));
driver.format();
driver.render();

Constructor Summary
Driver()
          create a new Driver

Method Summary
 voidaddElementMapping(ElementMapping mapping)
          add the given element mapping.
 voidaddElementMapping(String mappingClassName)
          add the element mapping with the given class name
 voidaddPropertyList(String listClassName)
          add the element mapping with the given class name
 voidbuildFOTree(XMLReader parser, InputSource source)
          build the formatting object tree using the given SAX Parser and SAX InputSource
 voidbuildFOTree(Document document)
          build the formatting object tree using the given DOM Document
 voiddumpError(Exception e)
          Dumps an error
 voidformat()
          format the formatting object tree into an area tree
 ContentHandlergetContentHandler()
          return the tree builder (a SAX ContentHandler).
 voidloadStandardConfiguration()
          loads standard configuration file and a user file, if it has been specified
 voidloadUserconfiguration(String userConfigFile)
           
 voidrender()
          render the area tree to the output form
 voidsetBaseDir(String fofile)
           
 voidsetErrorDump(boolean dump)
          Set the error dump option
 voidsetOutputStream(OutputStream stream)
          set the OutputStream to use to output the result of the Renderer (if applicable)
 voidsetRenderer(Renderer renderer)
          set the Renderer to use
 voidsetRenderer(String rendererClassName, String producer)
          set the class name of the Renderer to use as well as the producer string for those renderers that can make use of it

Constructor Detail

Driver

public Driver()
create a new Driver
Method Detail

addElementMapping

public void addElementMapping(ElementMapping mapping)
add the given element mapping. an element mapping maps element names to Java classes

addElementMapping

public void addElementMapping(String mappingClassName)
add the element mapping with the given class name

addPropertyList

public void addPropertyList(String listClassName)
add the element mapping with the given class name

buildFOTree

public void buildFOTree(XMLReader parser, InputSource source)
throws FOPException
build the formatting object tree using the given SAX Parser and SAX InputSource

buildFOTree

public void buildFOTree(Document document)
throws FOPException
build the formatting object tree using the given DOM Document

dumpError

public void dumpError(Exception e)
Dumps an error

format

public void format()
throws FOPException
format the formatting object tree into an area tree

getContentHandler

public ContentHandler getContentHandler()
return 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.

loadStandardConfiguration

public void loadStandardConfiguration()
loads standard configuration file and a user file, if it has been specified

loadUserconfiguration

public void loadUserconfiguration(String userConfigFile)

render

public void render()
throws java.io.IOException,
FOPException
render the area tree to the output form

setBaseDir

public void setBaseDir(String fofile)

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(OutputStream stream)
set the OutputStream to use to output the result of the Renderer (if applicable)

setRenderer

public void setRenderer(Renderer renderer)
set the Renderer to use

setRenderer

public void setRenderer(String rendererClassName, String producer)
set the class name of the Renderer to use as well as the producer string for those renderers that can make use of it

Association Links

to Class org.apache.fop.fo.FOTreeBuilder

the FO tree builder

to Class org.apache.fop.layout.AreaTree

the area tree that is the result of formatting the FO tree

to Class org.apache.fop.render.Renderer

the renderer to use to output the area tree

to Class java.io.OutputStream

the stream to use to output the results of the renderer