    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)

##

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

##

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

##

Template

     public Template(String templateText)

  Creates a template object using the given text

##

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

clear

     public void clear()

  Clears all variables. Any values given to them are removed.

replace

     public void replace(String variableName,
                         String variableValue)

  Replaces all occurances of the given variable with given string.

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.

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

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

replaceVariables

     protected String replaceVariables()

    All Packages  Class Hierarchy  This Package  Previous  Next  Index