1 package org.feistymeow.filesystem;
\r
3 import java.net.URLDecoder;
\r
5 import org.apache.commons.logging.Log;
\r
6 import org.apache.commons.logging.LogFactory;
\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
12 * @author Chris Koeritz
\r
14 public class PathHelper {
\r
15 private static Log c_logger = LogFactory.getLog(PathHelper.class);
\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
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
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