All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class dmoisan.text.TemplateStream

java.lang.Object
   |
   +----dmoisan.text.TemplateStream

public class TemplateStream
extends Object
TemplateStream A class for processing text in a stream against a supplied template so that user-defined keywords within the template are replaced with the user's text (e.g. is replaced with "David Moisan"). Designed for Scala Lingua scripts but can be used for general-purpose template loading and replacement.

Permission is granted to use this code in any commercial or non-commercial application. NO WARRANTY IS IMPLIED.


Constructor Index

 o TemplateStream(String)
Constructor

Method Index

 o closeTemplateOutput(FileWriter)
closeTemplateOutput -- Write out unused template, replacing all unused keywords and close output stream
 o newTemplate(String)
newTemplate -- Load a new template to match keywords against in future processing Note that name is appended to the template start string and the search is done on that string.
 o replaceString(String, String, FileWriter)
replaceString The heart of TemplateStream: Copy the template to the output stream, replacing the keyword with the specified text.
 o setTemplateDelim(String, String, String, String)
SetTemplateDelim -- Sets the strings that delimit the start and end of the template, and the command prefix that differentiates substitution keywords from plain text

Constructors

 o TemplateStream
 public TemplateStream(String contents)
Constructor

Parameters:
contents - String Contents of all templates

Methods

 o setTemplateDelim
 public void setTemplateDelim(String start,
                              String end,
                              String keystart,
                              String keyend)
SetTemplateDelim -- Sets the strings that delimit the start and end of the template, and the command prefix that differentiates substitution keywords from plain text

Parameters:
String - start Opening string in template
String - end Closing string in template
String - keystart Keyword opening delimiter
String - keyend Keyword closing delimiter
 o newTemplate
 public boolean newTemplate(String name)
newTemplate -- Load a new template to match keywords against in future processing Note that name is appended to the template start string and the search is done on that string.

Parameters:
name - String Name of template to load
Returns:
s boolean true if template loaded, false if not
 o replaceString
 public boolean replaceString(String keyword,
                              String replacement,
                              FileWriter deststream) throws IOException
replaceString The heart of TemplateStream: Copy the template to the output stream, replacing the keyword with the specified text.

Parameters:
keyword - String Keyword to replace
replacement - String text that replaces keyword
deststream - FileWriter Output stream
Returns:
s boolean true if keyword found and replaced, false if not.
Throws: IOException
Thrown for I/O errors
 o closeTemplateOutput
 public void closeTemplateOutput(FileWriter deststream) throws IOException
closeTemplateOutput -- Write out unused template, replacing all unused keywords and close output stream

Parameters:
deststream - FileWriter Output stream
Throws: IOException
Thrown for I/O errors

All Packages  Class Hierarchy  This Package  Previous  Next  Index