From: Fredrik Tolf Date: Mon, 12 Oct 2009 21:10:52 +0000 (+0200) Subject: Added a way to query the current server context. X-Git-Url: http://dolda2000.com/gitweb/?p=jsvc.git;a=commitdiff_plain;h=6f1acdb2f8879097cdd8c6cedfc0d6752f2b29ef Added a way to query the current server context. --- diff --git a/src/dolda/jsvc/Request.java b/src/dolda/jsvc/Request.java index fbadd23..4dc9cf6 100644 --- a/src/dolda/jsvc/Request.java +++ b/src/dolda/jsvc/Request.java @@ -21,4 +21,5 @@ public interface Request { /* Misc. */ public Map props(); + public ServerContext ctx(); } diff --git a/src/dolda/jsvc/RequestThread.java b/src/dolda/jsvc/RequestThread.java index 7940748..51f9d86 100644 --- a/src/dolda/jsvc/RequestThread.java +++ b/src/dolda/jsvc/RequestThread.java @@ -19,6 +19,10 @@ public class RequestThread extends Thread { } } + public static ServerContext context() { + return(((RequestThread)Thread.currentThread()).req.ctx()); + } + public static Request request() { return(((RequestThread)Thread.currentThread()).req); } diff --git a/src/dolda/jsvc/ServerContext.java b/src/dolda/jsvc/ServerContext.java new file mode 100644 index 0000000..b9809f9 --- /dev/null +++ b/src/dolda/jsvc/ServerContext.java @@ -0,0 +1,5 @@ +package dolda.jsvc; + +public interface ServerContext { + public String rootpath(); +} diff --git a/src/dolda/jsvc/j2ee/J2eeContext.java b/src/dolda/jsvc/j2ee/J2eeContext.java new file mode 100644 index 0000000..f253128 --- /dev/null +++ b/src/dolda/jsvc/j2ee/J2eeContext.java @@ -0,0 +1,21 @@ +package dolda.jsvc.j2ee; + +import dolda.jsvc.*; +import javax.servlet.*; +import javax.servlet.http.*; + +public class J2eeContext implements ServerContext { + private ServletConfig cfg; + private HttpServletRequest req; + private HttpServletResponse resp; + + J2eeContext(ServletConfig cfg, HttpServletRequest req, HttpServletResponse resp) { + this.cfg = cfg; + this.req = req; + this.resp = resp; + } + + public String rootpath() { + return(req.getContextPath()); + } +} diff --git a/src/dolda/jsvc/j2ee/J2eeRequest.java b/src/dolda/jsvc/j2ee/J2eeRequest.java index 9676c46..1e7d789 100644 --- a/src/dolda/jsvc/j2ee/J2eeRequest.java +++ b/src/dolda/jsvc/j2ee/J2eeRequest.java @@ -48,6 +48,10 @@ public class J2eeRequest extends ResponseBuffer { return(props); } + public ServerContext ctx() { + return(new J2eeContext(cfg, req, resp)); + } + public URL url() { return(url); }