|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsunlabs.brazil.velocity.VelocityFilter (view source)
public class VelocityFilter
A filter for processing markup that is a Velocity template. The filter will "merge" the content with a BeanShell script to produce output content.
The following server properties are used:
The BeanShell script is found by first looking in the filesystem. If not found, the classpath is searched. It's okay not to specify or use a BeanShell script. The content will still be processed by the Velocity engine.
The BeanShell interpreter is managed by session and is persistent during
the session. The interpreter has access to the Server
object, the prefix string, the Request
object, and the
Velocity context through the variables "server", "prefix", "request",
and "context".
A new Velocity context is created each time the filter
method is called. For convenience, the context is initially populated
with the same objects as the BeanShell. They are referenced by the
same names ("server", "prefix", "request", and "context"). However,
due to the design of Velocity, the public fields of the Server
and Request
objects are read only. The field values can not
be changed by the template code.
Each time the filter
method is called, a new Velocity
context is created and populated. Then the BeanShell script, if it exists,
is passed through Format.subst
for variable substitution
and then passed to the BeanShell interpreter. Finally the content (i.e. a
Velocity template) and the context are passed to the Velocity engine
for processing.
Note: Velocity requires at least a 1.2 Java VM. Attempts to use Velocity with a 1.1 VM will most likely produce incorrect results. Also note that the Brazil system must be compiled with a 1.2+ compiler so that core components of Brazil are compatible with the Velocity engine.
Nested Class Summary | |
---|---|
class |
VelocityFilter.Vrequest
A helper class for Velocity that provides read only access to the public fields of the Request object. |
class |
VelocityFilter.Vserver
A helper class for Velocity that provides read only access to the public fields of the Server object. |
Field Summary |
---|
Fields inherited from interface org.apache.velocity.runtime.log.LogSystem |
---|
DEBUG_ID, DEBUG_ON, ERROR_ID, INFO_ID, WARN_ID |
Constructor Summary | |
---|---|
VelocityFilter()
|
Method Summary | |
---|---|
byte[] |
filter(Request request,
MimeHeaders headers,
byte[] content)
Execute the BeanShell script if it exists and then process the content as a Velocity template. |
void |
init(RuntimeServices rsvc)
Velocity LogSystem interface implementation. |
boolean |
init(Server server,
String prefix)
Initializes the handler. |
void |
logVelocityMessage(int level,
String message)
|
boolean |
respond(Request request)
This is the request object before the content was fetched |
boolean |
shouldFilter(Request request,
MimeHeaders headers)
Only filter text/* documents |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public VelocityFilter()
Method Detail |
---|
public boolean init(Server server, String prefix)
Handler
init
in interface Handler
server
- The HTTP server that created this Handler
.
Typical Handler
s will use Server.props
to obtain run-time configuration information.prefix
- The handlers name.
The string this Handler
may prepend to all
of the keys that it uses to extract configuration information
from Server.props
. This is set (by the Server
and ChainHandler
) to help avoid configuration parameter
namespace collisions.
true
if this Handler
initialized
successfully, false
otherwise. If
false
is returned, this Handler
should not be used.public boolean respond(Request request)
respond
in interface Handler
request
- The Request
object that represents the HTTP
request.
true
if the request was handled. A request was
handled if a response was supplied to the client, typically
by calling Request.sendResponse()
or
Request.sendError
.public boolean shouldFilter(Request request, MimeHeaders headers)
shouldFilter
in interface Filter
request
- The in-progress HTTP request.headers
- The MIME headers generated by the wrapped Handler
.
true
if this filter would like to examine and
possibly rewrite the content, false
otherwise.public byte[] filter(Request request, MimeHeaders headers, byte[] content)
filter
in interface Filter
request
- The finished HTTP request.headers
- The MIME headers generated by the Handler
.content
- The output from the Handler
that this
Filter
may rewrite.
Filter
may return
the original content
unchanged. The
Filter
may return null
to indicate
that the FilterHandler
should stop processing the
request and should not return any content to the client.public void init(RuntimeServices rsvc)
init
in interface LogSystem
public void logVelocityMessage(int level, String message)
logVelocityMessage
in interface LogSystem
|
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 |