org.nanoko.coffee.mill.utils
Class RhinoLauncher

java.lang.Object
  extended by org.nanoko.coffee.mill.utils.RhinoLauncher

public class RhinoLauncher
extends Object


Nested Class Summary
static class RhinoLauncher.ScriptLoader
           
 
Method Summary
 RhinoLauncher addClientSideEnvironment()
          Add a client side environment to the script context (client-side aware).
 RhinoLauncher addJSON()
           
 RhinoLauncher addRequire(String streamroot)
          Add an equivalent to the require method from node in for Rhino.
 Object evaluate(Reader reader, String sourceName)
          Evaluates a script from a reader.
 Object evaluate(String script, String sourceName)
          Evaluates a script.
 RhinoLauncher evaluateChain(InputStream stream, String sourceName)
          Evaluates a script and return RhinoLauncher for a chained script evaluation.
 RhinoLauncher evaluateChain(String script, String sourceName)
          Evaluates a script and return RhinoLauncher for a chained script evaluation.
 org.mozilla.javascript.ScriptableObject getScope()
           
static RhinoLauncher newChain()
           
static RhinoLauncher newChain(org.mozilla.javascript.ScriptableObject scope)
           
static RhinoLauncher newClientSideAwareChain()
           
static String toJSMultiLineString(String data)
          Transforms a java multi-line string into javascript multi-line string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getScope

public org.mozilla.javascript.ScriptableObject getScope()
Returns:
the context

addClientSideEnvironment

public RhinoLauncher addClientSideEnvironment()
Add a client side environment to the script context (client-side aware).

Returns:
RhinoLauncher used to chain evaluation of the scripts.

addJSON

public RhinoLauncher addJSON()

addRequire

public RhinoLauncher addRequire(String streamroot)
Add an equivalent to the require method from node in for Rhino.

Returns:
RhinoLauncher used to chain evaluation of the scripts.
Throws:
IOException

evaluateChain

public RhinoLauncher evaluateChain(InputStream stream,
                                   String sourceName)
                            throws IOException
Evaluates a script and return RhinoLauncher for a chained script evaluation.

Parameters:
stream - InputStream of the script to evaluate.
sourceName - the name of the evaluated script.
Returns:
RhinoLauncher chain with required script evaluated.
Throws:
IOException - if the script couldn't be retrieved.

evaluateChain

public RhinoLauncher evaluateChain(String script,
                                   String sourceName)
Evaluates a script and return RhinoLauncher for a chained script evaluation.

Parameters:
script - the string representation of the script to evaluate.
sourceName - the name of the evaluated script.
Returns:
evaluated object.
Throws:
IOException - if the script couldn't be retrieved.

evaluate

public Object evaluate(Reader reader,
                       String sourceName)
                throws IOException
Evaluates a script from a reader.

Parameters:
reader - Reader of the script to evaluate.
sourceName - the name of the evaluated script.
Returns:
evaluated object.
Throws:
IOException - if the script couldn't be retrieved.

evaluate

public Object evaluate(String script,
                       String sourceName)
Evaluates a script.

Parameters:
script - string representation of the script to evaluate.
sourceName - the name of the evaluated script.
Returns:
evaluated object.
Throws:
IOException - if the script couldn't be retrieved.

newChain

public static RhinoLauncher newChain()
Returns:
default RhinoLauncher for script evaluation chaining.

newChain

public static RhinoLauncher newChain(org.mozilla.javascript.ScriptableObject scope)

toJSMultiLineString

public static String toJSMultiLineString(String data)
Transforms a java multi-line string into javascript multi-line string. This technique was found at http://stackoverflow.com/questions/805107/multiline-strings-in-javascript/

Parameters:
data - a string containing new lines.
Returns:
a string which being evaluated on the client-side will be treated as a correct multi-line string.

newClientSideAwareChain

public static RhinoLauncher newClientSideAwareChain()
Returns:
default RhinoLauncher for script evaluation chaining.


Copyright © 2012-2013 OW2. All Rights Reserved.