Added some possibilities for local configuration.
[jsvc.git] / src / dolda / jsvc / j2ee / J2eeContext.java
CommitLineData
6f1acdb2
FT
1package dolda.jsvc.j2ee;
2
3import dolda.jsvc.*;
c25c3aad 4import dolda.jsvc.util.*;
6f1acdb2
FT
5import javax.servlet.*;
6import javax.servlet.http.*;
b1488bee
FT
7import java.util.*;
8import java.io.*;
6f1acdb2
FT
9
10public 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
FT
55
56 public Properties config() {
57 return(config);
58 }
59
60 public ServletConfig j2eeconfig() {
61 return(sc);
62 }
6f1acdb2 63}