|
Asterisk-Java | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.asteriskjava.fastagi.ScriptEngineMappingStrategy
public class ScriptEngineMappingStrategy
A MappingStrategy that uses ScriptEngine
to run AgiScripts. This MappingStrategy
can be used to run JavaScript, Groovy, JRuby, etc. scripts.
Nested Class Summary | |
---|---|
protected class |
ScriptEngineMappingStrategy.ScriptEngineAgiScript
|
Field Summary | |
---|---|
static java.lang.String |
CHANNEL
The binding under which the AGI channel is made available to scripts. |
protected java.lang.String[] |
libPath
|
protected Log |
logger
|
static java.lang.String |
REQUEST
The binding under which the AGI request is made available to scripts. |
protected javax.script.ScriptEngineManager |
scriptEngineManager
|
protected java.lang.String[] |
scriptPath
|
Constructor Summary | |
---|---|
ScriptEngineMappingStrategy()
Creates a new ScriptEngineMappingStrategy that searches for scripts in the current directory. |
|
ScriptEngineMappingStrategy(java.lang.String[] scriptPath,
java.lang.String[] libPath)
Creates a new ScriptEngineMappingStrategy that searches for scripts on the given path. |
Method Summary | |
---|---|
AgiScript |
determineScript(AgiRequest request)
Returns the AgiScript instance that is responsible to handle the given request. |
protected java.lang.ClassLoader |
getClassLoader()
Returns the ClassLoader to use for the ScriptEngineManager. |
protected static java.lang.String |
getExtension(java.lang.String scriptName)
Returns the extension (the part after the last ".") of the given script. |
protected static java.io.Reader |
getReader(java.io.File file)
|
protected javax.script.ScriptEngine |
getScriptEngine(java.io.File file)
Searches for a ScriptEngine that can handle the given file. |
protected javax.script.ScriptEngineManager |
getScriptEngineManager()
Returns the ScriptEngineManager to use for loading the ScriptEngine. |
protected boolean |
isInside(java.io.File file,
java.io.File dir)
Checks whether a file is contained within a given directory (or a sub directory) or not. |
protected void |
populateBindings(java.io.File file,
AgiRequest request,
AgiChannel channel,
javax.script.Bindings bindings)
Override this method if you want to add additional bindings before the script is run. |
protected java.io.File |
searchFile(java.lang.String scriptName,
java.lang.String[] path)
Searches for the file with the given name on the path. |
void |
setLibPath(java.lang.String[] libPath)
Sets the path to search for additional libraries (jar files). |
void |
setScriptPath(java.lang.String[] scriptPath)
Sets the path to search for script files. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
public static final java.lang.String REQUEST
public static final java.lang.String CHANNEL
protected java.lang.String[] scriptPath
protected java.lang.String[] libPath
protected javax.script.ScriptEngineManager scriptEngineManager
Constructor Detail |
---|
public ScriptEngineMappingStrategy()
public ScriptEngineMappingStrategy(java.lang.String[] scriptPath, java.lang.String[] libPath)
scriptPath
- array of directory names to search for script files.libPath
- array of directory names to search for additional libraries (jar files).Method Detail |
---|
public void setScriptPath(java.lang.String[] scriptPath)
Default is "agi".
scriptPath
- array of directory names to search for script files.public void setLibPath(java.lang.String[] libPath)
Default is "lib".
libPath
- array of directory names to search for additional libraries (jar files).public AgiScript determineScript(AgiRequest request)
MappingStrategy
determineScript
in interface MappingStrategy
request
- the request to lookup.
null
if none could be determined by this strategy.protected javax.script.ScriptEngine getScriptEngine(java.io.File file)
file
- the file to search a ScriptEngine for.
null
if none is found.protected javax.script.ScriptEngineManager getScriptEngineManager()
ScriptEngineManager.ScriptEngineManager()
protected java.lang.ClassLoader getClassLoader()
getScriptEngineManager()
protected java.io.File searchFile(java.lang.String scriptName, java.lang.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(java.io.File file, java.io.File dir) throws java.io.IOException
file
- the file to check.dir
- the directory to check.
true
if file is below directory, false
otherwise.
java.io.IOException
- if the canonical path of file or dir cannot be determined.protected static java.lang.String getExtension(java.lang.String scriptName)
scriptName
- the name of the script to return the extension of.
null
if there is no extension.protected static java.io.Reader getReader(java.io.File file) throws java.io.FileNotFoundException
java.io.FileNotFoundException
protected void populateBindings(java.io.File file, AgiRequest request, AgiChannel channel, javax.script.Bindings bindings)
file
- the script file.request
- the AGI request.channel
- the AGI channel.bindings
- the bindings to populate.
|
Asterisk-Java | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |