Package ro.isdc.wro.extensions.script
Class RhinoScriptBuilder
java.lang.Object
ro.isdc.wro.extensions.script.RhinoScriptBuilder
Used to evaluate javascript on the serverside using rhino javascript engine.
Encapsulate and hides all implementation details used by rhino to evaluate
javascript on the serverside.
- Author:
- Alex Objelean
-
Method Summary
Modifier and TypeMethodDescriptionAdd a client side environment to the script context (client-side aware).addJSON()This method will load JSON utility and aslo a Douglas Crockford's utility required for decycling objects which would fail otherwise when using JSON.stringify.Evaluates a script from a reader.Evaluates a script.evaluateChain(InputStream stream, String sourceName) Evaluates a script and returnRhinoScriptBuilderfor a chained script evaluation.evaluateChain(String script, String sourceName) Evaluates a script and returnRhinoScriptBuilderfor a chained script evaluation.org.mozilla.javascript.ScriptableObjectgetScope()static RhinoScriptBuildernewChain()static RhinoScriptBuildernewChain(org.mozilla.javascript.ScriptableObject scope) static RhinoScriptBuilder
-
Method Details
-
getScope
public org.mozilla.javascript.ScriptableObject getScope()- Returns:
- the context
-
addClientSideEnvironment
Add a client side environment to the script context (client-side aware).- Returns:
RhinoScriptBuilderused to chain evaluation of the scripts.
-
addJSON
This method will load JSON utility and aslo a Douglas Crockford's utility required for decycling objects which would fail otherwise when using JSON.stringify. -
evaluateChain
Evaluates a script and returnRhinoScriptBuilderfor a chained script evaluation.- Parameters:
stream-InputStreamof the script to evaluate.sourceName- the name of the evaluated script.- Returns:
RhinoScriptBuilderchain with required script evaluated.- Throws:
IOException- if the script couldn't be retrieved.
-
evaluateChain
Evaluates a script and returnRhinoScriptBuilderfor a chained script evaluation.- Parameters:
script- the string representation of the script to evaluate.sourceName- the name of the evaluated script.- Returns:
- evaluated object.
-
evaluate
Evaluates a script from a reader.- Parameters:
reader-Readerof the script to evaluate.sourceName- the name of the evaluated script.- Returns:
- evaluated object.
- Throws:
IOException- if the script couldn't be retrieved.
-
evaluate
Evaluates a script.- Parameters:
script- string representation of the script to evaluate.sourceName- the name of the evaluated script.- Returns:
- evaluated object.
-
newChain
- Returns:
- default
RhinoScriptBuilderfor script evaluation chaining.
-
newChain
-
newClientSideAwareChain
- Returns:
- default
RhinoScriptBuilderfor script evaluation chaining.
-