Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Embedding EnvJs - how to get the Rhino Shell functions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
woody  
View profile  
 More options Nov 17 2009, 6:54 am
From: woody <sdwood...@googlemail.com>
Date: Tue, 17 Nov 2009 03:54:37 -0800 (PST)
Local: Tues, Nov 17 2009 6:54 am
Subject: Embedding EnvJs - how to get the Rhino Shell functions
Hi All,

I've been running env js from Rhino embedded within Java for some
time.  I've had problems due to EnvJs's reliance upon functions
provided by the Rhino shell (e.g. sync, print, load etc).  I was
mocking these out myself, however after some investigation it emerges
it's dead easy to get these functions into your context created from
Java - here's what I had before :

 Context cx = ContextFactory.getGlobal().enterContext();
 // set Rhino to work in interpreted mode, i.e. don't try and
 // compile the JavaScript source into Java, some of it exceeds the
 // Java 64kb method size limit.
 cx.setOptimizationLevel(-1);
 cx.setLanguageVersion(Context.VERSION_1_5);
 Scriptable scope = cx.initStandardObjects();

And here's what I needed to change it to to get the global shell
functions :

Global global = new Global();
Context cx = ContextFactory.getGlobal().enterContext();
global.init(cx);
// set Rhino to work in interpreted mode, i.e. don't try and
// compile the JavaScript source into Java, some of it exceeds the
// Java 64kb method size limit.
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);

Scriptable scope = cx.initStandardObjects(global);

global is in org.mozilla.javascript.tools.shell.Global

The variable "scope" is the thing you want to interpret your
JavaScript files against using context.evaluateReader. e.g. having
done the above I then do :

cx.evaluateReader(scope, new FileReader("test.js"), "test.js", 1,
null);

where test.js is a file that could be  :

(function () {

    load("env-rhino.js");
    window.djConfig = {
        locale : "en_GB",
        baseUrl : "foo/dojo/"
    };

    load("path/to/foo/dojo/dojo.js");

    window.location = "test.html";

    var nl = dojo.query("div.myClass");
    print("There are "+nl.length+" divs with 'myClass'");

}) ();

Note how it uses "load" and "print" :) Hopefully this is of use to
other people trying to achieve the same thing.  Chris - i can do a
more detailed write up if you want to include in the section on the
website under the "embed" section of the docs.

cheers,
Steve.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
chris thatcher  
View profile  
 More options Nov 17 2009, 6:09 pm
From: chris thatcher <thatcher.christop...@gmail.com>
Date: Tue, 17 Nov 2009 18:09:31 -0500
Local: Tues, Nov 17 2009 6:09 pm
Subject: Re: [env-js] Embedding EnvJs - how to get the Rhino Shell functions

That would be great!

--
Christopher Thatcher

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John  
View profile  
 More options Nov 27 2009, 5:20 pm
From: John <mr.ches...@gmail.com>
Date: Fri, 27 Nov 2009 14:20:24 -0800 (PST)
Local: Fri, Nov 27 2009 5:20 pm
Subject: Re: Embedding EnvJs - how to get the Rhino Shell functions
Thanks Steve!

I'm using EnvJs in an embedded environment using the Bean Scripting
Framework (http://jakarta.apache.org/bsf/index.html) I modified my
copy of the JavaScriptEngine class that comes with BSF to include your
changes, and it works beautifully, without any changes to the app it's
embedded in :)

~John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ake Jixun  
View profile  
 More options Sep 2 2012, 8:59 pm
From: ake Jixun <levinji...@gmail.com>
Date: Sun, 2 Sep 2012 17:59:32 -0700 (PDT)
Local: Sun, Sep 2 2012 8:59 pm
Subject: Re: Embedding EnvJs - how to get the Rhino Shell functions

Hi All,

     I used the following code to execute javascript which uses
document.write to generate  html content.    I want to know whether is
there a way to get the string document.write prints and save it to a java
variable(StringBuffer or String). Thanks!

FileInputStream fis = new FileInputStream(rhinoStrFileName);
            envReader = new InputStreamReader(fis);
            FileInputStream jis = new FileInputStream(jsFilename);

            Context cx = ContextFactory.getGlobal().enterContext();
            InputStreamReader reader = new InputStreamReader(jis, "gb2312");
            Global global = new Global();
            global.init(cx);
            cx.setOptimizationLevel(-1);
            cx.setLanguageVersion(Context.VERSION_1_7);
            envGlobals = cx.initStandardObjects(global);

            cx.evaluateReader(envGlobals, envReader, rhinoStrFileName, 1,
null);
            cx.evaluateReader(envGlobals, reader, jsFilename, 1, null);

在 2009年11月17日星期二UTC-5上午6时54分37秒,woody写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »