javax.script

How to use ScriptEngineManager in Android?

余生长醉 提交于 2019-12-10 08:00:29
问题 import android.widget.Toast; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public void bEqual(View v) throws ScriptException { ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName("JavaScript"); String value = inputText.getText().toString(); Toast.makeText(this,value,Toast.LENGTH_LONG).show(); try{ result = (double)engine.eval(value); Toast.makeText(this,String.format("%f",result),Toast

Rhino load() function available in JavaScript provided by javax.script?

六月ゝ 毕业季﹏ 提交于 2019-12-10 04:09:58
问题 Some JavaScript files that have been developed for Rhino's shell use load() to load additional JavaScript files. I'm attempting to embed functionality from one of these Rhino JavaScript files using javax.script. Unfortunately, the load() function is not implemented by javax.script's JavaScript. When attempting to eval() a script containing load(), the following error occurs: com.sun.script.javascript.RhinoScriptEngine:-1:in `eval': javax.script.ScriptException: sun.org.mozilla.javascript

sqlite3 module for Jython

若如初见. 提交于 2019-12-07 03:01:12
问题 I'm using Java Scripting API to execute some external Python scripts from my Java application. The python scripts use sqlite3 module. Execution of the application is resulting in error ImportError: No module named sqlite3 As I look into the Lib directory(which is in the classpath) of Jython, there's no sqlite3 module. Hence, my search begins and I found one _sqlite3.py file which is an implementation of javasqlite (http://bugs.jython.org/issue1682864). It's use produced more similar kind of

sqlite3 module for Jython

回眸只為那壹抹淺笑 提交于 2019-12-05 08:06:14
I'm using Java Scripting API to execute some external Python scripts from my Java application. The python scripts use sqlite3 module. Execution of the application is resulting in error ImportError: No module named sqlite3 As I look into the Lib directory(which is in the classpath) of Jython, there's no sqlite3 module. Hence, my search begins and I found one _sqlite3.py file which is an implementation of javasqlite ( http://bugs.jython.org/issue1682864 ). It's use produced more similar kind of errors. Then I searched the original python's sqlite3 package(original directory) from the python's

Rhino load() function available in JavaScript provided by javax.script?

别等时光非礼了梦想. 提交于 2019-12-05 04:48:37
Some JavaScript files that have been developed for Rhino's shell use load() to load additional JavaScript files. I'm attempting to embed functionality from one of these Rhino JavaScript files using javax.script. Unfortunately, the load() function is not implemented by javax.script's JavaScript. When attempting to eval() a script containing load(), the following error occurs: com.sun.script.javascript.RhinoScriptEngine:-1:in `eval': javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "load" is not defined. Does javax.script provide a for the load()

How can I specify my own Rhino context in Java?

﹥>﹥吖頭↗ 提交于 2019-12-02 01:01:29
I'm trying to ensure that my Rhino scripts (running under Java 6) are strict so that if a script developer misspells an expression I want an exception to be thrown. Currently what happens is the expression simply evaluates to "undefined". Now according to Mozilla org https://developer.mozilla.org/en/New_in_Rhino_1.6R6 there are features to enable strict checking in the context. I cannot find a working example of this. What I did so far was write a class to extend ContextFactory and then override the hasFeature method. public class ScriptContextFactory extends ContextFactory { protected boolean

Converting a Javascript array to a Java array

一世执手 提交于 2019-12-01 21:27:11
I'm trying to convert a Javascript array in Java to a Java array. I'm using the javax.script package. I tested this example here, but the type "NativeArray" was not recognized: https://stackoverflow.com/a/1433489/975097 How can I get the NativeArray type to be recognized? maerics Per this answer it looks like your best bet is to write a JavaScript converter function which transforms the native JavaScript array into a Java array using Rhino's Java binding functionality . Note that you'll have to take some care to use the correct type when converting the individual elements. [Edit] Here's a

Trying to use Rhino, getEngineByName(“JavaScript”) returns null in OpenJDK 7

做~自己de王妃 提交于 2019-11-30 16:39:55
问题 When I run the following piece of code, the engine variable is set to null when I'm using OpenJDK 7 ( java-7-openjdk-i386 ). import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class TestRhino { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); try { System.out

Can I create a 'window' object for javascript running in the Java6 Rhino Script Engine

走远了吗. 提交于 2019-11-30 05:11:44
问题 I want to run some Javascript on my Java6 server - i.e. using the javax.script API, specifically the Rhino Script Engine. (Although another solution would be acceptable) The script file is created & supported by a third party, so I don't want to download it and edit it in case it changes over time. The script directly references the 'window' object ( and probably the 'document' object etc. ) which Rhino does not seem to support. Can I do this, and if so, how? 回答1: var window = {} var document

Calling Python from Java through scripting engine (jython)?

戏子无情 提交于 2019-11-30 02:48:15
I'm trying to call Jython from a Java 6 application using javax.script : import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class jythonEx { public static void main (String args[]) throws ScriptException { ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine pyEngine = mgr.getEngineByName("python"); try { pyEngine.eval("print \"Python - Hello, world!\""); } catch (Exception ex) { ex.printStackTrace(); } } } This is causing a NullPointerException: java.lang.NullPointerException at jythonEx.main(jythonEx.java:12)