Ejemplo n.º 1
0
  /**
   * Implements getResource() See getRealPath(), it have to be local to the current Context - and
   * can't go to a sub-context. That means we don't need any overhead.
   */
  public URL getResource(String rpath) throws MalformedURLException {
    if (rpath == null) return null;

    if (URLUtil.hasEscape(rpath)) return null;

    URL url = null;
    String absPath = getAbsolutePath();

    if ("".equals(rpath)) return new URL("file", null, 0, absPath);

    if (!rpath.startsWith("/")) rpath = "/" + rpath;

    String realPath = FileUtil.safePath(absPath, rpath);
    if (realPath == null) {
      log("Unsafe path " + absPath + " " + rpath);
      return null;
    }

    try {
      url = new URL("file", null, 0, realPath);
      if (debug > 9) log("getResourceURL=" + url + " request=" + rpath);
      return url;
    } catch (IOException ex) {
      ex.printStackTrace();
      return null;
    }
  }
 /*
  * Helper method to return the install location. Return null if it is unavailable.
  */
 public static File getInstallLocation() {
   Location installLocation =
       ServiceHelper.getService(
           TestActivator.getContext(), Location.class, Location.INSTALL_FILTER);
   if (installLocation == null || !installLocation.isSet()) return null;
   URL url = installLocation.getURL();
   if (url == null) return null;
   return URLUtil.toFile(url);
 }
Ejemplo n.º 3
0
 /*
  * Helper method to return the eclipse.home location. Return
  * null if it is unavailable.
  */
 public static File getEclipseHome() {
   Location eclipseHome =
       (Location)
           ServiceHelper.getService(
               Activator.getContext(), Location.class.getName(), Location.ECLIPSE_HOME_FILTER);
   if (eclipseHome == null || !eclipseHome.isSet()) return null;
   URL url = eclipseHome.getURL();
   if (url == null) return null;
   return URLUtil.toFile(url);
 }