X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fj2ee%2FJ2eeContext.java;h=c6e09dfaf524f7e84853cd5622b9d387082c5063;hb=b1488beee36000cffb89e64787b8280404ba8c6b;hp=e8f65a6ee64c86f46e1a6e76bbd659da0344fb82;hpb=7114c38b358d27e6c390a689a50c7f9d2d2a048c;p=jsvc.git diff --git a/src/dolda/jsvc/j2ee/J2eeContext.java b/src/dolda/jsvc/j2ee/J2eeContext.java index e8f65a6..c6e09df 100644 --- a/src/dolda/jsvc/j2ee/J2eeContext.java +++ b/src/dolda/jsvc/j2ee/J2eeContext.java @@ -1,25 +1,63 @@ package dolda.jsvc.j2ee; import dolda.jsvc.*; +import dolda.jsvc.util.*; import javax.servlet.*; import javax.servlet.http.*; +import java.util.*; +import java.io.*; public class J2eeContext implements ServerContext { - private ServletConfig cfg; - private HttpServletRequest req; - private HttpServletResponse resp; + private final ServletConfig sc; + private final long ctime; + private final Properties config; - J2eeContext(ServletConfig cfg, HttpServletRequest req, HttpServletResponse resp) { - this.cfg = cfg; - this.req = req; - this.resp = resp; + J2eeContext(ServletConfig sc) { + this.sc = sc; + this.ctime = System.currentTimeMillis(); + config = readconfig(sc); } - public String rootpath() { - return(req.getContextPath()); + private static void loadprops(Properties props, File pfile) { + if(!pfile.exists()) + return; + try { + InputStream in = new FileInputStream(pfile); + try { + props.load(in); + } finally { + in.close(); + } + } catch(IOException e) { + throw(new RuntimeException(e)); + } + } + + private static Properties readconfig(ServletConfig sc) { + /* This only works on Tomcat now, but that's because I've no + * idea how other J2EE servers work. I don't even know if they + * _have_ any reasonable place to put configuration and + * storage. */ + Properties cfg = new Properties(); + String basename = System.getProperty("catalina.base"); + if(basename != null) { + File base = new File(basename); + cfg.put("jsvc.storage", new File(new File(base, "work"), "jsvc").getPath()); + File cdir = new File(base, "conf"); + loadprops(cfg, new File(cdir, "jsvc.properties")); + } + return(cfg); } public long starttime() { - return((Long)cfg.getServletContext().getAttribute("jsvc.starttime")); + return(ctime); + } + + public Properties config() { + return(config); + } + + public ServletConfig j2eeconfig() { + return(sc); } }