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