public class ScriptedParamBuilder extends AbstractParamBuilder
This ParamBuilder implementation can execute arbitrary scripts to build one or more parameters. This allows for very flexible and powerful ParamBuilder instances. All functionality provided by other ParamBuilders (and more) can also be accomplished with a ScriptedParamBuilder.
This ParamBuilder is based on Java's ScriptEngine API, allowing additional script engines to be added by adding a script engine jar file on the VODServer class path. Java comes bundled with the Rhino JavaScript engine, meaning JavaScript is supported out of the box. Other script engines should work as well, but have not been tested.
The script engine to use is configured using the scriptEngineName property, the default is js (JavaScript). The actual script to execute is configured using the script property. If the script engine supports compilation, the script is pre-compiled upon initialization of this ParamBuilder.
Apart from the standard script engine/Java integration, the following objects are available within the script context:
ScriptedParamBuilder.ScriptUtil
for a complete overview of available methods.Modifier and Type | Class and Description |
---|---|
static class |
ScriptedParamBuilder.ScriptUtil
An instance of this utility class is available in the script context
under the name 'util'.
|
Constructor and Description |
---|
ScriptedParamBuilder() |
Modifier and Type | Method and Description |
---|---|
void |
buildParams(Map<String,String> params,
javax.servlet.http.HttpServletRequest request)
Build the parameters; this will simply invoke the configured script to
build the parameters.
|
protected void |
extraAfterPropertiesSet()
Upon initialization, if the configured script engine supports compilation,
we will pre-compile the configured script.
|
protected Bindings |
getBindings(Map<String,String> params,
javax.servlet.http.HttpServletRequest request)
Get the bindings used for executing the script.
|
String |
getScript()
Get the configured script.
|
void |
setScript(String script)
Set the script to execute.
|
void |
setScriptEngineName(String scriptEngineName)
Set the script engine name.
|
String |
toString()
Provide a useful string representation of this ParamBuilder,
showing the script engine used, whether the script was precompiled,
and the script contents.
|
afterPropertiesSet, compareTo, getOrder, setOrder
getBeanName, setBeanName
public void buildParams(Map<String,String> params, javax.servlet.http.HttpServletRequest request)
params
- The parameters map to which parameters can be added or existing parameters can be retrieved.request
- The original request, useful to retrieve request parameters for example.protected Bindings getBindings(Map<String,String> params, javax.servlet.http.HttpServletRequest request)
params
- request
- protected void extraAfterPropertiesSet()
extraAfterPropertiesSet
in class AbstractParamBuilder
public void setScriptEngineName(String scriptEngineName)
scriptEngineName
- public String getScript()
public void setScript(String script)
script
- Copyright © 2013. All rights reserved.