X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=samples%2Fbsh%2Fsrc%2Fdolda%2Fbsvc%2FShellPage.java;fp=samples%2Fbsh%2Fsrc%2Fdolda%2Fbsvc%2FShellPage.java;h=e7412ad0684ea59ac51cb8d8d18ef8e45330d76b;hb=c04f28ae77d5a372eb4afd0296c12014fdbcf96e;hp=29d0d3d7d6bb429a160dee3664400e46c6caf760;hpb=d5dd6a2dada08df30133b739d0ce1fa8f2a0d2e9;p=jsvc.git diff --git a/samples/bsh/src/dolda/bsvc/ShellPage.java b/samples/bsh/src/dolda/bsvc/ShellPage.java index 29d0d3d..e7412ad 100644 --- a/samples/bsh/src/dolda/bsvc/ShellPage.java +++ b/samples/bsh/src/dolda/bsvc/ShellPage.java @@ -6,6 +6,47 @@ import java.io.*; import bsh.Interpreter; public class ShellPage extends SimpleWriter { + private RConsole cons = new RConsole(); + private Interpreter ip = new Interpreter(cons); + + private static class RConsole implements bsh.ConsoleInterface { + public Console back; + Reader in = new StringReader(""); + + public void error(Object msg) { + if(back != null) + back.error(msg); + } + + public void print(Object msg) { + if(back != null) + back.print(msg); + } + + public void println(Object msg) { + if(back != null) + back.println(msg); + } + + public PrintStream getOut() { + if(back == null) + return(null); + return(back.getOut()); + } + + public PrintStream getErr() { + if(back == null) + return(null); + return(back.getErr()); + } + + public Reader getIn() { + if(back == null) + return(null); + return(in); + } + } + private static class Console implements bsh.ConsoleInterface { ByteArrayOutputStream obuf = new ByteArrayOutputStream(); ByteArrayOutputStream ebuf = new ByteArrayOutputStream(); @@ -61,25 +102,31 @@ public class ShellPage extends SimpleWriter { out.println("

Shell

"); if((req.method() == "POST") && (cmd != null)) { Console cons = new Console(); - Interpreter ip = new Interpreter(cons); - Object resp; - try { - ip.set("req", req); - resp = ip.eval(cmd); - out.println("
");
-		out.println(Misc.htmlq((resp == null)?"(null)":(resp.toString())));
-		out.println("
"); - } catch(bsh.EvalError exc) { - out.println("

Evaluation error

"); - out.println("
");
-		out.print(exc.toString());
-		out.println("
"); - if(exc instanceof bsh.TargetError) { - bsh.TargetError te = (bsh.TargetError)exc; - out.println("

Target error

"); - out.println("
");
-		    te.getTarget().printStackTrace(out);
-		    out.println("
"); + synchronized(ip) { + this.cons.back = cons; + try { + Object resp; + try { + ip.set("req", req); + resp = ip.eval(cmd); + out.println("
");
+			out.println(Misc.htmlq((resp == null)?"(null)":(resp.toString())));
+			out.println("
"); + } catch(bsh.EvalError exc) { + out.println("

Evaluation error

"); + out.println("
");
+			out.print(exc.toString());
+			out.println("
"); + if(exc instanceof bsh.TargetError) { + bsh.TargetError te = (bsh.TargetError)exc; + out.println("

Target error

"); + out.println("
");
+			    te.getTarget().printStackTrace(out);
+			    out.println("
"); + } + } + } finally { + this.cons.back = null; } } String eo = new String(cons.obuf.toByteArray(), Misc.utf8);