org.writersforge.catalan
Class GenericGenerator

java.lang.Object
  extended byorg.writersforge.catalan.GenericGenerator

public class GenericGenerator
extends java.lang.Object

Content generator for creating PDFs, HTML, and ASCII text files from arbitrary XML data formats, using a layout-template XML file to filter and position the data in the output medium. Uses the BellowsLoader and GenericTemplate classes to handle the loading and layout. The Renderer must be set before invoking the rendering process.

The Catalan engine is a complex collection of components, perhaps even more complex because of its flexibility and extensibility. To simplify the rendering process, Catalan offers an easy to use front end for generating documents with generic XML templates: the GenericGenerator class. GenericGenerator can be used from the command line, or embedded into existing applications. Thus, adding PDF support to your application is as simple as writing an XML template, exporting your data as XML (or raw Datum), and invoking the GenericGenerator class.

The Command Line

To run the rendering engine through the command line, invoke the org.writersforge.render.GenericGenerator class using parameters to pass in the pertinent files:

  -t  the XML template file
  -i  an XML input data file (optional)
  -o  the output file
  -f  the output format, can be "PDF" or "TEXT"

If the template has all static content, you can omit the -i option; conversely, you may load more than one input data file by declaring multiple -i parameters. Here is an example that creates an output.pdf file using the template.xml generic template file and two input data files, data1.xml and data2.xml:

  java -classpath $LIBS org.writersforge.render.GenericGenerator \
    -t template.xml -i data1.xml -i data2.xml -o output.pdf -f PDF

The LIBS environment variable should contain the Catalan jar file, the Jakarta ORO jar file (for regular expression parsing), and an XML SAX parser like Nano-XML.

The Application Interface

The command line interface provides easy access to the rendering engine at the filesystem level, but often you will want tighter integration with an existing application. Or perhaps you want to use a custom Renderer. GenericGenerator exports an interface you can use from any Java application.

The first step is to create an instance of the generator:

  GenericGenerator generator = new GenericGenerator ();

Next, you must assign the input, output, and template files. The following code mirrors the example in the previous section:

  String[] input = new String[] { "data1.xml", "data2.xml" };
  generator.setInputFiles (input);
  generator.setOutputFile ("output.pdf");
  generator.setTemplateFile ("template.xml");

If you're content to use one of the standard Renderer classes, you can assign it with setFormat():

  generator.setFormat ("PDF");

If you need a custom renderer, you can use the setRenderer() method instead. Simply instantiate your Renderer and pass it in:

  CustomRenderer renderer = new CustomRenderer("output.cst");
  generator.setRenderer (renderer);

Finally, when you've set up the rendering environment, you can call the run() method to execute the rendering:

  generator.run ();

And that's it. You can re-use the generator instance for other files. Just call the parameter methods with the new settings and invoke run() again.

Author:
jsheets

Constructor Summary
GenericGenerator()
           
 
Method Summary
static void main(java.lang.String[] args)
          Invokes the rendering process using the generic XML processing tools.
 void parseArgs(java.lang.String[] args)
          Parses and processes the command-line arguments.
 void run()
          Fires off the document generator, given the current input and output file settings and output format.
 void setFormat(java.lang.String format)
          Sets the rendering format: "PDF", "TEXT", or "HTML".
 void setInputFiles(java.lang.String[] inputFiles)
          Sets the array of input file paths.
 void setOutputFile(java.lang.String outputFile)
          Sets the output file path.
 void setRenderer(Renderer renderer)
          Assigns the Renderer to use for creating the final output.
 void setTemplateFile(java.lang.String templateFile)
          Sets the file path for the template file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericGenerator

public GenericGenerator()
Method Detail

setRenderer

public void setRenderer(Renderer renderer)
Assigns the Renderer to use for creating the final output. There is no default renderer, so this method must be called.

Parameters:
renderer - the Renderer to use for output

setFormat

public void setFormat(java.lang.String format)
Sets the rendering format: "PDF", "TEXT", or "HTML".

Parameters:
format - the rendering format

setTemplateFile

public void setTemplateFile(java.lang.String templateFile)
Sets the file path for the template file.

Parameters:
templateFile - a path to the template file

setInputFiles

public void setInputFiles(java.lang.String[] inputFiles)
Sets the array of input file paths.

Parameters:
inputFiles - an array of input file paths

setOutputFile

public void setOutputFile(java.lang.String outputFile)
Sets the output file path.

Parameters:
outputFile - the output file path

parseArgs

public void parseArgs(java.lang.String[] args)
Parses and processes the command-line arguments.

Parameters:
args - an array of command-line arguments, e.g., from main()

run

public void run()
         throws java.io.IOException
Fires off the document generator, given the current input and output file settings and output format.

Throws:
java.io.IOException - if an error occurs while reading or writing files

main

public static void main(java.lang.String[] args)
Invokes the rendering process using the generic XML processing tools.

Parameters:
args - the command line arguments