예제 #1
0
  /**
   * Return the URL to the resource that is mapped to a specified path. The path must begin with a
   * "/" and is interpreted as relative to the current context root.
   *
   * @param path The path to the desired resource
   * @exception MalformedURLException if the path is not given in the correct form
   */
  public URL getResource(String path) throws MalformedURLException {

    DirContext resources = context.getResources();
    if (resources != null) {
      String fullPath = context.getName() + path;

      // this is the problem. Host must not be null
      String hostName = context.getParent().getName();

      try {
        resources.lookup(path);
        if (System.getSecurityManager() != null) {
          try {
            PrivilegedGetResource dp = new PrivilegedGetResource(hostName, fullPath, resources);
            return (URL) AccessController.doPrivileged(dp);
          } catch (PrivilegedActionException pe) {
            throw pe.getException();
          }
        } else {
          return new URL(
              "jndi",
              null,
              0,
              getJNDIUri(hostName, fullPath),
              new DirContextURLStreamHandler(resources));
        }
      } catch (Exception e) {
        // e.printStackTrace();
      }
    }
    return (null);
  }
예제 #2
0
  /**
   * Return the requested resource as an <code>InputStream</code>. The path must be specified
   * according to the rules described under <code>getResource</code>. If no such resource can be
   * identified, return <code>null</code>.
   *
   * @param path The path to the desired resource.
   */
  public InputStream getResourceAsStream(String path) {

    DirContext resources = context.getResources();
    if (resources != null) {
      try {
        Object resource = resources.lookup(path);
        if (resource instanceof Resource) return (((Resource) resource).streamContent());
      } catch (Exception e) {
      }
    }
    return (null);
  }
예제 #3
0
  /**
   * Return a Set containing the resource paths of resources member of the specified collection.
   * Each path will be a String starting with a "/" character. The returned set is immutable.
   *
   * @param path Collection path
   */
  public Set getResourcePaths(String path) {

    DirContext resources = context.getResources();
    if (resources != null) {
      if (System.getSecurityManager() != null) {
        PrivilegedAction dp = new PrivilegedGetResourcePaths(resources, path);
        return ((Set) AccessController.doPrivileged(dp));
      } else {
        return (getResourcePathsInternal(resources, path));
      }
    }
    return (null);
  }
예제 #4
0
 /**
  * Return the resources object that is mapped to a specified path. The path must begin with a "/"
  * and is interpreted as relative to the current context root.
  */
 public DirContext getResources() {
   return context.getResources();
 }