Interface RhinoSandbox

  • All Known Implementing Classes:
    RhinoSandboxImpl

    public interface RhinoSandbox
    • Method Detail

      • allow

        RhinoSandbox allow​(Class<?> clazz)

        Will allow access to this class in Rhino scripts.

        Note that for classes in packages which don't start with java., com., net. etc. the class name needs to be prefixed with Packages.

        e.g. mypackage.Myclass will be Packages.mypackage.MyClass

        see

      • inject

        RhinoSandbox inject​(String variableName,
                            Object object)
        Will add a global variable available to all scripts executed with this sandbox.
      • inject

        RhinoSandbox inject​(Class<org.mozilla.javascript.ScriptableObject> clazz)
        Will make this class available to instantiate in Rhino scripts.
      • setInstructionLimit

        RhinoSandbox setInstructionLimit​(int limit)
        Sets the maximum instructions allowed for script execution.
      • setMaxDuration

        RhinoSandbox setMaxDuration​(int limitInMs)
        Sets the maximum allowed duration for scripts.
      • setUseSafeStandardObjects

        RhinoSandbox setUseSafeStandardObjects​(boolean useSafeStandardObject)
        If .initSafeStandardObjects should be used.
      • setUseSealedScope

        RhinoSandbox setUseSealedScope​(boolean value)
        If the global scope should be sealed (default: true).
      • evalWithGlobalScope

        Object evalWithGlobalScope​(String sourceName,
                                   String js)
        Evaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.
      • evalWithGlobalScope

        Object evalWithGlobalScope​(String sourceName,
                                   Reader js)
                            throws IOException
        Evaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.
        Throws:
        IOException
      • eval

        Object eval​(String sourceName,
                    String js)
        Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
      • callFunction

        Object callFunction​(org.mozilla.javascript.NativeFunction function,
                            Object[] args)
        executes a javascript function
        Parameters:
        function - a Native function you may got from js
        args - parameters you need to call the function
        Returns:
        the result of the javascript function
      • eval

        Object eval​(String sourceName,
                    Reader js)
             throws IOException
        Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
        Throws:
        IOException
      • eval

        Object eval​(String sourceName,
                    String js,
                    Map<String,​Object> variables)

        Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.

        variables defines variables with Java objects which will be available for the execution of this script.

      • eval

        Object eval​(String sourceName,
                    Reader js,
                    Map<String,​Object> variables)
             throws IOException

        Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.

        variables defines variables with Java objects which will be available for the execution of this script.

        Throws:
        IOException