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
Loading Scripts in the Env
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
  11 messages - 10 new - 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
 
Thatcher  
View profile  
 More options Oct 6 2008, 11:06 pm
From: Thatcher <thatcher.christop...@gmail.com>
Date: Mon, 6 Oct 2008 20:06:34 -0700 (PDT)
Local: Mon, Oct 6 2008 11:06 pm
Subject: Loading Scripts in the Env
I'd like to suggest that the something along the lines of the
following be added to the windows 'location' setter:

xhr.onreadystatechange = function(){
..
    scripts =  document.getElementsByTagName('script');
    for(i=0;i<scripts.length;i++){
           script = scripts[i];
            try{
                load(script.attributes['src']);
            }catch(e){
                print(e);
            }
    }
..

the reason being that I'd like the Env.js to load the javascript so I
can easily run and include the files of my choosing, the same way I
would in a browser. The above example is obviously a little naive
since it doesnt bother to look at the type of script.

To be a little more needy I'd actually like a little more control of
the initialization of the Env.js window, so that I could perhaps
specify a callback to override the default script loading strategy
with one of my own so that I can easily implement Jaxer like behavior.

I already do this, but have to modify env.js each time it loads up.

Any thoughts here?

PS I do have some Java I've written to integrate env.js into Tomcat or
Jetty and do Jaxer like stuff on the server.  The code is a little
specific to the particular project I've been developing, but it might
make more sense to generalize it by discussion in this group, and
contribute it to the Env project.

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.
KamBha  
View profile  
 More options Oct 14 2008, 3:37 am
From: KamBha <kamal.bh...@gmail.com>
Date: Tue, 14 Oct 2008 00:37:52 -0700 (PDT)
Local: Tues, Oct 14 2008 3:37 am
Subject: Re: Loading Scripts in the Env
Is there such a thing as a load function in an embedded environment?
Last time I played with a load function using embedded Rhino, I got
nothing. If you are using load in an embedded environment, can someone
give me some pointers as to what I did wrong? I did end up finding a
way of creating a load function, but it involved me revealing the
Context object to script and it became all rather sinister.

On Oct 7, 2:06 pm, Thatcher <thatcher.christop...@gmail.com> wrote:


 
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 Oct 14 2008, 10:25 am
From: "chris thatcher" <thatcher.christop...@gmail.com>
Date: Tue, 14 Oct 2008 10:25:32 -0400
Local: Tues, Oct 14 2008 10:25 am
Subject: Re: Loading Scripts in the Env

This is how I create my shell, which is in turn used but my servlet
enviromnent.  As you can see I used to inject the xhr implementation but now
I use the one provided by env.  Note I also chose to expose three built in
rhino methods, load, print, and runCommand(which does nothing right now).  I
also added an implementation of a FileListener so I could start the servlet
container and change my js without having to restart the container.

Hope this helps.  I think I based this off an example I found on the web
googling arround.

Thatcher

package claypool.continuation;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

import org.mozilla.javascript.*;

public class Shell extends ScriptableObject implements FileListener{

    private Context cx;
    private String basePath;
    private FileMonitor monitor = new FileMonitor (3000);

    public Shell(String basePath) {
        this.basePath = basePath;

        cx = Context.enter();
        cx.initStandardObjects(this);

        // host objects --------------

        // Give easy access to the global object by making a global property
named "global".
        // This is the same as how "window" is used in browser scripting.
        defineProperty("global", this, ScriptableObject.DONTENUM);
        defineProperty("window", this, ScriptableObject.DONTENUM);
        defineProperty("cwd", basePath, ScriptableObject.DONTENUM);

        // global functions
        String[] names = {"load", "print", "runCommand"};
        defineFunctionProperties(names, Shell.class,
ScriptableObject.PERMANENT);
        //Add the XMLHttpRequest Implementation
        //JsXMLHttpRequest.register(this);
        //JsSimpleDomNode.register(this);

        monitor.addListener(this);
    }

    public String getClassName() {
        return "global";
    }

    public Context getContext() {
        return cx;
    }

    public static void print(String msg){
        System.out.println(msg);
    }
    public static void runCommand(String command){
        //TODO
        return;
    }
    /**
     * Load and execute a set of JavaScript source files.
     *
     * This method is defined as a JavaScript function.
     */
    public static void load(Context cx, Scriptable thisObj,
                            Object[] args, Function funObj)
    {
      Shell shell = (Shell)getTopLevelScope(thisObj);
      for (int i = 0; i < args.length; i++) {
         shell.processFile(Context.toString(args[i]));
      }
    }

    /**
     * Load a JavaScript file.
     *
     * @param filename the JavaScript file to load
     */
    public void loadFile( String filename) {
        System.out.println("Loading absolute file : " + filename + " from
path : " + basePath);
        Object[] args = {filename};
        Shell.load(cx, this, args, null);
        //this.processAbsoluteFile(filename);
    }

    /**
     * A convinence method to call a global JavaScript function.
     *
     * @param methodName the global JavaScript function to be called
     * @param args the arguments for the JavaScript function
     */
    public Object callGlobalFunction(String methodName, Object[] args) {
        return ScriptableObject.callMethod(this, methodName, args);
    }

    private void processFile(String relativeFileName){
        String absoluteFileName = this.basePath  + relativeFileName;
        this.processAbsoluteFile(absoluteFileName);
    }
    /**
     * Evaluate JavaScript source file.
     *
     * @param filename the name of the file to evaluate
     */
    private void processAbsoluteFile(String absoluteFileName) {
        System.out.println("Loading Script: " + absoluteFileName);
        FileReader in = null;
        try {
            in = new FileReader(absoluteFileName);
            // reloads changed files
            monitor.addFile (new File (absoluteFileName));
        }
        catch (FileNotFoundException ex) {
            Context.reportError("Couldn't open file \"" + absoluteFileName +
"\".");
            return;
        }

        try {
            // Here we evalute the entire contents of the file as a script.
            cx.evaluateReader(this, in, absoluteFileName, 1, null);
        }
        catch (WrappedException we) {
            System.err.println(we.getWrappedException().toString());
            we.printStackTrace();
        }
        catch (EvaluatorException ee) {
            System.err.println("js: " + ee.getMessage());
        }
        catch (JavaScriptException jse) {
            System.err.println("js: " + jse.getMessage());
        }
        catch (IOException ioe) {
            System.err.println(ioe.toString());
        }
        finally {
            try {
                in.close();
            }
            catch (IOException ioe) {
                System.err.println(ioe.toString());
            }
        }

    }

    public void fileChanged (File file) {
        //Because the Context/Thread relationship the smartest thing I could
        //think to do is modify/touch WEB-INF/web.xml to force a reload.
        File webXml = new File(this.basePath + "/WEB-INF/web.xml");
        webXml.setLastModified(new java.util.Date().getTime());
    }

--
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.
KamBha  
View profile  
 More options Oct 14 2008, 5:36 pm
From: KamBha <kamal.bh...@gmail.com>
Date: Tue, 14 Oct 2008 14:36:18 -0700 (PDT)
Local: Tues, Oct 14 2008 5:36 pm
Subject: Re: Loading Scripts in the Env
That's what I thought. I was going to do something similar, but I was
told not to (my manager thought it was a bit dodgy to reveal the
context within a running script).

John mentioned that he wants env.js to work independent of Rhino and I
think this is a worthwhile goal. Maybe instead of revealing Rhino
functions, we should create our own object that gets included when
env.js is run  and anyone who wants to support env.js can build the
functionality in whatever language/Javascript engine they are using.
To me, that sounds like a better approach.

On Oct 15, 1:25 am, "chris thatcher" <thatcher.christop...@gmail.com>
wrote:


 
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 Resig  
View profile  
 More options Oct 14 2008, 5:53 pm
From: "John Resig" <jere...@gmail.com>
Date: Tue, 14 Oct 2008 17:53:51 -0400
Local: Tues, Oct 14 2008 5:53 pm
Subject: Re: Loading Scripts in the Env
I could absolutely foresee a set of replaceable functions like:

var Env = {
  readFile: function(file){},
  writeFile: function(file, str){},
  loadJS: function(file){},
  // etc.

};

and we could just swap them out based upon the platform.

--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.
Alex Robinson  
View profile  
 More options Oct 14 2008, 6:31 pm
From: Alex Robinson <solidgold...@gmail.com>
Date: Tue, 14 Oct 2008 15:31:06 -0700 (PDT)
Local: Tues, Oct 14 2008 6:31 pm
Subject: Re: Loading Scripts in the Env
John,

Is env.js meant to be an all-encompassing server-side library or just
a tool to use on the server side?

If the former, have you thought about talking to Peter Michaux about
where he's going with xjs and xpkg?

If the latter, just how much utility functionality do you envisage
bolting on?

On Oct 14, 10:53 pm, "John Resig" <jere...@gmail.com> wrote:

...

read more »


 
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 Resig  
View profile  
 More options Oct 15 2008, 11:31 am
From: "John Resig" <jere...@gmail.com>
Date: Wed, 15 Oct 2008 11:31:52 -0400
Local: Wed, Oct 15 2008 11:31 am
Subject: Re: Loading Scripts in the Env
Alex -

If someone wants to use it for a server-side library than that's fine
- but I don't see it progressing in that manner, explicitly. The
functions that I defined in the Env object are *only* functions that
would be used internally in env.js. I'd rather not include anything
that isn't explicitly needed (much in the same way with jQuery).

--John

...

read more »


 
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.
Alex Robinson  
View profile  
 More options Oct 15 2008, 1:08 pm
From: Alex Robinson <solidgold...@gmail.com>
Date: Wed, 15 Oct 2008 10:08:07 -0700 (PDT)
Local: Wed, Oct 15 2008 1:08 pm
Subject: Re: Loading Scripts in the Env

> I'd rather not include anything
> that isn't explicitly needed (much in the same way with jQuery).

That sounds good to me - all this talk of adding writeFile etc had me
worried. Fight the bloat!

 
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 Oct 16 2008, 11:13 am
From: "chris thatcher" <thatcher.christop...@gmail.com>
Date: Thu, 16 Oct 2008 11:13:56 -0400
Local: Thurs, Oct 16 2008 11:13 am
Subject: Re: Loading Scripts in the Env

Alex, env.js already includes code that writes an ajax post request to a
file:// protocol to a local file.  What we were talking about is isolating
any code that cannot be written using the native javascript and encapsulate
it into a simple API so that we can easily swap out platforms, eg rhino,
spidermonkey, v8.

Thatcher

On Wed, Oct 15, 2008 at 1:08 PM, Alex Robinson <solidgold...@gmail.com>wrote:

> > I'd rather not include anything
> > that isn't explicitly needed (much in the same way with jQuery).

> That sounds good to me - all this talk of adding writeFile etc had me
> worried. Fight the bloat!

--
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.
Justin Meyer  
View profile  
 More options Oct 27 2008, 9:44 pm
From: Justin Meyer <JustinBMe...@gmail.com>
Date: Mon, 27 Oct 2008 18:44:25 -0700 (PDT)
Local: Mon, Oct 27 2008 9:44 pm
Subject: Re: Loading Scripts in the Env
I've gotten loading scripts dynamically (even with document.write) to
work on JavaScriptMVC.

http://code.google.com/p/javascriptmvc/source/browse/trunk/jmvc/rhino...
http://code.google.com/p/javascriptmvc/source/browse/trunk/jmvc/rhino...

On Oct 16, 10:13 am, "chris thatcher" <thatcher.christop...@gmail.com>
wrote:


 
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.
Kamal Bhatt  
View profile  
 More options Oct 28 2008, 6:30 am
From: "Kamal Bhatt" <kamal.bh...@gmail.com>
Date: Tue, 28 Oct 2008 21:30:30 +1100
Local: Tues, Oct 28 2008 6:30 am
Subject: Re: Loading Scripts in the Env
I am not familiar with the HTML parser. Am I correct in saying that we
now support the ability to dynamically add script tags?

I was looking over the code you provided, but some of it doesn't make
sense to me. I was hoping you could explain some of it.

        set onload(f){
            this.onload_handler = onload;
        }

We have set the onload_handler, but I see no call to it. Should there
be a call to onload_handler somewhere, or am I missing something?

Also, is loadText a function in Rhino? Is it available in embedded environments?


 
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