-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunAndroidScriptEngine.java
45 lines (28 loc) · 1.07 KB
/
RunAndroidScriptEngine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
public class RunAndroidScriptEngine {
private static Context cx;
private static void init()
{
cx = Context.enter();
cx.setOptimizationLevel(-1);
}
public static Boolean runProcess(String functionName,String script ,Object[] parametros ) throws Exception
{
if(script==null)
throw new Exception("Script null");
if(script.equals(""))
throw new Exception("Script vacio");
init();
Scriptable scope = cx.initStandardObjects();
ScriptableObject.putProperty(
scope, "javaContext", Context.javaToJS(new ProcesadorUtil(), scope));
// Evaluate the script.
cx.evaluateString(scope, script, "ScriptAPI", 1, null);
Function function = (Function) scope.get(functionName, scope);
Boolean resultado = (Boolean) function.call(cx, scope, scope, parametros);
return resultado;
}
}