updated code for kona libs, not quite working yet.
[feisty_meow.git] / kona / src / org / feistymeow / filesystem / PathHelper.java
1 package org.feistymeow.filesystem;\r
2 \r
3 import java.net.URLDecoder;\r
4 \r
5 import org.apache.commons.logging.Log;\r
6 import org.apache.commons.logging.LogFactory;\r
7 \r
8 /*\r
9  * Provides access to the relevant paths for a Java application.\r
10  * This class cannot provide static members due to runtime constraints.\r
11  * \r
12  * @author Chris Koeritz\r
13  */\r
14 public class PathHelper {\r
15     private static Log c_logger = LogFactory.getLog(PathHelper.class);\r
16     \r
17         // locates the home directory where *this* application is installed.\r
18         // this can be used as a root path for finding configuration files\r
19         // needed by the application.\r
20         public String findHome() {\r
21                 String path = ".";\r
22                 try {\r
23                         path = URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "x-www-form-urlencoded");\r
24                         // we remove the leading slash that is sometimes present, but only if the path looks.\r
25                         // like a dos path.\r
26                         if ( (path.length() >=3) && (path.charAt(0) == '/') && (path.charAt(2) == ':') )\r
27                                 path = path.substring(1);\r
28                         // we chop the last component off, because we want an actual path.\r
29                         int lastSlash = path.lastIndexOf('/');\r
30                         path = path.substring(0, lastSlash);\r
31                 } catch (Exception ex) {\r
32                         c_logger.error("caught exception during path calculation: " + ex.toString());\r
33                         // unknown what we should say here, so we return the default.\r
34                 }\r
35                 return path;\r
36         }               \r
37 };\r
38 \r