4 import dolda.jsvc.util.*;
5 import dolda.jsvc.next.*;
8 import bsh.Interpreter;
10 public class ShellPage implements Responder {
11 private Console cons = new Console();
12 private Interpreter ip = new Interpreter(cons);
14 public void respond(Request req) {
15 MultiMap<String, String> params = req.params();
16 String cmd = params.get("cmd");
18 Html buf = Html.xhtml11("Shell");
19 buf.addcss("css", null);
20 buf.insert("body", buf.el("h1", buf.text("Shell")));
22 if((req.method() == "POST") && (cmd != null)) {
30 buf.insert("body", buf.el("pre", buf.text((resp == null)?"(null)":(resp.toString()))));
31 } catch(bsh.EvalError exc) {
32 buf.insert("body", buf.el("h2", buf.text("Evaluation error")));
33 buf.insert("body", buf.el("pre", buf.text(exc.toString())));
34 if(exc instanceof bsh.TargetError) {
35 bsh.TargetError te = (bsh.TargetError)exc;
36 buf.insert("body", buf.el("h3", buf.text("Target error")));
37 StringWriter sbuf = new StringWriter();
38 te.getTarget().printStackTrace(new PrintWriter(sbuf));
39 buf.insert("body", buf.el("pre", buf.text(sbuf.toString())));
42 eo = new String(cons.obuf.toByteArray(), Misc.utf8);
43 ee = new String(cons.ebuf.toByteArray(), Misc.utf8);
46 buf.insert("body", buf.el("h2", buf.text("Output")));
47 buf.insert("body", buf.el("pre", buf.text(eo)));
50 buf.insert("body", buf.el("h2", buf.text("Errors")));
51 buf.insert("body", buf.el("pre", buf.text(ee)));
56 buf.insert("body", buf.el("form", form = buf.el("p", null), "action=sh", "method=post"));
57 form.appendChild(buf.el("textarea", buf.text(cmd), "cols=80", "rows=5", "name=cmd"));
58 form.appendChild(buf.el("input", null, "type=submit", "value=Evaluate"));
59 form.appendChild(buf.el("input", null, "type=reset", "value=Reset"));
62 } catch(IOException e) {
63 throw(new RuntimeException(e));