Class ScriptRunner<T>
- java.lang.Object
-
- com.norconex.importer.handler.ScriptRunner<T>
-
- Type Parameters:
T
- The evaluation response type.
public class ScriptRunner<T> extends Object
Runs scripts written in a programming language supported by the provided script engine. Java SE 6 and higher includes the JSR 223 API, which allows to "plug" any script engines to support your favorite scripting language.
JavaScript
The JavaScript (ECMAScript) script engine should already be present as part of your Java installation and is the default script engine used by this class when none is specified. As of Java 8, the Oracle version of Java uses the Nashorn engine, an implementation of the ECMAScript Edition 5.1 language specification (greater version of Java may use a more recent edition). Prior to version 8, Java used a JavaScript engine based on Mozilla Rhino.
Lua
As of 2.7.0, support for the Lua script engine is available. It relies on the LuaJ project to do so. To use it, set "lua" as the scripting engine with
setEngineName(String)
.Others
Several third-party script engines already exist to support additional languages such as Groovy, JRuby, Scala, Fantom, Jython, etc. Refer to appropriate third-party documentation about these languages to find out how to use them.
Note: While using a scripting language can be very convenient, it requires extra knowledge and should only be considered by experimented or adventurous users. Use at your own risk.
- Since:
- 2.4.0
- Author:
- Pascal Essiembre
- See Also:
ScriptFilter
,ScriptTagger
,ScriptTransformer
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_SCRIPT_ENGINE
static String
JAVASCRIPT_ENGINE
static String
LUA_ENGINE
-
Constructor Summary
Constructors Constructor Description ScriptRunner()
ScriptRunner(String engineName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bindings
createBindings()
boolean
equals(Object other)
T
eval(Bindings bindings)
String
getEngineName()
String
getScript()
int
hashCode()
void
setEngineName(String engineName)
void
setScript(String script)
String
toString()
-
-
-
Field Detail
-
LUA_ENGINE
public static final String LUA_ENGINE
- See Also:
- Constant Field Values
-
JAVASCRIPT_ENGINE
public static final String JAVASCRIPT_ENGINE
- See Also:
- Constant Field Values
-
DEFAULT_SCRIPT_ENGINE
public static final String DEFAULT_SCRIPT_ENGINE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ScriptRunner
public ScriptRunner()
-
ScriptRunner
public ScriptRunner(String engineName)
-
-
Method Detail
-
getEngineName
public String getEngineName()
-
setEngineName
public void setEngineName(String engineName)
-
getScript
public String getScript()
-
setScript
public void setScript(String script)
-
createBindings
public Bindings createBindings() throws ImporterHandlerException
- Throws:
ImporterHandlerException
-
eval
public T eval(Bindings bindings) throws ImporterHandlerException
- Throws:
ImporterHandlerException
-
-