rhino

JavaScript (Rhino) use library or include other scripts

泪湿孤枕 提交于 2019-12-18 10:51:11
问题 In JDK6, is there a way to load multiple scripts, each in a file, and have the one script reference a method of another script? Sort of like "include"? 回答1: I think you're after the load() method/property of Rhino's global object/scope load("file1.js"); load("file2.js"); load("file3.js"); methodFromFileOne(); var bar = methodFromFileTwo(); var etc = dotDotDot(); This will load a javascript source file, similar to how include/require will in PHP. Once you load a file, you'll be able to call

nServiceBus, Rhino Service Bus, MassTransit - Videos, Demos, Learning Resources

空扰寡人 提交于 2019-12-18 10:16:52
问题 Hey people would love to hear about any resources you have or know about for nServiceBus, Rhino Service Bus and MassTransit. Videos? Blog posts? Books? Demo Projects etc 回答1: The discussion group at Google Groups is a very good resource. So far I have written three articles about nServiceBus at ArtOfBabel.com: Open Source Integration with nServiceBus Up and Running with nServiceBus 1.9 nServiceBus: Building the Solution A few more articles should be available soon too. 回答2: If you are

Instantiating Rhinoscript Native Objects from Java/Scala

一笑奈何 提交于 2019-12-18 09:24:46
问题 I'm trying to improve the performance of a javascript snippet evaluator . These script snippets can reference any number of variables that exist in a string-keyed map of json-like object graphs (IE: Json AST). I'm using JDK 1.6 and the embedded Rhinoscript engine (v1.6R2). Currently, processing takes the form: Snippet is parsed to discover the names of referenced variables Variables are retrieved from the map and serialized to a json string Json string is assigned to a similarly named

testing an internal class

社会主义新天地 提交于 2019-12-17 19:47:13
问题 how to write unit tests to internal classes ??? 回答1: You write tests which specify the behaviour of the top-level class' external interface. Whether that class uses internal classes to implement that behaviour or not, is an implementation detail of the class, and the tests don't need to know anything about it. If the internal class cannot be adequately tested through the top-level class' interface, then it's usually best to move the internal class out and test it directly as a new top-level

ReferenceError: “alert” is not defined

◇◆丶佛笑我妖孽 提交于 2019-12-17 19:34:07
问题 I am trying to call a java script function from java code. Here is my Java code public static void main(String[] args) throws FileNotFoundException { try { /** * To call a anonymous function from java script file */ ScriptEngine engine = new ScriptEngineManager() .getEngineByName("javascript"); FileReader fr = new FileReader("src/js/MySpec.js"); engine.eval(fr); } catch (ScriptException scrEx) { scrEx.printStackTrace(); } } Here is my java script file: (function() { alert("Hello World !!!");

How can I add methods from a Java class as global functions in Javascript using Rhino?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 18:37:47
问题 I have a simple Java class that has some methods: public class Utils { public void deal(String price, int amount) { // .... } public void bid(String price, int amount) { // .... } public void offer(String price, int amount) { // .... } } I would like to create an instance of this class and allow the Javascript code to call the methods directly, like so: deal("1.3736", 100000); bid("1.3735", 500000); The only way I could figure out for now was to use ScriptEngine engine = new

Rhino: How to call JS function from Java

本秂侑毒 提交于 2019-12-17 17:36:48
问题 I'm using Mozilla Rhino 1.7r2 (not the JDK version), and I want to call a JS function from Java. My JS function is like this: function abc(x,y) { return x+y } How do I do this? Edit: (The JS function is in a separate file) 回答1: String script = "function abc(x,y) {return x+y;}"; Context context = Context.enter(); try { ScriptableObject scope = context.initStandardObjects(); Scriptable that = context.newObject(scope); Function fct = context.compileFunction(scope, script, "script", 1, null);

ANT script to compile all (css) LESS files in a dir and subdirs with RHINO

淺唱寂寞╮ 提交于 2019-12-17 15:44:59
问题 I want do compile all *.less scripts in a specific folder and it subdirs with less-rhino-1.1.3.js . There is an example on github for doing this for a specific file, which works perfect. But I want to do the same for a complete folder. I tried a lot, here is my last try. It doesn't work, propertyregex seems not to be standard ANT, I don't want to use such things. I am not even sure if this code would work. <project name="test" default="main" basedir="../../"> <property name="css.dir" location

Call external javascript functions from java code

被刻印的时光 ゝ 提交于 2019-12-17 04:20:22
问题 By using Java Scripting API, I am able to execute JavaScript within Java. However, can someone please explain what I would need to add to this code in order to be able to call on functions that are in C:/Scripts/Jsfunctions.js import javax.script.*; public class InvokeScriptFunction { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); // JavaScript code in a String

How can I provide a pseudo file system for r.js?

一个人想着一个人 提交于 2019-12-14 04:00:01
问题 Ok, so r.js can run on Rhino. Which is great. To do the stuff it needs to do. On rhino it basically uses java.io.File , java.io.FileOutputStream and java.io.FileInputStream to achieve the filesystem modifications that it needs to do. (Background: I am working on delivering a better development experience for Maven based Java/Javascript developers. Being Maven, there is the power of convention and the power of being opinionated. You can see the progress at jszip.org.) So what I want to do is