sunlabs.brazil.groovy
Class GroovyServerTemplate
java.lang.Object
sunlabs.brazil.template.Template
sunlabs.brazil.groovy.GroovyServerTemplate (view source)
- All Implemented Interfaces:
- TemplateInterface
public class GroovyServerTemplate
- extends Template
The GroovyServerTemplate
looks for each
<groovy>
tag in an HTML page and treats the following data up to the next
</groovy>
)
tag as a groovy script to evaluate.
All Groovy fragments within a given page are evaluated in the same Groovy
interpreter. The Groovy interpreter actually lives for the entire duration
of this Template
object, so the user can implement
persistence across requests: Each session gets its own interpreter.
The following configuration parameters are used to initialize this
template.
- script
- The name of the Groovy script to evaluate when the interpreter is
created. This script only evaluated when the interp is created,
not on every request. The variables
prefix
and
server
are set before this file is evaluated, and
are references to the parameters passed to a handler
init method.
- root
- The document root, if the script is a relative file name.
If the "root" property under the template prefix is not found, the
global "root" property is used. If the global "root" property is
not found, the current directory is used.
- debug
- If this configuration parameter is present, this class
replaces the
<groovy>
and
</groovy>
tags with comments, so the user
can keep track of where the dynamically generated content is coming
from by examining the comments in the resultant HTML document.
By default, the <groovy>
and
</groovy>
are completely eliminated from the
HTML document rather than changed into comments.
Before evaluating each HTML document, this class sets variables
in the Groovy interpreter, which can be used to interact back with Java to
do things like set the response headers:
- request
- Exposes the
Request
Java object.
It is set anew at each request.
- prefix
- Exposes the handler prefix String.
- server
- Exposes the handler
Server
object.
Fields inherited from class sunlabs.brazil.template.Template |
debug |
Methods inherited from class sunlabs.brazil.template.Template |
done |
GroovyServerTemplate
public GroovyServerTemplate()
init
public boolean init(RewriteContext hr)
- Initialize the groovy interperter (1st time only) and set the
current request object.
- Specified by:
init
in interface TemplateInterface
- Overrides:
init
in class Template
tag_groovy
public void tag_groovy(RewriteContext hr)