1 package dolda.jsvc.j2ee;
4 import dolda.jsvc.util.*;
5 import javax.servlet.*;
6 import java.lang.reflect.*;
10 public class TomcatContext extends J2eeContext {
11 private final String name;
13 TomcatContext(ServletConfig sc) {
15 ServletContext ctx = j2eeconfig().getServletContext();
16 Class<?> cclass = ctx.getClass();
18 Method cpm = cclass.getMethod("getContextPath");
19 name = Misc.stripslashes((String)cpm.invoke(ctx), true, true);
20 } catch(NoSuchMethodException e) {
21 throw(new RuntimeException("Could not fetch context path from Tomcat", e));
22 } catch(IllegalAccessException e) {
23 throw(new RuntimeException("Could not fetch context path from Tomcat", e));
24 } catch(InvocationTargetException e) {
25 throw(new RuntimeException("Could not fetch context path from Tomcat", e));
30 private static void loadprops(Properties props, File pfile) {
34 InputStream in = new FileInputStream(pfile);
40 } catch(IOException e) {
41 throw(new RuntimeException(e));
45 private void readconfig() {
46 String basename = System.getProperty("catalina.base");
47 File base = new File(basename);
48 config.put("jsvc.storage", "file:" + new File(new File(base, "work"), "jsvc").getPath());
49 File cdir = new File(base, "conf");
50 loadprops(config, new File(cdir, "jsvc.properties"));
53 public static boolean tomcatp(ServletConfig sc) {
54 ServletContext ctx = sc.getServletContext();
55 if(ctx.getClass().getName().equals("org.apache.catalina.core.ApplicationContextFacade"))
60 public String name() {