View Javadoc

1   package delight.rhinosandox;
2   
3   import java.util.Map;
4   import org.mozilla.javascript.ScriptableObject;
5   
6   @SuppressWarnings("all")
7   public interface RhinoSandbox {
8     /**
9      * <p>Will allow access to this class in Rhino scripts.
10     * <p>Note that for classes in packages which don't start with java., com., net. etc. the class name needs to be prefixed with Packages.
11     * <p>e.g. mypackage.Myclass will be Packages.mypackage.MyClass
12     * <p><a href='https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/New_in_Rhino_1.7R1#Common_package_names_preloaded'>see</a>
13     */
14    public abstract RhinoSandbox allow(final Class<?> clazz);
15    
16    /**
17     * Will add a global variable available to all scripts executed with this sandbox.
18     */
19    public abstract RhinoSandbox inject(final String variableName, final Object object);
20    
21    /**
22     * Will make this class available to instantiate in Rhino scripts.
23     */
24    public abstract RhinoSandbox inject(final Class<ScriptableObject> clazz);
25    
26    /**
27     * Sets the maximum instructions allowed for script execution.
28     */
29    public abstract RhinoSandbox setInstructionLimit(final int limit);
30    
31    /**
32     * Sets the maximum allowed duration for scripts.
33     */
34    public abstract RhinoSandbox setMaxDuration(final int limitInMs);
35    
36    /**
37     * If .initSafeStandardObjects should be used.
38     */
39    public abstract RhinoSandbox setUseSafeStandardObjects(final boolean useSafeStandardObject);
40    
41    /**
42     * If the global scope should be sealed (default: true).
43     */
44    public abstract RhinoSandbox setUseSealedScope(final boolean value);
45    
46    /**
47     * Evaluate the given script with the global scope. That is all new global variables written will be available to all other scripts.
48     */
49    public abstract Object evalWithGlobalScope(final String sourceName, final String js);
50    
51    /**
52     * Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
53     */
54    public abstract Object eval(final String sourceName, final String js);
55    
56    /**
57     * <p>Evaluate a script with its own scope. It has access to all objects in the global scope but cannot add new ones.
58     * <p><code>variables</code> defines variables with Java objects which will be available for the execution of this script.
59     */
60    public abstract Object eval(final String soureName, final String js, final Map<String, Object> variables);
61  }