fi.hut.tml.xsmiles.mlfc.xslfo.apps
Class Driver2

java.lang.Object
  extended byfi.hut.tml.xsmiles.mlfc.xslfo.apps.Driver2

public class Driver2
extends java.lang.Object

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_TXT
          Render to Text.
static int RENDER_XML
          Render to XML.
 
Constructor Summary
Driver2()
          create a new Driver
Driver2(org.xml.sax.InputSource source, java.io.OutputStream stream)
           
 
Method Summary
 void addElementMapping(org.apache.fop.fo.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()
           
 org.apache.fop.render.Renderer getRenderer()
           
 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 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(org.apache.fop.render.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

See Also:
Constant Field Values

RENDER_AWT

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

See Also:
Constant Field Values

RENDER_MIF

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

See Also:
Constant Field Values

RENDER_XML

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

See Also:
Constant Field Values

RENDER_PRINT

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

See Also:
Constant Field Values

RENDER_PCL

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

See Also:
Constant Field Values

RENDER_PS

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

See Also:
Constant Field Values

RENDER_TXT

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

See Also:
Constant Field Values
Constructor Detail

Driver2

public Driver2()
create a new Driver


Driver2

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

getParserClassName

public static final java.lang.String getParserClassName()

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.


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
Throws:
java.lang.IllegalArgumentException

setRenderer

public void setRenderer(org.apache.fop.render.Renderer renderer)
Set the Renderer to use

Parameters:
renderer - the renderer instance to use

getRenderer

public org.apache.fop.render.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(org.apache.fop.fo.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

Throws:
java.lang.IllegalArgumentException

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 org.apache.fop.apps.FOPException
Build the formatting object tree using the given SAX Parser and SAX InputSource

Throws:
org.apache.fop.apps.FOPException

render

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

Throws:
org.apache.fop.apps.FOPException

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,
                org.apache.fop.apps.FOPException
Runs the formatting and renderering process using the previously set inputsource and outputstream

Throws:
java.io.IOException
org.apache.fop.apps.FOPException


X-Smiles 1.2