rhino

removing dependancy of a private function inside a public function using Rhino Mocks

Hi All, I am new to mocking, and have started with Rhino Mocks. My scenario is like this..in my class library i have a public function and inside it i have a private function call, which gets output from a service.I want to remove the private function dependency. public class Employee { public virtual string GetFullN...

Is there "native" support for JSON in JDK6 Script Engine?

I'm using JDK6the standard Scripting. I need to store and retrieve some JavaScript Objects that also contain Java Objects to JSON. I loaded the json2.js into the ScriptENgine and can use it fine without issue if the objects are all created in the Scrip Engine. The moment I try to use my own Java classes, I get some errors like "objec...

JavaScript window object element properties

A coworker showed me the following code and asked me why it worked. <span id="myspan">Do you like my hat?</span> <script type="text/javascript"> var spanElement = document.getElementById("myspan"); alert("Here I am! " + spanElement.innerHTML + "\n" + myspan.innerHTML); </script> I explained that a property is attached to the window ob...

Quick Look at Objects in Rhino Shell (PHP var_dump equivalent?)

Is there a better way of debugging in Rhino than typing this everytime? : for (prop in obj) { print("obj[" + prop + "] = " + obj[prop]); }; Update: To be clear, my question is whether there are any existing standard practices/modules/tricks on this topic. ...

How can I pass a javaScript function to a Java Method to act as a callback (Rhino)

Hi everyone, Basically I'm trying to pass a javaScript function to a Java method to act as a callback to the script. I can do it - sort of - but the object I receive is a sun.org.mozilla.javascript.internal.InterpretedFunction and I don't see a way to invoke it. Any ideas? Here's what I have so far: var someNumber = 0; function st...

Replace <Unknown Source> in Java Rhino (JSR223) with actual file name

Hello everyone, In my code, all of the scripts are contained in .js files. Whenever one of the scripts contains an error, I get this: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "nonexistant" is not defined. (<Unknown source>#5) in <Unknown source> at line number 5 What bugs me is the <...

Filtering in E4X

This is just a simple question. I'm currently using Mozilla's Rhino to develop a little webapp. As one step, I need to get a webpage and filter all of it's nodes. For doing that, I use E4X. I thought I could do this like that: var pnodes = doc..*(p); But that produces an error. How is it done right? (BTW: this is just a step for incr...

Rhino - Set FEATURE_LOCATION_INFORMATION_IN_ERROR in code?

I'd like fileName, lineNumber and stack traces to automatically be provided by Rhino for any errors. I've been told that I need to set FEATURE_LOCATION_INFORMATION_IN_ERROR on the current context, but I'm not sure how to do this in code. Does anybody have an example of turning this feature on so that I can see stacktrace dumps on crash...

Fix internal links in JS

I just created a script which extracts the article out of a webpage via server-side JS. (If your interested: it's used for http://pipes.yahoo.com/fb55/expandr .) I just got a little problem with internal links. Some pages include links like: /subfolder/subpage.html What I would need to do is fixing them and setting there root, like t...

I want to run remote javascript on my server.

Hi, I've had a search and come up with Rhino and Jaxer is possible solutions, but wanted to put the queston out there anyway as I'm not sure they're quite what I'm after (especially if I have no control over the javascript, so I'm unable to add runat="server" for example). So, I want to call a remote page on a 3rd party site, from my s...

Trouble using 'eval' to define a toplevel function when called from within an object.

I've written (in JavaScript) an interactive read-eval-print-loop that is encapsulated within an object. However, I recently noticed that toplevel function definitions specified to the interpreter do not appear to be 'remembered' by the interpreter. After some diagnostic work, I've reduced the core problem to this: var evaler = { ...

Why is Rhino unhappy with this javascript?

I have been successfully using my code with the javascript library in the ANTLR javascript target in a few browsers, but now I want to use Rhino on the server and I am having some trouble. I have some simple java code that references the Rhino 1.7R2 release's js-14.jar file. Context context = Context.enter(); Scriptable scope = context...

Rhino Mocks verify a private method is called from a public method

I have been trying to figure this one out, how do i test that a private method is called with rhino mocks with in the class that I am testing. So my class would be something like this. Public class Foo { public bool DoSomething() { if(somevalue) { //DoSomething; } else { Rep...

Rhino, adding code from multiple javascript files

Hi, I am embedding some javascript in a Java application using Rhino. I am following the example on the Rhino website, executing a script by calling the Context's evaluateString method and passing the actual script in as a String. I have a whole bunch of existing javascript code that I would like to make use of. I don't want to concaten...

Scripting java : Create a class in a script file

Hello, I want to create a java class in a script file (javax.script). please help ...

How to create a 'real' JavaScript array in Rhino

Okay, I'm a little stumped. I'm probably missing something blatantly obvious but apparently I just can't see the forest for the trees: I'm trying to call a JavaScript function that expects its parameter to be an array, i.e. it checks if (arg instanceof Array)... Unfortunately, I (or Rhino) just can't seem to create such an array: Con...

Scripting java : import a class from an external file

I want to import a class that I already write in an external folder, for example : My class Example.java that is located in c:\class\Example.java to my script like using var importedClass = new JavaImporter("c:\\class\\Example.java"); or importClass("c:\\class\\Example.java"); this is in a script for ScriptEngine rhino how can I ...

How can I create and Apache Axiom element from a E4X object from a script running in Rhino?

I am running a script running in Rhino, which creates an E4X object like this: var s = <product id="123"> <name>Google Search</name> <source>https://google.com&lt;/source&gt; </product> I want to include such XML in a SOAP message. I am using Apache Axis 2 ServiceClient for creat...

How do I build a Rhino project as a runnable JAR in Eclipse?

I have a Rhino project where I've written some .js files, and from Eclipse I start my program by calling org.mozilla.javascript.tools.shell.Main with a parameter to one of my .js files, "src/bot.js". Now, in order to run this on my server I would like to be able to build it into a single runnable JAR for easy deployment. How do I do this...

Anonymous implementation of abstract classes in Rhino

I need to implement a listener in JavaScript by anonymous subclass of an existing abstract base class, defined like this: public class Speaker { public static abstract class MyListener { private String name; public MyListener(final String name) { this.name = name; } public abstract boolean listen(final String words); } }...