Class RhinoScriptBuilder

java.lang.Object
ro.isdc.wro.extensions.script.RhinoScriptBuilder

public final class RhinoScriptBuilder extends Object
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 Details

    • getScope

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

      public RhinoScriptBuilder addClientSideEnvironment()
      Add a client side environment to the script context (client-side aware).
      Returns:
      RhinoScriptBuilder used to chain evaluation of the scripts.
    • addJSON

      public RhinoScriptBuilder 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

      public RhinoScriptBuilder evaluateChain(InputStream stream, String sourceName) throws IOException
      Evaluates a script and return RhinoScriptBuilder for a chained script evaluation.
      Parameters:
      stream - InputStream of the script to evaluate.
      sourceName - the name of the evaluated script.
      Returns:
      RhinoScriptBuilder chain with required script evaluated.
      Throws:
      IOException - if the script couldn't be retrieved.
    • evaluateChain

      public RhinoScriptBuilder evaluateChain(String script, String sourceName)
      Evaluates a script and return RhinoScriptBuilder 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.
    • 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.
    • newChain

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

      public static RhinoScriptBuilder newChain(org.mozilla.javascript.ScriptableObject scope)
    • newClientSideAwareChain

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