|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.writersforge.catalan.GenericGenerator
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 LineTo 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 InterfaceThe 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.
| 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 |
public GenericGenerator()
| Method Detail |
public void setRenderer(Renderer renderer)
renderer - the Renderer to use for outputpublic void setFormat(java.lang.String format)
format - the rendering formatpublic void setTemplateFile(java.lang.String templateFile)
templateFile - a path to the template filepublic void setInputFiles(java.lang.String[] inputFiles)
inputFiles - an array of input file pathspublic void setOutputFile(java.lang.String outputFile)
outputFile - the output file pathpublic void parseArgs(java.lang.String[] args)
args - an array of command-line arguments, e.g., from main()
public void run()
throws java.io.IOException
java.io.IOException - if an error occurs while reading or writing filespublic static void main(java.lang.String[] args)
args - the command line arguments
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||