All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.util.Template

java.lang.Object
   |
   +----sdsu.util.Template

public class Template
extends Object
A Template is an document containing variables. This class does the variable substitution and replaces with given values. If a variable is not given a value, it and the variable marker is removed from the template. Variables in denoted in the template by preceeding and following them by a special string, the variableMarker. The default value for the variableMarker is @@@. The creator of the template must insure this string does not occur as text in the template.

Author:
Roger Whitney (whitney@cs.sdsu.edu)

Constructor Index

 o Template(String)
Creates a template object using the given text

Method Index

 o clear()
Clears all variables.
 o fromFile(String)
Reads the text for a template from the given file.
 o replace(Hashtable)
Replaces all occurances of the given variables with given values.
 o replace(String, String)
Replaces all occurances of the given variable with given string.
 o replaceVariables()
 o setVariableMarker(String)
Changes the value of the variable marker.
 o toString()
Returns the template with all variables subsituted for the given values.

Constructors

 o Template
 public Template(String templateText)
Creates a template object using the given text

Methods

 o fromFile
 public static Template fromFile(String fileName) throws FileNotFoundException, IOException
Reads the text for a template from the given file.

Throws: FileNotFoundException
if fileName can not be found
Throws: IOException
on read error when reading file
 o clear
 public void clear()
Clears all variables. Any values given to them are removed.

 o replace
 public void replace(String variableName,
                     String variableValue)
Replaces all occurances of the given variable with given string.

 o replace
 public void replace(Hashtable variablesAndValues)
Replaces all occurances of the given variables with given values.

Parameters:
variablesAndValues - a hashtable whose keys are used as the variables and values are used as values of the variables. Keys and values are converted to strings before using.
 o setVariableMarker
 public void setVariableMarker(String newMarker)
Changes the value of the variable marker. Variables in the template are preceeded and followed by a special string, the variable marker. Default value is @@@.

Parameters:
newMarker - the new value for the variable marker
 o toString
 public String toString()
Returns the template with all variables subsituted for the given values. If a variable is not given a value, it is removed from the template string

Overrides:
toString in class Object
 o replaceVariables
 protected String replaceVariables()

All Packages  Class Hierarchy  This Package  Previous  Next  Index