1 package dolda.jsvc.j2ee;
4 import dolda.jsvc.util.*;
5 import javax.servlet.*;
6 import java.lang.reflect.*;
9 import java.util.logging.*;
11 public class TomcatContext extends J2eeContext {
12 private final String name;
13 private static final Logger logger = Logger.getLogger("dolda.jsvc.context");
15 TomcatContext(ServletConfig sc) {
17 ServletContext ctx = j2eeconfig().getServletContext();
18 Class<?> cclass = ctx.getClass();
21 Method cpm = cclass.getMethod("getContextPath");
22 name = Misc.stripslashes((String)cpm.invoke(ctx), true, true);
23 } catch(NoSuchMethodException e) {
24 throw(new RuntimeException("Could not fetch context path from Tomcat", e));
25 } catch(IllegalAccessException e) {
26 throw(new RuntimeException("Could not fetch context path from Tomcat", e));
27 } catch(InvocationTargetException e) {
28 throw(new RuntimeException("Could not fetch context path from Tomcat", e));
29 } catch(SecurityException e) {
30 logger.log(Level.WARNING, "no permissions to fetch context name from Tomcat", e);
37 private static void loadprops(Properties props, File pfile) {
41 InputStream in = new FileInputStream(pfile);
47 } catch(IOException e) {
48 throw(new RuntimeException(e));
52 private void readconfig() {
55 String basename = System.getProperty("catalina.base");
56 base = new File(basename);
57 } catch(SecurityException e) {
58 logger.log(Level.WARNING, "no permissions to fetch Tomcat base directory while reading configuration", e);
61 sysconfig.put("jsvc.storage", "file:" + new File(new File(base, "work"), "jsvc").getPath());
62 File cdir = new File(base, "conf");
64 loadprops(sysconfig, new File(cdir, "jsvc.properties"));
65 } catch(SecurityException e) {
66 logger.log(Level.WARNING, "no permssions to read from Tomcat conf directory while reading configuration", e);
70 public static boolean tomcatp(ServletConfig sc) {
71 ServletContext ctx = sc.getServletContext();
72 if(ctx.getClass().getName().equals("org.apache.catalina.core.ApplicationContextFacade"))
77 public String name() {