--- /dev/null
+package org.feistymeow.filesystem;\r
+\r
+import java.net.URLDecoder;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+/*\r
+ * Provides access to the relevant paths for a Java application.\r
+ * This class cannot provide static members due to runtime constraints.\r
+ * \r
+ * @author Chris Koeritz\r
+ */\r
+public class PathHelper {\r
+ private static Log c_logger = LogFactory.getLog(PathHelper.class);\r
+ \r
+ // locates the home directory where *this* application is installed.\r
+ // this can be used as a root path for finding configuration files\r
+ // needed by the application.\r
+ public String findHome() {\r
+ String path = ".";\r
+ try {\r
+ path = URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "x-www-form-urlencoded");\r
+ // we remove the leading slash that is sometimes present, but only if the path looks.\r
+ // like a dos path.\r
+ if ( (path.length() >=3) && (path.charAt(0) == '/') && (path.charAt(2) == ':') )\r
+ path = path.substring(1);\r
+ // we chop the last component off, because we want an actual path.\r
+ int lastSlash = path.lastIndexOf('/');\r
+ path = path.substring(0, lastSlash);\r
+ } catch (Exception ex) {\r
+ c_logger.error("caught exception during path calculation: " + ex.toString());\r
+ // unknown what we should say here, so we return the default.\r
+ }\r
+ return path;\r
+ } \r
+};\r
+\r