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
-
TemplateProcessor(File)
- creates a new TemplateProcessor with a null hashtable of name/value pairs and
the text from the given file.
-
TemplateProcessor(File, Hashtable)
- creates a new TemplateProcessor with the text from the given file and using the
given hashtable of name/value pairs.
-
TemplateProcessor(String)
- creates a new TemplateProcessor with the given string and a null hashtable of
name/value pairs.
-
TemplateProcessor(String, Hashtable)
- creates a new TemplateProcessor with the given string and the given hasthable.
-
addValue(String, String)
- adds a name/value pair to the hashtable of names and values
-
getProcessedString()
- Creates a processed String.
-
getReplacement()
- returns the current hashtable of name/value pairs
-
isProcessed()
- Has the process() method been run with the current hashtable?
-
main(String[])
- A sample of the template processor.
-
setReplacement(Hashtable)
- replaces the current hashtable of name/value pairs
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.
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.
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.
TemplateProcessor
public TemplateProcessor(String start,
Hashtable replacement)
- creates a new TemplateProcessor with the given string and the given hasthable.
isProcessed
public boolean isProcessed()
- Has the process() method been run with the current hashtable?
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() )
addValue
public void addValue(String name,
String value)
- adds a name/value pair to the hashtable of names and values
setReplacement
public void setReplacement(Hashtable newReplacement)
- replaces the current hashtable of name/value pairs
getReplacement
public Hashtable getReplacement()
- returns the current hashtable of name/value pairs
main
public static void main(String args[])
- A sample of the template processor.
All Packages Class Hierarchy This Package Previous Next Index