sunlabs.brazil.sunlabs
Class ScriptServerTemplate

java.lang.Object
  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>

language
The language name (e.g. from getEngineByName()).
eval
evaluate all ${...} constructs before running the script
result=true|false
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:

rewrite_context
The current rewrite context. Although the "rewrite context" is sufficient, the rest are sometimes more convenient.
prefix
The same as rewrite_context.prefix
request
The same as rewrite_context.request
props
The same as rewrite_context.request.props
brazil_version
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:

ensure
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
debug
 
Constructor Summary
ScriptServerTemplate()
           
 
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
done
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptServerTemplate

public ScriptServerTemplate()
Method Detail

init

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
Parameters:
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.
Returns:
true if this Handler initialized successfully, false otherwise. If false is returned, this Handler should not be used.

respond

public boolean respond(Request request)
                throws IOException
Description copied from interface: Handler
Responds to an HTTP request.

Specified by:
respond in interface Handler
Parameters:
request - The Request object that represents the HTTP request.
Returns:
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.
Throws:
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.


init

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

Specified by:
init in interface TemplateInterface
Overrides:
init in class Template

tag_interp

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.