org.apache.velocity.texen

Class Generator

public class Generator extends Object

A text/code generator class

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

Author: Leon Messerschmidt Jason van Zyl

Field Summary
ContextcontrolContext
Context used for generating the texen output.
static StringDEFAULT_TEXEN_PROPERTIES
Default properties file used for controlling the tools placed in the context.
protected StringinputEncoding
This is the encoding for the input file(s) (templates).
static Generatorinstance
The generator tools used for creating additional output withing the control template.
protected StringoutputEncoding
This is the encoding for the output file(s).
static StringOUTPUT_PATH
Where the texen output will placed.
Propertiesprops
Default properties used by texen.
static StringTEMPLATE_PATH
Where the velocity templates live.
protected VelocityEngineve
Velocity engine.
Hashtablewriters
Keep track of the file writers used for outputting to files.
Constructor Summary
Generator()
Default constructor.
Generator(String propFile)
Create a new generator object with properties loaded from a file.
Generator(Properties props)
Create a new Generator object with a given property set.
Method Summary
protected voidfillContextDefaults(Context context)
Add properties that will aways be in the context by default
protected voidfillContextHash(Context context, Hashtable objs)
Add all the contents of a Hashtable to the context.
protected voidfillContextProperties(Context context)
Add objects to the context from the current properties.
protected ContextgetContext(Hashtable objs)
Create a new context and fill it with the elements of the objs Hashtable.
static GeneratorgetInstance()
Create a new generator object with default properties.
StringgetOutputPath()
Get the output path for the generated output.
TemplategetTemplate(String templateName, String encoding)
Returns a template, based on encoding and path.
StringgetTemplatePath()
Get the template path.
WritergetWriter(String path, String encoding)
Returns a writer, based on encoding and path.
Stringparse(String inputTemplate, String outputFile)
Parse an input and write the output to an output file.
Stringparse(String inputTemplate, String outputFile, String objectID, Object object)
Parse an input and write the output to an output file.
Stringparse(String inputTemplate, String intputEncoding, String outputFile, String outputEncoding, String objectID, Object object)
Parse an input and write the output to an output file.
Stringparse(String controlTemplate, Context controlContext)
Parse the control template and merge it with the control context.
protected voidsetDefaultProps()
Set default properties.
voidsetInputEncoding(String inputEncoding)
Set the input (template) encoding.
voidsetOutputEncoding(String outputEncoding)
Set the output encoding.
voidsetOutputPath(String outputPath)
Set the output path for the generated output.
voidsetTemplatePath(String templatePath)
Set the template path, where Texen will look for Velocity templates.
voidsetVelocityEngine(VelocityEngine ve)
Set the velocity engine.
voidshutdown()
Properly shut down the generator, right now this is simply flushing and closing the file writers that we have been holding on to.

Field Detail

controlContext

private Context controlContext
Context used for generating the texen output.

DEFAULT_TEXEN_PROPERTIES

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

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).

OUTPUT_PATH

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

props

private Properties props
Default properties used by texen.

TEMPLATE_PATH

public static final String TEMPLATE_PATH
Where the velocity templates live.

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 Detail

Generator

private Generator()
Default constructor.

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: String properties used to help populate the control context.

Returns: Generator generator used in the control context.

Generator

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

Parameters: Properties properties object to help populate the control context.

Method Detail

fillContextDefaults

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

Parameters: Context control context to fill with default values.

fillContextHash

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

Parameters: Context context to fill with objects Hashtable source of objects

fillContextProperties

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

Parameters: Context control context to fill with objects that are specified in the default.properties file

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: Hashtable objects to place in the control context

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)
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)
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)
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: String input template String output file

parse

public String parse(String inputTemplate, String outputFile, String objectID, Object object)
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: String input template String output file String id for object to be placed in the control context String object to be placed in the context

Returns: String generated output from velocity

parse

public 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. 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: String input template String inputEncoding template encoding String output file String outputEncoding encoding of output file String id for object to be placed in the control context String object to be placed in the context

Returns: String generated output from velocity

parse

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

Parameters: String control template Context control context

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.

Returns: String output path for texen output.

setTemplatePath

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

Parameters: String template path for velocity templates.

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.