All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class datarep.common.TemplateProcessor

java.lang.Object
   |
   +----datarep.common.TemplateProcessor

public class TemplateProcessor
extends Object
Template Processor: give it a string (or a text file which is turned into a string) and a hashtable of name/new name pairs (must be Strings). Then call getProcessedString() to generate an output string where the substitutions have been made.

When searching for name/value pairs, whole words are not required for a match. I.e. "are" matches "Mare", "aren't", and " are ", but not "a re".

The matches are case sensitive.

Once text has been replaced with a new value, that text is no longer searched. This means that you can't have endless loops by replacing "at" with "fishes" and then "he" with "hat". However, it also means that if you have a name/value pair "lis"/"Lis" and also "lisa"/"Elisabeth", if the first substitution is done first, the second will not be done.

Version:
1.2
Author:
Data Representations

Constructor Index

 o TemplateProcessor(File)
creates a new TemplateProcessor with a null hashtable of name/value pairs and the text from the given file.
 o TemplateProcessor(File, Hashtable)
creates a new TemplateProcessor with the text from the given file and using the given hashtable of name/value pairs.
 o TemplateProcessor(String)
creates a new TemplateProcessor with the given string and a null hashtable of name/value pairs.
 o TemplateProcessor(String, Hashtable)
creates a new TemplateProcessor with the given string and the given hasthable.

Method Index

 o addValue(String, String)
adds a name/value pair to the hashtable of names and values
 o getProcessedString()
Creates a processed String.
 o getReplacement()
returns the current hashtable of name/value pairs
 o isProcessed()
Has the process() method been run with the current hashtable?
 o main(String[])
A sample of the template processor.
 o setReplacement(Hashtable)
replaces the current hashtable of name/value pairs

Constructors

 o TemplateProcessor
 public TemplateProcessor(File f)
creates a new TemplateProcessor with a null hashtable of name/value pairs and the text from the given file. If a hashtable is not set, then no changes will be made.

 o TemplateProcessor
 public TemplateProcessor(File f,
                          Hashtable replacement)
creates a new TemplateProcessor with the text from the given file and using the given hashtable of name/value pairs.

 o TemplateProcessor
 public TemplateProcessor(String start)
creates a new TemplateProcessor with the given string and a null hashtable of name/value pairs. If no hashtable is defined, no substitutions will be made.

 o TemplateProcessor
 public TemplateProcessor(String start,
                          Hashtable replacement)
creates a new TemplateProcessor with the given string and the given hasthable.

Methods

 o isProcessed
 public boolean isProcessed()
Has the process() method been run with the current hashtable?

 o getProcessedString
 public String getProcessedString()
Creates a processed String. This is the method to use to generate output.
It will only call process() [a private method] if the hashtable of name/value pairs has actually changed since the last time process() was called. (see isProcessed() )

 o addValue
 public void addValue(String name,
                      String value)
adds a name/value pair to the hashtable of names and values

 o setReplacement
 public void setReplacement(Hashtable newReplacement)
replaces the current hashtable of name/value pairs

 o getReplacement
 public Hashtable getReplacement()
returns the current hashtable of name/value pairs

 o main
 public static void main(String args[])
A sample of the template processor.


All Packages  Class Hierarchy  This Package  Previous  Next  Index