rhino

in Rhino, can I enumerate the list of available Java packages? How?

孤街醉人 提交于 2019-12-07 14:47:53
问题 I tried doing this: var r = {}; for (p in Packages) { if (Packages.hasOwnProperty(p)) { r[p] = p.toString(); } } ...But I got an error: TypeError: Invalid iterator value ... at line xx The line indicated in the error message is the one with for (p in Packages) { ... } Also, var r = { "Packages" : typeof Packages, "Packages.length" : typeof Packages.length, "Packages.java" : typeof Packages.java, "Packages.surelyThisIsNotDefined" : typeof Packages.surelyThisIsNotDefined }; results in: {

How to append xml nodes (as a string) into an existing XML Element node (only using java builtins)?

时光毁灭记忆、已成空白 提交于 2019-12-07 10:07:00
问题 (Disclaimer: using Rhino inside RingoJS) Let's say I have a document with an element , I don't see how I can append nodes as string to this element. In order to parse the string to xml nodes and then append them to the node, I tried to use documentFragment but I couldn't get anywhere. In short, I need something as easy as .NET's .innerXML but it's not in the java api. var dbFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); var dBuilder = dbFactory.newDocumentBuilder(); var doc

Android, Javascript, Rhino, JSON

不问归期 提交于 2019-12-06 15:46:26
After long search in repo folders I found rhino1_7R2.jar for Android at http://code.google.com/p/android-scripting/source/browse/rhino/rhino1_7R2.jar Unfortunately 1_7R3 is not there. The script I'm using uses JSON.stringify function which is not present in 1_7R2. There is the JSON2.js file for Rhino but I don't know the proper way to load it at run time. Documentation and example codes are weak. Should I load it as a string and prepend on the running script? Or there is a better way? I'm using JavaScript to dynamically evaluate some calculations in a loop. I really want to avoid prepending

Dojo not getting loaded into rhino emmbedded in java

谁都会走 提交于 2019-12-06 15:34:49
I'm trying to render the dojo charts server side. I came across the Rhino and envjs for server side browser emulation. when I tried to an example program to load the dojo.js in the rhino embedded in the java impl, the exception is thrown, Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.EcmaError: ReferenceError: "location" is not defined. (#15) in at line number 15. My code is as follows: import javax.script.*; import java.io.*; public class Java6RhinoRunner { public static void main(String[] args) throws ScriptException { new Java6RhinoRunner().load(args[0]

Anchor element's pathname returns undefined in Rhino with env.js

拥有回忆 提交于 2019-12-06 11:10:56
问题 I have run into an issue that I believe is rooted in the implementation of anchor tags in Rhino. Although I am utilizing env.js, I suspect perhaps I am not configuring something correctly. In particular, my issue occurs while I am attempting to write unit tests against code written for an angularjs application. When I include angular.js (versions 1.2.1 to present), I get the following error: TypeError: Cannot call method "charAt" of undefined I am convinced the error is the result of this

sun.org.mozilla.javascript.internal.NativeObject vs org.mozilla.javascript.NativeObject

微笑、不失礼 提交于 2019-12-06 10:26:03
I am really stuck at this now.. Essentially I have a Java Map, which I would like to pass it to a Javascript Code, so that in my JS code I can use dot notation to refer the keys in this Map. ( I know I can serialize the map into JSON and deserialize it back and pass it into JS, but I don't like that ) I have this piece of the unit code @Test public void mapToJsTest() throws Exception{ Map m = Maps.newHashMap(); m.put("name", "john"); NativeObject nobj = new NativeObject(); for (Object k : m.keySet()) { nobj.defineProperty((String)k, m.get(k), NativeObject.READONLY); } engine.eval("function

JavaScript engine for Java

狂风中的少年 提交于 2019-12-06 09:20:35
Currently I'm using Rhino in my application. I need to eval some JavaScript ant get values from it (I don't need to use Java classes through JavaScript). But it is too slow. Maybe there are any ways to use V8 with Java application? Update: I have a large collection of objects of different types. I need a flexible mechanism for validation and transformation these objects to the required form (the user should be able to change the rules of validation and transformation (in runtime), ie hardcoding these rules in Java not suitable). Now everything works on Rhino, but performance is bad. I thought

Rhino.Security and IEntityInformationExtractor

强颜欢笑 提交于 2019-12-06 08:00:45
I've recently downloaded Rhino.Security and I am trying to implement permissions on a entity. Since I like Ninject (v2) I would like to put together a simple example to start with. In my NinjectModule I've bound the repository and the services: Bind<ISessionFactory>() .ToProvider(new SessionFactoryProvider()) .InSingletonScope(); Bind<ISession>().ToProvider(new SessionProvider()) .InSingletonScope(); Bind<IAuthorizationRepository>() .To<AuthorizationRepository>() .InSingletonScope(); Bind<IPermissionsService>() .To<PermissionsService>() .InSingletonScope(); Bind<IAuthorizationService>() .To

Different result from JavaScript RegExp in “rhino1.7.6” vs “V8”

三世轮回 提交于 2019-12-06 07:16:52
currently, I found the same JavaScript RegExp might generate different result in different JavaScript Engines, here is an example: In Chrome V8 JS engine, /\x3c/.test("\x3c") --> returns true /\x3c/.test(function() { return "\x3c" }) -->returns ***false*** In rhino1.7.6,I typed the command like this: >java -jar js.jar Rhino 1.7.6 2015 04 15 js> /\x3c/.test(function() { return "\x3c" }) true js> And I tested these two: /\x3c/.test("\x3c") --> returns true /\x3c/.test(function() { return "\x3c" }) -->returns ***true*** I am wondering why these two engines generate different result. I believe

如何在另一个JavaScript文件中包含一个JavaScript文件?

本小妞迷上赌 提交于 2019-12-06 01:54:01
JavaScript中是否有类似于CSS中 @import 的内容,可让您在另一个JavaScript文件中包含一个JavaScript文件? #1楼 而不是在运行时添加,而是使用脚本在上传之前进行串联。 我使用 链轮 (我不知道是否还有其他 链轮 )。 您将JavaScript代码构建在单独的文件中,并包含由Sprockets引擎处理的注释(包括)。 对于开发,您可以依次包含文件,然后在生产中将它们合并... 也可以看看: Sprockets简介:JavaScript依赖关系管理和串联 #2楼 如果有人在寻找更高级的东西,请尝试 RequireJS 。 您将获得更多好处,例如依赖管理,更好的并发性,并避免重复(也就是说,多次检索脚本)。 您可以在“模块”中编写JavaScript文件,然后在其他脚本中将它们作为依赖项引用。 或者,您可以将RequireJS用作简单的“获取此脚本”解决方案。 例: 将依赖项定义为模块: some-dependency.js define(['lib/dependency1', 'lib/dependency2'], function (d1, d2) { //Your actual script goes here. //The dependent scripts will be fetched if necessary. return