Top Description Fields Constructors Methods
bsh.servlet

public Class SimpleTemplate

extends Object
Class Inheritance
Imports
java.io.*, java.util.*, java.net.URL

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.
Author
Pat Niemeyer

Field Summary

Modifier and TypeField and Description
pack-priv StringBuffer
pack-priv static boolean
pack-priv static String
pack-priv static Map<K, V>

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
pack-priv int[]
findTemplate(String name)

Find the starting (inclusive) and ending (exclusive) index of the named template and return them as a two element int [].

public static String
public static String
public static SimpleTemplate
getTemplate(String file)

Get a template by name, with caching.

private void
public static void
main(String[] args)

usage: filename param value

public void
replace(String param, String value)

Substitute the specified text for the parameter

public static void
setCacheTemplates(boolean b)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

buffback to summary
pack-priv StringBuffer buff
cacheTemplatesback to summary
pack-priv static boolean cacheTemplates
NO_TEMPLATEback to summary
pack-priv static String NO_TEMPLATE
templateDataback to summary
pack-priv static Map<K, V> templateData

Constructor Detail

SimpleTemplateback to summary
public SimpleTemplate(String template)
SimpleTemplateback to summary
public SimpleTemplate(Reader reader) throws IOException
SimpleTemplateback to summary
public SimpleTemplate(URL url) throws IOException

Method Detail

findTemplateback to summary
pack-priv int[] findTemplate(String name)

Find the starting (inclusive) and ending (exclusive) index of the named template and return them as a two element int []. Or return null if the param is not found.

getStringFromStreamback to summary
public static String getStringFromStream(InputStream ins) throws IOException
getStringFromStreamback to summary
public static String getStringFromStream(Reader reader) throws IOException
getTemplateback to summary
public static SimpleTemplate getTemplate(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.

initback to summary
private void init(String s)
mainback to summary
public static void main(String[] args) throws IOException

usage: filename param value

replaceback to summary
public void replace(String param, String value)

Substitute the specified text for the parameter

setCacheTemplatesback to summary
public static void setCacheTemplates(boolean b)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

writeback to summary
public void write(PrintWriter out)
writeback to summary
public void write(PrintStream out)