diff --git a/src/main/java/altk/comm/engine/CommEngine.java b/src/main/java/altk/comm/engine/CommEngine.java index 1c62254..dffbdea 100644 --- a/src/main/java/altk/comm/engine/CommEngine.java +++ b/src/main/java/altk/comm/engine/CommEngine.java @@ -100,6 +100,28 @@ public abstract class CommEngine extends HttpServlet myException = null; } + /** + * Relocates a filepath relative to runtime directory if filepath is not absolute. + * @param filepath + * @return + */ + public String relocateToRuntimeDir(String filepath) + { + if (filepath.startsWith("/")) return filepath; // no change to absolute path + + String relocated = filepath; + + // The next 2 lines take care of pre-git era meaning convention of filepath in properties. + // Then, the runtime is relative to the current working directory of tomcat. + // Now they are relative to the runtimDirPath obtained from the tomcat tomcat context. + // These 2 lines an be deleted when all CommEngines in production are in the git era. + String unwanted_prefix = engineName + "/"; + if (filepath.startsWith(unwanted_prefix)) relocated = filepath.substring(unwanted_prefix.length()); + + relocated = runtimeDirPath + "/" + relocated; + return relocated; + } + /** * Invoked by servlet container during initialization of servlet. */ @@ -131,8 +153,10 @@ public abstract class CommEngine extends HttpServlet String key = (String)e.nextElement(); if (key.toLowerCase().endsWith(".file")) { - prop.setProperty(key, runtimeDirPath + "/" + prop.getProperty(key)); - System.out.println(key + "=" + prop.getProperty(key)); + String filepath = prop.getProperty(key); + String relocate = relocateToRuntimeDir(filepath); + prop.setProperty(key, relocate); + System.out.println(key + "=" + relocate); } } PropertyConfigurator.configure(prop);