public final class ScriptUtil extends Object
Important: To avoid a lot of Map
copying, all methods that accept a context
Map
argument will pass that Map
directly to the scripting engine. Any variables that
are declared or modified in the script will affect the original Map
. Client code that wishes to preserve
the state of the Map
argument should pass a copy of the Map
.
Modifier and Type | Field and Description |
---|---|
static String |
module |
static String |
PARAMETERS_KEY
The service/servlet/request parameters map bindings key.
|
static String |
RESULT_KEY
The result map bindings key.
|
static String |
SCRIPT_HELPER_KEY
The
ScriptHelper key. |
static Set<String> |
SCRIPT_NAMES
A set of script names - derived from the JSR-223 scripting engines.
|
static String |
WIDGET_CONTEXT_KEY
The screen widget context map bindings key.
|
Modifier and Type | Method and Description |
---|---|
static CompiledScript |
compileScriptFile(String filePath)
Returns a compiled script.
|
static CompiledScript |
compileScriptString(String language,
String script)
Returns a compiled script.
|
static ScriptContext |
createScriptContext(Map<String,Object> context)
Returns a
ScriptContext that contains the members of context . |
static ScriptContext |
createScriptContext(Map<String,Object> context,
Set<String> protectedKeys)
Returns a
ScriptContext that contains the members of context . |
static ScriptHelper |
createScriptHelper(ScriptContext context) |
static Object |
evaluate(String language,
String script,
Class<?> scriptClass,
Map<String,Object> context)
Executes a script
String and returns the result. |
static Object |
executeScript(CompiledScript script,
String functionName,
ScriptContext scriptContext,
Object[] args)
Executes a compiled script and returns the result.
|
static Object |
executeScript(String filePath,
String functionName,
Map<String,Object> context)
Executes the script at the specified location and returns the result.
|
static Object |
executeScript(String filePath,
String functionName,
Map<String,Object> context,
Object[] args)
Executes the script at the specified location and returns the result.
|
static Object |
executeScript(String filePath,
String functionName,
ScriptContext scriptContext,
Object[] args)
Executes the script at the specified location and returns the result.
|
static Class<?> |
parseScript(String language,
String script) |
public static final String module
public static final String WIDGET_CONTEXT_KEY
public static final String PARAMETERS_KEY
public static final String RESULT_KEY
public static final String SCRIPT_HELPER_KEY
ScriptHelper
key.public static CompiledScript compileScriptFile(String filePath) throws ScriptException, IOException
filePath
- Script path and file name.null
if the script engine does not support compilation.IllegalArgumentException
ScriptException
IOException
public static CompiledScript compileScriptString(String language, String script) throws ScriptException
language
- script
- null
if the script engine does not support compilation.IllegalArgumentException
ScriptException
public static ScriptContext createScriptContext(Map<String,Object> context)
ScriptContext
that contains the members of context
.
If a CompiledScript
instance is to be shared by multiple threads, then
each thread must create its own ScriptContext
and pass it to the
CompiledScript
eval method.
context
- public static ScriptContext createScriptContext(Map<String,Object> context, Set<String> protectedKeys)
ScriptContext
that contains the members of context
.
If a CompiledScript
instance is to be shared by multiple threads, then
each thread must create its own ScriptContext
and pass it to the
CompiledScript
eval method.
context
- protectedKeys
- public static ScriptHelper createScriptHelper(ScriptContext context)
public static Object evaluate(String language, String script, Class<?> scriptClass, Map<String,Object> context) throws Exception
String
and returns the result.language
- script
- scriptClass
- context
- Exception
public static Object executeScript(CompiledScript script, String functionName, ScriptContext scriptContext, Object[] args) throws ScriptException, NoSuchMethodException
script
- Compiled script.functionName
- Optional function or method to invoke.scriptContext
- Script execution context.IllegalArgumentException
ScriptException
NoSuchMethodException
public static Object executeScript(String filePath, String functionName, Map<String,Object> context)
filePath
- Script path and file name.functionName
- Optional function or method to invoke.context
- Script execution context.IllegalArgumentException
public static Object executeScript(String filePath, String functionName, Map<String,Object> context, Object[] args)
filePath
- Script path and file name.functionName
- Optional function or method to invoke.context
- Script execution context.args
- Function/method arguments.IllegalArgumentException
public static Object executeScript(String filePath, String functionName, ScriptContext scriptContext, Object[] args) throws ScriptException, NoSuchMethodException, IOException
filePath
- Script path and file name.functionName
- Optional function or method to invoke.scriptContext
- Script execution context.args
- Function/method arguments.ScriptException
NoSuchMethodException
IOException
IllegalArgumentException