public class JavaScriptEngine extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static String |
KEY_STARTING_SCOPE
Key used to place the scope in which the execution of some javascript code
started as thread local attribute in current context.
This is needed to resolve some relative locations relatively to the page in which the script is executed and not to the page which location is changed. |
Constructor and Description |
---|
JavaScriptEngine(WebClient webClient)
Create an instance for the specified webclient
|
Modifier and Type | Method and Description |
---|---|
void |
cacheScript(WebResponse webResponse,
org.mozilla.javascript.Script script)
Cache a parsed script
|
Object |
callFunction(HtmlPage htmlPage,
org.mozilla.javascript.Function function,
org.mozilla.javascript.Context context,
org.mozilla.javascript.Scriptable scope,
org.mozilla.javascript.Scriptable thisObject,
Object[] args)
Calls the given function taking care of synchronization issues.
|
Object |
callFunction(HtmlPage htmlPage,
Object javaScriptFunction,
Object thisObject,
Object[] args,
DomNode htmlElement)
Call a JavaScript function and return the result.
|
org.mozilla.javascript.Script |
compile(HtmlPage htmlPage,
String sourceCode,
String sourceName,
int startLine)
Compiles the specified javascript code in the context of a given html page.
|
Object |
execute(HtmlPage htmlPage,
org.mozilla.javascript.Script script)
Execute the specified javascript code in the context of a given html page.
|
Object |
execute(HtmlPage htmlPage,
String sourceCode,
String sourceName,
int startLine)
Execute the specified javascript code in the context of a given html page.
|
org.mozilla.javascript.Script |
getCachedScript(WebResponse webResponse)
Get the cached script for the given response.
|
protected org.apache.commons.logging.Log |
getLog()
Return the log object for this class
|
static org.apache.commons.logging.Log |
getScriptEngineLog()
Return the log object that is being used to log information about the script engine.
|
static long |
getTimeout()
Returns the number of milliseconds a script is allowed to execute before
being terminated.
|
WebClient |
getWebClient()
Return the web client that this engine is associated with.
|
void |
initialize(WebWindow webWindow)
Perform initialization for the given webWindow
|
boolean |
isScriptRunning()
Indicates if JavaScript is running in current thread.
|
String |
preProcess(HtmlPage htmlPage,
String sourceCode,
String sourceName,
HtmlElement htmlElement)
Pre process the specified source code in the context of the given page using the processor specified
in the webclient.
|
static void |
setTimeout(long timeout)
Set the number of milliseconds a script is allowed to execute before
being terminated.
|
public static final String KEY_STARTING_SCOPE
public JavaScriptEngine(WebClient webClient)
webClient
- The webClient that will own this engine.public final WebClient getWebClient()
public void initialize(WebWindow webWindow)
webWindow
- the web window to initialize forprotected org.apache.commons.logging.Log getLog()
public org.mozilla.javascript.Script compile(HtmlPage htmlPage, String sourceCode, String sourceName, int startLine)
htmlPage
- The page that the code will execute withinsourceCode
- The javascript code to execute.sourceName
- The name that will be displayed on error conditions.startLine
- the line at which the script source startspublic Object execute(HtmlPage htmlPage, String sourceCode, String sourceName, int startLine)
htmlPage
- The page that the code will execute withinsourceCode
- The javascript code to execute.sourceName
- The name that will be displayed on error conditions.startLine
- the line at which the script source startspublic Object execute(HtmlPage htmlPage, org.mozilla.javascript.Script script)
htmlPage
- The page that the code will execute withinscript
- the script to executepublic Object callFunction(HtmlPage htmlPage, Object javaScriptFunction, Object thisObject, Object[] args, DomNode htmlElement)
htmlPage
- The pagejavaScriptFunction
- The function to call.thisObject
- The this object for class method calls.args
- The list of arguments to pass to the function.htmlElement
- The html element that will act as the context.public Object callFunction(HtmlPage htmlPage, org.mozilla.javascript.Function function, org.mozilla.javascript.Context context, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable thisObject, Object[] args)
htmlPage
- the html page that caused this script to executedfunction
- the js function to executecontext
- the context in which execution should occurscope
- the execution scopethisObject
- the 'this' objectargs
- the function's argumentspublic boolean isScriptRunning()
true
if JavaScript is running.public static void setTimeout(long timeout)
timeout
- the timeout valuepublic static long getTimeout()
public static org.apache.commons.logging.Log getScriptEngineLog()
public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, HtmlElement htmlElement)
WebClient
. If no pre processor handler is defined, the original source code is returned
unchanged.htmlPage
- The pagesourceCode
- The code to process.sourceName
- A name for the chunk of code. This will be used in error messages.htmlElement
- The html element that will act as the context.ScriptPreProcessor
public org.mozilla.javascript.Script getCachedScript(WebResponse webResponse)
webResponse
- the response corresponding to the script codepublic void cacheScript(WebResponse webResponse, org.mozilla.javascript.Script script)
webResponse
- the response corresponding to the script code. A weak reference to this object
will be used as key for the cache.script
- the parsed script to cacheCopyright © 2002-2012 Gargoyle Software Inc.. All Rights Reserved.