javax.script

Calling Python from Java through scripting engine (jython)?

僤鯓⒐⒋嵵緔 提交于 2020-01-28 18:26:46
问题 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

Calling Python from Java through scripting engine (jython)?

℡╲_俬逩灬. 提交于 2020-01-28 18:26:08
问题 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

Java ScriptEngine (nashorn & rhino) : how to stack scopes / bindings?

放肆的年华 提交于 2020-01-04 17:54:47
问题 I have to port a software using Rhino1.7R4 and its org.mozilla.javascript package to use the javax.script package and its ScriptEngine ( Rhino in Java 6 & 7, Nashorn in Java 8). The main problem is to stack scopes (Bindings). Using the Rhino jar, I do: Scriptable scope ... Scriptable newScope = javascriptContext.initStandardObjects(); newScope.setParentScope(scope); So if a variable is defined without var, it's a global variable (root scope) if a variable is defined with var, it's a local

Evaluating a string holding a logic operation as a Boolean in java

白昼怎懂夜的黑 提交于 2019-12-25 09:17:36
问题 I am trying to evaluate "in1 && in2" to a Boolean as a test, but i hope to be able to evaluate all booleans as stings for my actual project. in1 and in2 are the names of nodes that have a boolean state, i get the actual expression like so, logic = logic.replaceAll(curName, (nodes.get(ins.get(j)).getState() ? "true" : "false")); logic is the string contacting the logic i want evaluated, curname is the current node name being replaced with its boolean("in1" for example) its in a loop so all

How do I secure scripts run using javax.scripting?

安稳与你 提交于 2019-12-20 18:35:14
问题 I am using javax.scripting to add support for running arbitrary user-uploaded JavaScripts on the server-side. Obviously I want to secure those scripts! Rhino, on it's own, has a framework for securing scripts at runtime. The documentation for javax.scripting , however, doesn't mention security, permissions or restricting classes available to the script. So is this just a huge hole in the javax.scripting API that it doesn't offer a framework to secure scripts it executes? I don't want to use

How do I secure scripts run using javax.scripting?

喜欢而已 提交于 2019-12-20 18:35:00
问题 I am using javax.scripting to add support for running arbitrary user-uploaded JavaScripts on the server-side. Obviously I want to secure those scripts! Rhino, on it's own, has a framework for securing scripts at runtime. The documentation for javax.scripting , however, doesn't mention security, permissions or restricting classes available to the script. So is this just a huge hole in the javax.scripting API that it doesn't offer a framework to secure scripts it executes? I don't want to use

How can I specify my own Rhino context in Java?

徘徊边缘 提交于 2019-12-20 03:32:09
问题 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

Converting a Javascript array to a Java array

﹥>﹥吖頭↗ 提交于 2019-12-20 02:35:13
问题 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? 回答1: 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

Converting a Javascript array to a Java array

不羁的心 提交于 2019-12-20 02:35:08
问题 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? 回答1: 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

Why does getEngineByName(“js”) return null?

拥有回忆 提交于 2019-12-11 04:04:14
问题 Whatever I try, getEngineByName() keeps returning null. Here's my code: final ScriptEngineManager manager = new ScriptEngineManager(); final ScriptEngine engine = manager.getEngineByName("js"); But engine is null after these lines. I also tried: getEngineByName("javascript") getEngineByName("nashorn") They all return null . Actually, manager.getEngineFactories() shows an empty array - meaning there are no Factories at all. These 2 answers suggest passing null to the constructor, but it didn't