01: package org.jruby.demo;
02:
03: import java.applet.Applet;
04: import java.io.IOException;
05: import java.io.PipedInputStream;
06: import java.io.PipedOutputStream;
07: import java.io.PrintStream;
08: import java.util.ArrayList;
09:
10: import org.jruby.Ruby;
11: import org.jruby.RubyInstanceConfig;
12:
13: public class DOMScriptingApplet extends Applet {
14:
15: public void start() {
16: super .start();
17:
18: try {
19: final PipedInputStream pipeIn = new PipedInputStream();
20: final PipedOutputStream out = new PipedOutputStream(pipeIn);
21: final PipedInputStream in = new PipedInputStream();
22: final PipedOutputStream pipeOut = new PipedOutputStream(in);
23: final RubyInstanceConfig config = new RubyInstanceConfig() {
24: {
25: setInput(pipeIn);
26: setOutput(new PrintStream(pipeOut));
27: setError(new PrintStream(pipeOut));
28: setObjectSpaceEnabled(false);
29: }
30: };
31: final Ruby runtime = Ruby.newInstance(config);
32:
33: runtime.defineGlobalConstant("ARGV", runtime.newArray());
34: //runtime.defineGlobalConstant("JSObject", JavaEmbedUtils.javaToRuby(runtime, JSObject.getWindow(this)));
35: runtime.getLoadService().init(new ArrayList(0));
36:
37: final String script = getParameter("script");
38:
39: Thread t2 = new Thread() {
40: public void run() {
41: runtime.evalScript(script);
42: }
43: };
44: t2.start();
45: } catch (IOException ioe) {
46: ioe.printStackTrace();
47: }
48: }
49:
50: /**
51: *
52: */
53: private static final long serialVersionUID = 3746242973444417387L;
54:
55: }
|