- /** lets us put multi-level get/put/call keys all in the same method */
- private class Sub extends JS {
- Object key;
- Sub(Object key) { this.key = key; }
- public void put(Object key, Object val) throws JSExn {
- ServletScope.this.put(JS.toString(this.key) + "." + JS.toString(key), val); }
- public Object get(Object key) throws JSExn {
- return ServletScope.this.get(JS.toString(this.key) + "." + JS.toString(key)); }
- public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
- return ServletScope.this.callMethod(this.key, a0, a1, a2, rest, nargs);
- }
- public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
- return ServletScope.this.callMethod(JS.toString(this.key) + "."
- + JS.toString(method), a0, a1, a2, rest, nargs);
- }
- }
- private Sub getSub(String key) { return new Sub(key); }
-
- public Object callMethod(Object method, final Object a, final Object b, Object c, Object[] rest, int nargs) throws JSExn {
- //#switch(method)
- case "session.invalidate": request.getSession(true).invalidate(); return null;
- case "context.list":
- String path = JS.toString(a);
- if (path.indexOf("..") != -1) throw new JSExn("cannot use .. in paths");
- File f = new File(cx.getRealPath("/") + File.separatorChar + path);
- if (!f.isDirectory()) return null;
- String[] contents = f.list();
- JSArray ret = new JSArray(contents.length);
- for(int i=0; i<contents.length; i++) ret.addElement(contents[i]);
- return ret;
- //#end
- return null;
- }
- public Object get(Object key) throws JSExn {
- //#switch(key)