|
Tynamo™-SNAP v1.0.4 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.qindesign.servlet.Template
public class Template
This class implements a simple template engine for use in servlets.
Variables are indicated by enclosing a name within hash marks. For
example, the string "<p>Hello,
#name#!</p>", contains a variable named "name".
Zero-length variable names ("##") are replaced by a single
hash mark in the output, and unclosed hashes, or variable names with non-
identifier chars in them are ignored and output as-is. Additionally, unset
variables are also ignored and output as-is.
For variable names with non-identifier chars, parsing stops at the first such character, and what would be the variable's ending hash becomes the starting hash for another variable. For example, the string
"<span style=\"color: #C0C0C0\">My name is #name#</span>"
is considered to have only the variable, "name". Parsing stops for the potential variable whose name starts with "C0C0C0" because a double quote character is not a valid Java identifier.
Internally, the template string is stored in a byte array for fast output.
| Nested Class Summary | |
|---|---|
static interface |
Template.UnsetVariableHandler
This handler is called for each variable that is not set. |
| Method Summary | |
|---|---|
void |
clear()
Unsets all the template variables. |
static void |
flushCache()
This clears the template cache. |
String |
get(String name)
Gets the value associated with the specified variable. |
boolean |
has(String name)
Checks if this template has the specified variable. |
Enumeration |
names()
Returns an enumeration of the variable names in this template. |
void |
output(HttpServletRequest req,
HttpServletResponse resp)
Outputs the template. |
static Template |
parse(File file)
Parses a file containing a template. |
static Template |
parse(String s)
Parses a string containing a template. |
void |
set(String name,
String value)
Sets a value in the template. |
void |
setUnsetVariableHandler(Template.UnsetVariableHandler handler)
Sets the handler for unset variables. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void flushCache()
public static Template parse(File file)
throws IOException
file - the file containing the template
null if the file does not exist.
IOException - if there was an error reading from the file.
NullPointerException - if file is null.public static Template parse(String s)
s - the template to parse
NullPointerException - if the string is null.public void clear()
public void set(String name,
String value)
null unsets the
variable.
name - the variable name to setvalue - the valuepublic String get(String name)
null if the variable is unset or does not exist.
name - the variable name to get
null if the variable is unset or does not exist.public boolean has(String name)
name - the variable name to search forpublic Enumeration names()
Enumeration of all the variable names in this
template.public void setUnsetVariableHandler(Template.UnsetVariableHandler handler)
Passing a value of null removes any previously set
handler.
handler - the handler to listen for unset variables, or
null to remove the handler
public void output(HttpServletRequest req,
HttpServletResponse resp)
throws IOException,
ServletException
req - the HTTP request objectresp - the HTTP response object
IOException - if there was an I/O error while outputting the
template.
ServletException - if the callback generated this exception.
|
Tynamo™-SNAP v1.0.4 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||