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;
    }
  }