org.apache.velocity.texen

Class Generator


public class Generator
extends java.lang.Object

A text/code generator class

Version:
$Id: Generator.java,v 1.20.4.1 2004/03/03 23:23:07 geirm Exp $

Authors:
Leon Messerschmidt
Jason van Zyl

Field Summary

private static String
DEFAULT_TEXEN_PROPERTIES
Default properties file used for controlling the tools placed in the context.
static String
OUTPUT_PATH
Where the texen output will placed.
static String
TEMPLATE_PATH
Where the velocity templates live.
private Context
controlContext
Context used for generating the texen output.
protected String
inputEncoding
This is the encoding for the input file(s) (templates).
private static Generator
instance
The generator tools used for creating additional output withing the control template.
protected String
outputEncoding
This is the encoding for the output file(s).
private Properties
props
Default properties used by texen.
protected VelocityEngine
ve
Velocity engine.
private Hashtable
writers
Keep track of the file writers used for outputting to files.

Constructor Summary

Generator()
Default constructor.
Generator(Properties props)
Create a new Generator object with a given property set.
Generator(String propFile)
Create a new generator object with properties loaded from a file.

Method Summary

protected void
fillContextDefaults(Context context)
Add properties that will aways be in the context by default
protected void
fillContextHash(Context context, Hashtable objs)
Add all the contents of a Hashtable to the context.
protected void
fillContextProperties(Context context)
Add objects to the context from the current properties.
protected Context
getContext(Hashtable objs)
Create a new context and fill it with the elements of the objs Hashtable.
static Generator
getInstance()
Create a new generator object with default properties.
String
getOutputPath()
Get the output path for the generated output.
Template
getTemplate(String templateName, String encoding)
Returns a template, based on encoding and path.
String
getTemplatePath()
Get the template path.
Writer
getWriter(String path, String encoding)
Returns a writer, based on encoding and path.
String
parse(String inputTemplate, String outputFile)
Parse an input and write the output to an output file.
String
parse(String inputTemplate, String outputFile, String objectID, Object object)
Parse an input and write the output to an output file.
String
parse(String inputTemplate, String intputEncoding, String outputFile, String outputEncoding, String objectID, Object object)
Parse an input and write the output to an output file.
String
parse(String controlTemplate, Context controlContext)
Parse the control template and merge it with the control context.
protected void
setDefaultProps()
Set default properties.
void
setInputEncoding(String inputEncoding)
Set the input (template) encoding.
void
setOutputEncoding(String outputEncoding)
Set the output encoding.
void
setOutputPath(String outputPath)
Set the output path for the generated output.
void
setTemplatePath(String templatePath)
Set the template path, where Texen will look for Velocity templates.
void
setVelocityEngine(VelocityEngine ve)
Set the velocity engine.
void
shutdown()
Properly shut down the generator, right now this is simply flushing and closing the file writers that we have been holding on to.

Field Details

DEFAULT_TEXEN_PROPERTIES

private static final String DEFAULT_TEXEN_PROPERTIES
Default properties file used for controlling the tools placed in the context.


OUTPUT_PATH

public static final String OUTPUT_PATH
Where the texen output will placed.


TEMPLATE_PATH

public static final String TEMPLATE_PATH
Where the velocity templates live.


controlContext

private Context controlContext
Context used for generating the texen output.


inputEncoding

protected String inputEncoding
This is the encoding for the input file(s) (templates).


instance

private static Generator instance
The generator tools used for creating additional output withing the control template. This could use some cleaning up.


outputEncoding

protected String outputEncoding
This is the encoding for the output file(s).


props

private Properties props
Default properties used by texen.


ve

protected VelocityEngine ve
Velocity engine.


writers

private Hashtable writers
Keep track of the file writers used for outputting to files. If we come across a file writer more then once then the additional output will be appended to the file instead of overwritting the contents.

Constructor Details

Generator

private Generator()
Default constructor.


Generator

public Generator(Properties props)
Create a new Generator object with a given property set. The property set will be duplicated.

Parameters:


Generator

public Generator(String propFile)
Create a new generator object with properties loaded from a file. If the file does not exist or any other exception occurs during the reading operation the default properties are used.

Parameters:

Method Details

fillContextDefaults

protected void fillContextDefaults(Context context)
Add properties that will aways be in the context by default

Parameters:


fillContextHash

protected void fillContextHash(Context context,
                               Hashtable objs)
Add all the contents of a Hashtable to the context.

Parameters:


fillContextProperties

protected void fillContextProperties(Context context)
Add objects to the context from the current properties.

Parameters:


getContext

protected Context getContext(Hashtable objs)
Create a new context and fill it with the elements of the objs Hashtable. Default objects and objects that comes from the properties of this Generator object is also added.

Parameters:

Returns:
Context context filled with objects


getInstance

public static Generator getInstance()
Create a new generator object with default properties.

Returns:
Generator generator used in the control context.


getOutputPath

public String getOutputPath()
Get the output path for the generated output.

Returns:
String output path for texen output.


getTemplate

public Template getTemplate(String templateName,
                            String encoding)
            throws Exception
Returns a template, based on encoding and path.

Parameters:
templateName - name of the template
encoding - template encoding


getTemplatePath

public String getTemplatePath()
Get the template path.

Returns:
String template path for velocity templates.


getWriter

public Writer getWriter(String path,
                        String encoding)
            throws Exception
Returns a writer, based on encoding and path.

Parameters:
path - path to the output file
encoding - output encoding


parse

public String parse(String inputTemplate,
                    String outputFile)
            throws Exception
Parse an input and write the output to an output file. If the output file parameter is null or an empty string the result is returned as a string object. Otherwise an empty string is returned.

Parameters:


parse

public String parse(String inputTemplate,
                    String outputFile,
                    String objectID,
                    Object object)
            throws Exception
Parse an input and write the output to an output file. If the output file parameter is null or an empty string the result is returned as a string object. Otherwise an empty string is returned. You can add objects to the context with the objs Hashtable.

Parameters:

Returns:
String generated output from velocity


parse

public String parse(String inputTemplate,
                    String intputEncoding,
                    String outputFile,
                    String outputEncoding,
                    String objectID,
                    Object object)
            throws Exception
Parse an input and write the output to an output file. If the output file parameter is null or an empty string the result is returned as a string object. Otherwise an empty string is returned. You can add objects to the context with the objs Hashtable.

Parameters:

Returns:
String generated output from velocity


parse

public String parse(String controlTemplate,
                    Context controlContext)
            throws Exception
Parse the control template and merge it with the control context. This is the starting point in texen.

Parameters:

Returns:
String generated output


setDefaultProps

protected void setDefaultProps()
Set default properties.


setInputEncoding

public void setInputEncoding(String inputEncoding)
Set the input (template) encoding.


setOutputEncoding

public void setOutputEncoding(String outputEncoding)
Set the output encoding.


setOutputPath

public void setOutputPath(String outputPath)
Set the output path for the generated output.


setTemplatePath

public void setTemplatePath(String templatePath)
Set the template path, where Texen will look for Velocity templates.

Parameters:


setVelocityEngine

public void setVelocityEngine(VelocityEngine ve)
Set the velocity engine.


shutdown

public void shutdown()
Properly shut down the generator, right now this is simply flushing and closing the file writers that we have been holding on to.


Copyright B) 2002 Apache Software Foundation. All Rights Reserved.