Class ScriptServerTemplate

  extended by sunlabs.brazil.template.Template
      extended by sunlabs.brazil.sunlabs.ScriptServerTemplate (view source)
All Implemented Interfaces:
Handler, TemplateInterface

public class ScriptServerTemplate
extends Template
implements Handler

Run a script using the specified language: <interp language="xxx" [eval=true|false]> ... script markup .... </interp>

The language name (e.g. from getEngineByName()).
evaluate all ${...} constructs before running the script
If true, the result of the script is placed in the resultant document, otherwise it is ignored.
The script is replaced in the markup by the script ouput, followed by its result (if result=true).

The following variables are made available to each script invocation:

The current rewrite context. Although the "rewrite context" is sufficient, the rest are sometimes more convenient.
The same as rewrite_context.prefix
The same as rewrite_context.request
The same as rewrite_context.request.props
The same as Server.version

NOTE: This only works with Java 1.6 (or higher), and requires the desired script engine to be in the classpath (except "javascript", which is built in). There is currently no provision for startup scripts.

This class may be installed as a handler to make sure all required script languages are available before starting the server. In that case, the property:

white space delimited list of required languages.
If any of the required languages is not available, the server will not start.

Field Summary
Fields inherited from class sunlabs.brazil.template.Template
Constructor Summary
Method Summary
 boolean init(RewriteContext hr)
          Make sure all markup between <interp>...</interp> is captured.
 boolean init(Server server, String prefix)
          Install as handler to insure required script engines are available before startin the server.
 boolean respond(Request request)
          Responds to an HTTP request.
 void tag_interp(RewriteContext hr)
          Grab all markup 'till the closing tag, and run it through the proper language engine.
Methods inherited from class sunlabs.brazil.template.Template
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public ScriptServerTemplate()
Method Detail


public boolean init(Server server,
                    String prefix)
Install as handler to insure required script engines are available before startin the server. Actually instantiate the engines, as it is possible that an engine will exist, but fail during creation.

Specified by:
init in interface Handler
server - The HTTP server that created this Handler. Typical Handlers 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)
                throws IOException
Description copied from interface: Handler
Responds to an HTTP request.

Specified by:
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.
IOException - if there was an I/O error while sending the response to the client. Typically, in that case, the Server will (try to) send an error message to the client and then close the client's connection.

The IOException should not be used to silently ignore problems such as being unable to access some server-side resource (for example getting a FileNotFoundException due to not being able to open a file). In that case, the Handler's duty is to turn that IOException into a HTTP response indicating, in this case, that a file could not be found.


public boolean init(RewriteContext hr)
Make sure all markup between <interp>...</interp> is captured.

Specified by:
init in interface TemplateInterface
init in class Template


public void tag_interp(RewriteContext hr)
Grab all markup 'till the closing tag, and run it through the proper language engine. Each session gets their own engine instance.

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.