|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--bsh.servlet.SimpleTemplate
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.
Field Summary | |
(package private) java.lang.StringBuffer |
buff
|
(package private) static boolean |
cacheTemplates
|
(package private) static java.lang.String |
NO_TEMPLATE
|
(package private) static java.util.Map |
templateData
|
Constructor Summary | |
SimpleTemplate(java.io.Reader reader)
|
|
SimpleTemplate(java.lang.String template)
|
|
SimpleTemplate(java.net.URL url)
|
Method Summary | |
(package private) int[] |
findTemplate(java.lang.String name)
Find the starting (inclusive) and ending (exclusive) index of the named template and return them as a two element int []. |
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. |
private void |
init(java.lang.String s)
|
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 |
Field Detail |
java.lang.StringBuffer buff
static java.lang.String NO_TEMPLATE
static java.util.Map templateData
static boolean cacheTemplates
Constructor Detail |
public SimpleTemplate(java.lang.String template)
public SimpleTemplate(java.io.Reader reader) throws java.io.IOException
public SimpleTemplate(java.net.URL url) throws java.io.IOException
Method Detail |
public static SimpleTemplate getTemplate(java.lang.String file)
public static java.lang.String getStringFromStream(java.io.InputStream ins) throws java.io.IOException
java.io.IOException
public static java.lang.String getStringFromStream(java.io.Reader reader) throws java.io.IOException
java.io.IOException
private void init(java.lang.String s)
public void replace(java.lang.String param, java.lang.String value)
int[] findTemplate(java.lang.String name)
public java.lang.String toString()
toString
in class java.lang.Object
public void write(java.io.PrintWriter out)
public void write(java.io.PrintStream out)
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
public static void setCacheTemplates(boolean b)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |