org.apache.velocity.texen
Class Generator

java.lang.Object
  extended by org.apache.velocity.texen.Generator

public class Generator
extends Object

A text/code generator class

Version:
$Id: Generator.java 463298 2006-10-12 16:10:32Z henning $
Author:
Leon Messerschmidt, Jason van Zyl

Field Summary
protected  String inputEncoding
          This is the encoding for the input file(s) (templates).
static String OUTPUT_PATH
          Where the texen output will placed.
protected  String outputEncoding
          This is the encoding for the output file(s).
static String TEMPLATE_PATH
          Where the velocity templates live.
protected  VelocityEngine ve
          Velocity engine.
 
Constructor Summary
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 controlTemplate, Context controlContext)
          Parse the control template and merge it with the control context.
 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 inputEncoding, String outputFile, String outputEncoding, String objectID, Object object)
          Parse an input and write the output to an output file.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_PATH

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

See Also:
Constant Field Values

TEMPLATE_PATH

public static final String TEMPLATE_PATH
Where the velocity templates live.

See Also:
Constant Field Values

outputEncoding

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


inputEncoding

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


ve

protected VelocityEngine ve
Velocity engine.

Constructor Detail

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:
propFile - properties used to help populate 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:
props - properties object to help populate the control context.
Method Detail

getInstance

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

Returns:
Generator generator used in the control context.

setVelocityEngine

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

Parameters:
ve -

setDefaultProps

protected void setDefaultProps()
Set default properties.


setTemplatePath

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

Parameters:
templatePath - template path for velocity templates.

getTemplatePath

public String getTemplatePath()
Get the template path.

Returns:
String template path for velocity templates.

setOutputPath

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

Parameters:
outputPath -

getOutputPath

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

Returns:
String output path for texen output.

setOutputEncoding

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

Parameters:
outputEncoding -

setInputEncoding

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

Parameters:
inputEncoding -

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
Returns:
A Writer for this generator.
Throws:
Exception

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
Returns:
A Template.
Throws:
Exception

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:
inputTemplate - input template
outputFile - output file
Returns:
The parsed file.
Throws:
Exception

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:
inputTemplate - input template
outputFile - output file
objectID - id for object to be placed in the control context
object - object to be placed in the context
Returns:
String generated output from velocity
Throws:
Exception

parse

public String parse(String inputTemplate,
                    String inputEncoding,
                    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:
inputTemplate - input template
inputEncoding - template encoding
outputFile - output file
outputEncoding - outputEncoding encoding of output file
objectID - id for object to be placed in the control context
object - object to be placed in the context
Returns:
String generated output from velocity
Throws:
Exception

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:
controlTemplate - control template
controlContext - control context
Returns:
String generated output
Throws:
Exception

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:
objs - objects to place in the control context
Returns:
Context context filled with objects

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
objs - source of objects

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.

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

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 © 2000-2007 The Apache Software Foundation. All Rights Reserved.