bsh.servlet
Class SimpleTemplate

java.lang.Object
  extended by bsh.servlet.SimpleTemplate

public class SimpleTemplate
extends java.lang.Object

This is a simple template engine. An instance of SimpleTemplate wraps a StringBuffer and performs replace operations on one or more parameters embedded as HMTL style comments. The value can then be retrieved as a String or written to a stream. Template values in the text are of the form: Substitutions then take the form of: template.replace( "NAME", value ); Two static util methods are provided to help read the text of a template from a stream (perhaps a URL or resource). e.g.


Constructor Summary
SimpleTemplate(java.io.Reader reader)
           
SimpleTemplate(java.lang.String template)
           
SimpleTemplate(java.net.URL url)
           
 
Method Summary
static java.lang.String getStringFromStream(java.io.InputStream ins)
           
static java.lang.String getStringFromStream(java.io.Reader reader)
           
static SimpleTemplate getTemplate(java.lang.String file)
          Get a template by name, with caching.
static void main(java.lang.String[] args)
          usage: filename param value
 void replace(java.lang.String param, java.lang.String value)
          Substitute the specified text for the parameter
static void setCacheTemplates(boolean b)
           
 java.lang.String toString()
           
 void write(java.io.PrintStream out)
           
 void write(java.io.PrintWriter out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleTemplate

public SimpleTemplate(java.lang.String template)

SimpleTemplate

public SimpleTemplate(java.io.Reader reader)
               throws java.io.IOException
Throws:
java.io.IOException

SimpleTemplate

public SimpleTemplate(java.net.URL url)
               throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getTemplate

public static SimpleTemplate getTemplate(java.lang.String file)
Get a template by name, with caching. Note: this should be updated to search the resource path first, etc. Create a new instance of a template from the specified file. The file text is cached so lookup is fast. Failure to find the file is also cached so the read will not happen twice.


getStringFromStream

public static java.lang.String getStringFromStream(java.io.InputStream ins)
                                            throws java.io.IOException
Throws:
java.io.IOException

getStringFromStream

public static java.lang.String getStringFromStream(java.io.Reader reader)
                                            throws java.io.IOException
Throws:
java.io.IOException

replace

public void replace(java.lang.String param,
                    java.lang.String value)
Substitute the specified text for the parameter


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

write

public void write(java.io.PrintWriter out)

write

public void write(java.io.PrintStream out)

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
usage: filename param value

Throws:
java.io.IOException

setCacheTemplates

public static void setCacheTemplates(boolean b)