X-Git-Url: http://git.megacz.com/?p=org.ibex.xt.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fxt%2FServlet.java;fp=src%2Forg%2Fibex%2Fxt%2FServlet.java;h=7a2b58f00978c208ded1432ae26248d72035c51b;hp=f00c38712cffebb15ab0a4b521f2cb9c7638566a;hb=507fd40aa9c563c5fdeeac08929523f9fdd35590;hpb=ef26083dc84f06010099ecee9caec22df3b3e114 diff --git a/src/org/ibex/xt/Servlet.java b/src/org/ibex/xt/Servlet.java index f00c387..7a2b58f 100644 --- a/src/org/ibex/xt/Servlet.java +++ b/src/org/ibex/xt/Servlet.java @@ -49,7 +49,9 @@ public class Servlet extends HttpServlet { w.flush(); } - public class ServletScope extends JS.Obj { + // ServletScope ////////////////////////////////////////////////////////////////////////////// + + public class ServletScope extends JSSubProperties { HttpServletRequest request; HttpServletResponse response; ServletContext cx; @@ -60,103 +62,80 @@ public class Servlet extends HttpServlet { this.response = (HttpServletResponse)response; this.cx = cx; } + + // FIXME: setattributes + //#repeat params/cookies/requestHeader/attributes \ + // getParameter/getCookie/getHeader/getAttribute \ + // getParameterNames/getCookieNames/getHeaderNames/getAttributeNames \ + // request/request/request/session/response \ + // setParameter/setCookie/setHeader/setAttribute private JS params = new JS.Obj() { - public JS get(JS key) throws JSExn { return JSU.S(request.getParameter(JSU.toString(key))); } - public Enumeration keys() throws JSExn { return new JS.Enumeration.JavaStringEnumeration(request.getParameterNames()); } - }; - private JS cookies = new JS.Obj() { - /* - public Object get(Object key) { return request.getCookie(JSU.toString(key)); } - public Enumeration keys() { return request.getCookieNames(); } - */ - }; - private JS sessionAttributes = new JS.Obj() { - public JS get(JS key) throws JSExn { return JSU.S(request.getSession(true).getAttribute(JSU.toString(key)).toString()); } - public void put(JS key, JS val) throws JSExn { - if (val == null) request.getSession(true).removeAttribute(JSU.toString(key)); - else request.setAttribute(JSU.toString(key), val); } - public Enumeration keys() throws JSExn { return new JS.Enumeration.JavaStringEnumeration(request.getSession(true).getAttributeNames()); } - }; - private JS requestHeader = new JS.Obj() { - public JS get(JS key) throws JSExn { return JSU.S(request.getHeader(JSU.toString(key))); } - public Enumeration keys() throws JSExn { return new JS.Enumeration.JavaStringEnumeration(request.getHeaderNames()); } - }; - private JS responseHeader = new JS.Obj() { - public void put(JS key, JS val) throws JSExn { response.setHeader(JSU.toString(key), JSU.toString(val)); } + public JS get(JS key) throws JSExn { return JSU.S(request.getParameter(JSU.toString(key)).toString()); } + public void put(JS key, JS val) throws JSExn { request.setParameter(JSU.toString(key), JSU.toString(val)); } + public Enumeration keys() throws JSExn { + return new JS.Enumeration.JavaStringEnumeration(request.getParameterNames()); } }; + //#end - - /** lets us put multi-level get/put/call keys all in the same method */ - private class Sub extends JS.Obj { - JS key; - Sub(JS key) { this.key = key; } - public void put(JS key, JS val) throws JSExn { - ServletScope.this.put(JSU.S(JSU.toString(this.key) + "." + JSU.toString(key)), val); } - public JS get(JS key) throws JSExn { - return ServletScope.this.get(JSU.S(JSU.toString(this.key) + "." + JSU.toString(key))); } - public JS call(JS method, JS[] args) throws JSExn { - return ServletScope.this.call(JSU.S(JSU.toString(this.key) + "." + JSU.toString(method)), args); - } - } - private Sub getSub(String key) { return new Sub(JSU.S(key)); } - - public JS call(JS method, JS[] args) throws JSExn { - //#switch(JSU.toString(method)) - case "session.invalidate": request.getSession(true).invalidate(); return null; - case "context.list": - String path = JSU.toString(args[0]); - 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