net.sourceforge.jinit
Class TemplateEngine

java.lang.Object
  extended by net.sourceforge.jinit.TemplateEngine

public class TemplateEngine
extends Object

A simplistic template engine. Basically replaces any ${var} references with actual values. All references that are supposed to be substituted are added to a context object. If a reference is found and it is not in the context, it is simply ignored, which makes this engine ideal to use for Apache Ant build scripts where some references should be resolved but not all.

The basic working is as follows: Suppose you have a file with:

    @(#) ${filename} ${date} ${time}

And another with :

    filename=Test.java
    date=2004-10-31

And you run the template engine on the files, the first file will have the following:

    @(#) Test.java 2004-10-31 ${time}

Since:
0.1
Version:
0.2
Author:
Trevor Miller

Method Summary
static void merge(Hashtable context, File file)
          Merges the data in the context with the file given by resolving all references contained in the context and substituting their values in the file.
static String merge(Hashtable context, String source)
          Merges the data in the context with the source given by resolving all references contained in the context and substituting their values in the source string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

merge

public static void merge(Hashtable context,
                         File file)
                  throws Exception
Merges the data in the context with the file given by resolving all references contained in the context and substituting their values in the file.

Parameters:
context - The context containing reference values
file - The file to merge with
Throws:
Exception - If an error occurs

merge

public static String merge(Hashtable context,
                           String source)
Merges the data in the context with the source given by resolving all references contained in the context and substituting their values in the source string.

Parameters:
context - The context containing reference values
source - The source string
Returns:
The merged string


Copyright © 2005 JInit Project. All Rights Reserved.