Commit | Line | Data |
---|---|---|
6f1acdb2 FT |
1 | package dolda.jsvc.j2ee; |
2 | ||
3 | import dolda.jsvc.*; | |
c25c3aad | 4 | import dolda.jsvc.util.*; |
6f1acdb2 FT |
5 | import javax.servlet.*; |
6 | import javax.servlet.http.*; | |
b1488bee FT |
7 | import java.util.*; |
8 | import java.io.*; | |
6f1acdb2 FT |
9 | |
10 | public class J2eeContext implements ServerContext { | |
b1488bee FT |
11 | private final ServletConfig sc; |
12 | private final long ctime; | |
13 | private final Properties config; | |
6f1acdb2 | 14 | |
b1488bee FT |
15 | J2eeContext(ServletConfig sc) { |
16 | this.sc = sc; | |
4b8346e1 | 17 | this.ctime = System.currentTimeMillis(); |
b1488bee FT |
18 | config = readconfig(sc); |
19 | } | |
20 | ||
21 | private static void loadprops(Properties props, File pfile) { | |
22 | if(!pfile.exists()) | |
23 | return; | |
24 | try { | |
25 | InputStream in = new FileInputStream(pfile); | |
26 | try { | |
27 | props.load(in); | |
28 | } finally { | |
29 | in.close(); | |
30 | } | |
31 | } catch(IOException e) { | |
32 | throw(new RuntimeException(e)); | |
33 | } | |
34 | } | |
35 | ||
36 | private static Properties readconfig(ServletConfig sc) { | |
37 | /* This only works on Tomcat now, but that's because I've no | |
38 | * idea how other J2EE servers work. I don't even know if they | |
39 | * _have_ any reasonable place to put configuration and | |
40 | * storage. */ | |
41 | Properties cfg = new Properties(); | |
42 | String basename = System.getProperty("catalina.base"); | |
43 | if(basename != null) { | |
44 | File base = new File(basename); | |
45 | cfg.put("jsvc.storage", new File(new File(base, "work"), "jsvc").getPath()); | |
46 | File cdir = new File(base, "conf"); | |
47 | loadprops(cfg, new File(cdir, "jsvc.properties")); | |
48 | } | |
49 | return(cfg); | |
6f1acdb2 | 50 | } |
7114c38b FT |
51 | |
52 | public long starttime() { | |
4b8346e1 | 53 | return(ctime); |
7114c38b | 54 | } |
b1488bee | 55 | |
72b69304 FT |
56 | public String config(String key) { |
57 | return((String)config.get(key)); | |
b1488bee FT |
58 | } |
59 | ||
60 | public ServletConfig j2eeconfig() { | |
61 | return(sc); | |
62 | } | |
6f1acdb2 | 63 | } |