|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsunlabs.brazil.template.Template
sunlabs.brazil.beanshell.BeanShellServerTemplate (view source)
public class BeanShellServerTemplate
The BeanShellServerTemplate
looks for one of the
starting tags
<server language="beanshell">
,
<beanshell>
, or
<bsh>
in an HTML page and treats the following data up to the corresponding
ending tag (
</server>
,
</beanshell>
, or
</bsh>
)
as a BeanShell script to evaluate. For information on BeanShell, see
www.beanshell.org.
The reason that BeanShell scripts are included in an HTML page is usually to generate dynamic, server-side content. After running this template, everything between and including the starting tag and and the ending tag is replaced by all output written to the BeanShell output stream (if any).
All BeanShell fragments within a given page are evaluated in the
same BeanShell interpreter. The BeanShell interpreter actually
lives for the entire duration of this Template
object,
so the user can implement persistence across requests.
The following configuration parameters are used to initialize this template.
prefix
and server
are set
before this file is evaluated, and are references to the
parameters passed to a handler
init method.
Before evaluating each HTML document, this class sets variables in the BeanShell interpreter, which can be used to interact back with Java to do things like set the response headers:
Request
Java object.
It is set anew at each request.
Server
object.
eval
is present as an attribute, all
constructs off the form ${...} are substituted before processing
the script.
Here's a simple example of a BeanShell template:
<html>
<head>
<title>BeanShell Examples</title>
</head>
<body>
The global variables <code>request</code>,
<code>prefix</code>, and <code>server</code>
are already defined. Here's how to add a new property:
<bsh>
sum = 3 + 4 + 5;
request.props.put("sum", Integer.toString(sum));
</bsh>
And here's a way to list the properties contained in the request:
<table>
<bsh>
e = request.props.propertyNames();
while (e.hasMoreElements()) {
name = e.nextElement();
value = request.props.getProperty(name);
print("<tr><td>" + name + "</td><td>"
+ value + "</td></tr>");
}
</bsh>
</table>
</body>
</html>
Field Summary |
---|
Fields inherited from class sunlabs.brazil.template.Template |
---|
debug |
Constructor Summary | |
---|---|
BeanShellServerTemplate()
|
Method Summary | |
---|---|
boolean |
init(RewriteContext hr)
Called at the beginning of each HTML document that this BeanShellServerTemplate is asked to process. |
void |
tag_beanshell(RewriteContext hr)
Processes the <beanshell> tag. |
void |
tag_bsh(RewriteContext hr)
Processes the <bsh> tag. |
void |
tag_server(RewriteContext hr)
Processes the <server> tag. |
Methods inherited from class sunlabs.brazil.template.Template |
---|
done |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanShellServerTemplate()
Method Detail |
---|
public boolean init(RewriteContext hr)
BeanShellServerTemplate
is asked to process.
The first time this method is called, the initialization script
is sourced into the interpreter, based on the configuration
properties in the Request
init
in interface TemplateInterface
init
in class Template
hr
- The request and associated HTML document that will be
processed.
true
interpreter was successfully
initialized false
otherwise. About the
only way that the initialization could fail would be
due to an error sourcing the initialization script. If
false
is returned, an error message is
logged.public void tag_server(RewriteContext hr)
<server>
tag. Substitutes the
result of evaluating the following BeanShell script into the
resultant HTML document.
hr
- The request and associated HTML document that will be
processed.public void tag_beanshell(RewriteContext hr)
<beanshell>
tag. Substitutes
the result of evaluating the following BeanShell script into
the resultant HTML document.
hr
- The request and associated HTML document that will be
processed.public void tag_bsh(RewriteContext hr)
<bsh>
tag. Substitutes the
result of evaluating the following BeanShell script into the
resultant HTML document.
hr
- The request and associated HTML document that will be
processed.
|
Version Kenai-svn-r24, Generated 08/18/09 Copyright (c) 2001-2009, Sun Microsystems. |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |