public class ScriptEngineMappingStrategy extends Object implements MappingStrategy
ScriptEngine to run
AgiScripts. This MappingStrategy can be used to run JavaScript, Groovy,
JRuby, etc. scripts.| Modifier and Type | Class and Description |
|---|---|
protected class |
ScriptEngineMappingStrategy.ScriptEngineAgiScript |
| Modifier and Type | Field and Description |
|---|---|
static String |
CHANNEL
The binding under which the AGI channel is made available to scripts.
|
protected String[] |
libPath |
protected Log |
logger |
static String |
REQUEST
The binding under which the AGI request is made available to scripts.
|
protected ScriptEngineManager |
scriptEngineManager |
protected String[] |
scriptPath |
| Constructor and Description |
|---|
ScriptEngineMappingStrategy()
Creates a new ScriptEngineMappingStrategy that searches for scripts in
the current directory.
|
ScriptEngineMappingStrategy(String[] scriptPath,
String[] libPath)
Creates a new ScriptEngineMappingStrategy that searches for scripts on
the given path.
|
| Modifier and Type | Method and Description |
|---|---|
AgiScript |
determineScript(AgiRequest request,
AgiChannel channel)
Returns the AgiScript instance that is responsible to handle
the given request.
|
protected ClassLoader |
getClassLoader()
Returns the ClassLoader to use for the ScriptEngineManager.
|
protected static String |
getExtension(String scriptName)
Returns the extension (the part after the last ".") of the given script.
|
protected static Reader |
getReader(File file) |
protected ScriptEngine |
getScriptEngine(File file)
Searches for a ScriptEngine that can handle the given file.
|
protected ScriptEngineManager |
getScriptEngineManager()
Returns the ScriptEngineManager to use for loading the ScriptEngine.
|
protected boolean |
isInside(File file,
File dir)
Checks whether a file is contained within a given directory (or a sub
directory) or not.
|
protected void |
populateBindings(File file,
AgiRequest request,
AgiChannel channel,
Bindings bindings)
Override this method if you want to add additional bindings before the
script is run.
|
protected File |
searchFile(String scriptName,
String[] path)
Searches for the file with the given name on the path.
|
void |
setLibPath(String[] libPath)
Sets the path to search for additional libraries (jar files).
|
void |
setScriptPath(String[] scriptPath)
Sets the path to search for script files.
|
protected final Log logger
public static final String REQUEST
public static final String CHANNEL
protected String[] scriptPath
protected String[] libPath
protected ScriptEngineManager scriptEngineManager
public ScriptEngineMappingStrategy()
public ScriptEngineMappingStrategy(String[] scriptPath, String[] libPath)
scriptPath - array of directory names to search for script files.libPath - array of directory names to search for additional
libraries (jar files).public void setScriptPath(String[] scriptPath)
Default is "agi".
scriptPath - array of directory names to search for script files.public void setLibPath(String[] libPath)
Default is "lib".
libPath - array of directory names to search for additional
libraries (jar files).public AgiScript determineScript(AgiRequest request, AgiChannel channel)
MappingStrategydetermineScript in interface MappingStrategyrequest - the request to lookup.channel - the channel.null if none could be determined by this strategy.protected ScriptEngine getScriptEngine(File file)
file - the file to search a ScriptEngine for.null if none is found.protected ScriptEngineManager getScriptEngineManager()
ScriptEngineManager()protected ClassLoader getClassLoader()
getScriptEngineManager()protected File searchFile(String scriptName, String[] path)
scriptName - the name of the file to search for.path - an array of directories to search for the file in order of
preference.null if
not found.protected final boolean isInside(File file, File dir) throws IOException
file - the file to check.dir - the directory to check.true if file is below directory, false
otherwise.IOException - if the canonical path of file or dir cannot be
determined.protected static String getExtension(String scriptName)
scriptName - the name of the script to return the extension of.null if there is no
extension.protected static Reader getReader(File file) throws FileNotFoundException
FileNotFoundExceptionprotected void populateBindings(File file, AgiRequest request, AgiChannel channel, Bindings bindings)
file - the script file.request - the AGI request.channel - the AGI channel.bindings - the bindings to populate.Copyright © 2004–2021. All rights reserved.