craigmcc    00/10/21 07:40:27

  Modified:    catalina/src/share/org/apache/catalina/resources
                        FileResources.java JarResources.java
  Log:
  Add implementation of getResourcePaths().  The following assumptions have
  been made (clarification questions submitted to ensure that the behavior
  is correct):
  * Entries for "directory" nodes in the WAR (i.e. real directories when
    unpacked) should be included in the list.
  * An entry for "/" representing the document root should be included in
    the list.
  * Entries for elements under WEB-INF should be included in the list,
    since these resources are accessible through getResource() and
    getResourceAsStream().
  
  Revision  Changes    Path
  1.4       +75 -37    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java
  
  Index: FileResources.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileResources.java        2000/10/17 19:45:24     1.3
  +++ FileResources.java        2000/10/21 14:40:27     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java,v
 1.3 2000/10/17 19:45:24 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/10/17 19:45:24 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/FileResources.java,v
 1.4 2000/10/21 14:40:27 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/10/21 14:40:27 $
    *
    * ====================================================================
    *
  @@ -75,6 +75,8 @@
   import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.util.ArrayList;
  +import java.util.List;
   import org.apache.catalina.Context;
   
   
  @@ -93,7 +95,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.3 $ $Date: 2000/10/17 19:45:24 $
  + * @version $Revision: 1.4 $ $Date: 2000/10/21 14:40:27 $
    */
   
   public final class FileResources extends ResourcesBase {
  @@ -293,14 +295,14 @@
                   File currentFile = fileList[i];
                   ResourceBean newEntry = null;
                   if (currentFile.isDirectory()) {
  -                    newEntry = 
  -                        new DirectoryBean(normalize(normalized + "/" 
  -                                                    + currentFile.getName()), 
  +                    newEntry =
  +                        new DirectoryBean(normalize(normalized + "/"
  +                                                    + currentFile.getName()),
                                                       currentFile);
                   } else {
  -                    newEntry = 
  -                        new ResourceBean(normalize(normalized + "/" 
  -                                                   + currentFile.getName()), 
  +                    newEntry =
  +                        new ResourceBean(normalize(normalized + "/"
  +                                                   + currentFile.getName()),
                                                      currentFile);
                   }
                   directory.addResource(newEntry);
  @@ -342,15 +344,15 @@
   
   
       /**
  -     * Returns true if a resource exists at the specified path, 
  +     * Returns true if a resource exists at the specified path,
        * where <code>path</code> would be suitable for passing as an argument to
  -     * <code>getResource()</code> or <code>getResourceAsStream()</code>.  
  +     * <code>getResource()</code> or <code>getResourceAsStream()</code>.
        * If there is no resource at the specified location, return false.
        *
        * @param path The path to the desired resource
        */
       public boolean exists(String path) {
  -        
  +
           String normalized = normalize(path);
        if (normalized == null) {
               //            if (debug >= 1)
  @@ -364,7 +366,7 @@
               //                log("exists(" + path + ") --> IAE");
               throw e;
           }
  -        
  +
        File file = new File(base, normalized.substring(1));
           if (file != null) {
               //            if (debug >= 1)
  @@ -376,7 +378,7 @@
               //                log("exists(" + path + ") --> NO FILE");
               return (false);
           }
  -        
  +
       }
   
   
  @@ -412,14 +414,29 @@
   
   
       /**
  +     * Return the set of context-relative paths of all available resources.
  +     * Each path will begin with a "/" character.
  +     */
  +     public String[] getResourcePaths() {
  +
  +        ArrayList paths = new ArrayList();
  +        paths.add("/"); // NOTE: Assumes directories are included
  +        appendResourcePaths(paths, "", base);
  +        String results[] = new String[paths.size()];
  +        return (results);
  +
  +     }
  +
  +
  +    /**
        * Return the creation date/time of the resource at the specified
        * path, where <code>path</code> would be suitable for passing as an
        * argument to <code>getResource()</code> or
        * <code>getResourceAsStream()</code>.  If there is no resource at the
  -     * specified location, return -1. If this time is unknown, the 
  +     * specified location, return -1. If this time is unknown, the
        * implementation should return getResourceModified(path).
        * <p>
  -     * <strong>IMPLEMENTATION NOTE</strong>: The creation date of a file 
  +     * <strong>IMPLEMENTATION NOTE</strong>: The creation date of a file
        * shouldn't change except if the file is deleted and the recreated, so
        * this method uses the cache.
        *
  @@ -449,7 +466,7 @@
        * path, where <code>path</code> would be suitable for passing as an
        * argument to <code>getResource()</code> or
        * <code>getResourceAsStream()</code>.  If the content length
  -     * of the resource can't be determined, return -1. If no content is 
  +     * of the resource can't be determined, return -1. If no content is
        * available (when for exemple, the resource is a collection), return 0.
        *
        * @param path The path to the desired resource
  @@ -469,20 +486,20 @@
           if (resource != null) {
               return (resource.getSize());
           }
  -        
  +
           // No entry was found in the cache
        File file = file(normalized);
        if (file != null)
            return (file.length());
        else
            return (-1L);
  -        
  +
       }
   
   
       /**
        * Return true if the resource at the specified path is a collection. A
  -     * collection is a special type of resource which has no content but 
  +     * collection is a special type of resource which has no content but
        * contains child resources.
        *
        * @param path The path to the desired resource
  @@ -499,15 +516,15 @@
            return (file.isDirectory());
        else
            return (false);
  -        
  +
       }
   
   
       /**
        * Return the children of the resource at the specified path, if any. This
  -     * will return null if the resource is not a collection, or if it is a 
  +     * will return null if the resource is not a collection, or if it is a
        * collection but has no children.
  -     * 
  +     *
        * @param path The path to the desired resource
        */
       public String[] getCollectionMembers(String path) {
  @@ -534,16 +551,16 @@
       /**
        * Set the content of the resource at the specified path. If the resource
        * already exists, its previous content is overwritten. If the resource
  -     * doesn't exist, its immediate parent collection (according to the path 
  +     * doesn't exist, its immediate parent collection (according to the path
        * given) exists, then its created, and the given content is associated
        * with it. Return false if either the resource is a collection, or
        * no parent collection exist.
  -     * 
  +     *
        * @param path The path to the desired resource
        * @param content InputStream to the content to be set
        */
       public boolean setResource(String path, InputStream content) {
  -        
  +
           String normalized = normalize(path);
        if (normalized == null)
            return (false);
  @@ -552,9 +569,9 @@
        File file = new File(base, normalized.substring(1));
           //if ((file.exists()) && (file.isDirectory()))
           //return (false);
  -        
  +
           OutputStream os = null;
  -        
  +
           try {
               os = new FileOutputStream(file);
           } catch (FileNotFoundException e) {
  @@ -562,7 +579,7 @@
        } catch (IOException e) {
          return (false);
           }
  -        
  +
           try {
               byte[] buffer = new byte[BUFFER_SIZE];
               while (true) {
  @@ -574,21 +591,21 @@
           } catch (IOException e) {
               return (false);
           }
  -        
  +
           try {
               os.close();
           } catch (IOException e) {
               return (false);
           }
  -        
  +
           try {
               content.close();
           } catch (IOException e) {
               return (false);
           }
  -        
  +
           return (true);
  -        
  +
       }
   
   
  @@ -596,7 +613,7 @@
        * Create a collection at the specified path. A parent collection for this
        * collection must exist. Return false if a resource already exist at the
        * path specified, or if the parent collection doesn't exist.
  -     * 
  +     *
        * @param path The path to the desired resource
        */
       public boolean createCollection(String path) {
  @@ -618,9 +635,9 @@
       /**
        * Delete the specified resource. Non-empty collections cannot be deleted
        * before deleting all their member resources. Return false is deletion
  -     * fails because either the resource specified doesn't exist, or the 
  +     * fails because either the resource specified doesn't exist, or the
        * resource is a non-empty collection.
  -     * 
  +     *
        * @param path The path to the desired resource
        */
       public boolean deleteResource(String path) {
  @@ -642,6 +659,27 @@
   
   
       // -------------------------------------------------------- Private Methods
  +
  +
  +    /**
  +     * Append resource paths for files in the specified directory to the
  +     * list we are accumulating.
  +     *
  +     * @param paths The list containing our accumulated paths
  +     * @param path Context-relative path for this directory
  +     * @param dir File object for this directory
  +     */
  +    private void appendResourcePaths(List paths, String path, File dir) {
  +
  +        String names[] = dir.list();
  +        for (int i = 0; i < names.length; i++) {
  +            paths.add(path + "/" + names[i]);
  +            File file = new File(dir, names[i]);        // Assume dirs included
  +            if (file.isDirectory())
  +                appendResourcePaths(paths, path + "/" + names[i], file);
  +        }
  +
  +    }
   
   
       /**
  
  
  
  1.2       +40 -19    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/JarResources.java
  
  Index: JarResources.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/JarResources.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JarResources.java 2000/08/11 22:45:57     1.1
  +++ JarResources.java 2000/10/21 14:40:27     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/JarResources.java,v
 1.1 2000/08/11 22:45:57 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 22:45:57 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/resources/JarResources.java,v
 1.2 2000/10/21 14:40:27 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/10/21 14:40:27 $
    *
    * ====================================================================
    *
  @@ -71,7 +71,9 @@
   import java.net.JarURLConnection;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.util.ArrayList;
   import java.util.Enumeration;
  +import java.util.Iterator;
   import java.util.jar.JarEntry;
   import java.util.jar.JarFile;
   import org.apache.catalina.Context;
  @@ -104,7 +106,7 @@
    * requested the first time (and passes the "cacheable" test).
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 22:45:57 $
  + * @version $Revision: 1.2 $ $Date: 2000/10/21 14:40:27 $
    */
   
   public final class JarResources extends ResourcesBase {
  @@ -309,21 +311,21 @@
   
   
       /**
  -     * Returns true if a resource exists at the specified path, 
  +     * Returns true if a resource exists at the specified path,
        * where <code>path</code> would be suitable for passing as an argument to
  -     * <code>getResource()</code> or <code>getResourceAsStream()</code>.  
  +     * <code>getResource()</code> or <code>getResourceAsStream()</code>.
        * If there is no resource at the specified location, return false.
        *
        * @param path The path to the desired resource
        */
       public boolean exists(String path) {
  -        
  +
        // Look up and return the last modified time for this resource
        String normalized = normalize(path);
        if (normalized == null)
            return (false);
        validate(normalized);
  -        
  +
        ResourceBean resource = null;
        synchronized (resourcesCache) {
            resource = (ResourceBean) resourcesCache.get(normalized);
  @@ -332,7 +334,7 @@
            return (true);
        else
            return (false);
  -        
  +
       }
   
   
  @@ -372,11 +374,30 @@
   
   
       /**
  +     * Return the set of context-relative paths of all available resources.
  +     * Each path will begin with a "/" character.
  +     */
  +     public String[] getResourcePaths() {
  +
  +        ArrayList paths = new ArrayList();
  +        // NOTE: assumes directories are included
  +        synchronized (resourcesCache) {
  +            Iterator names = resourcesCache.keySet().iterator();
  +            while (names.hasNext())
  +                paths.add((String) names.next());
  +        }
  +        String results[] = new String[paths.size()];
  +        return ((String[]) paths.toArray(results));
  +
  +     }
  +
  +
  +    /**
        * Return the creation date/time of the resource at the specified
        * path, where <code>path</code> would be suitable for passing as an
        * argument to <code>getResource()</code> or
        * <code>getResourceAsStream()</code>.  If there is no resource at the
  -     * specified location, return -1. If this time is unknown, the 
  +     * specified location, return -1. If this time is unknown, the
        * implementation should return getResourceModified(path).
        *
        * @param path The path to the desired resource
  @@ -391,7 +412,7 @@
        * path, where <code>path</code> would be suitable for passing as an
        * argument to <code>getResource()</code> or
        * <code>getResourceAsStream()</code>.  If the content length
  -     * of the resource can't be determined, return -1. If no content is 
  +     * of the resource can't be determined, return -1. If no content is
        * available (when for exemple, the resource is a collection), return 0.
        *
        * @param path The path to the desired resource
  @@ -403,7 +424,7 @@
   
       /**
        * Return true if the resource at the specified path is a collection. A
  -     * collection is a special type of resource which has no content but 
  +     * collection is a special type of resource which has no content but
        * contains child resources.
        *
        * @param path The path to the desired resource
  @@ -415,9 +436,9 @@
   
       /**
        * Return the children of the resource at the specified path, if any. This
  -     * will return null if the resource is not a collection, or if it is a 
  +     * will return null if the resource is not a collection, or if it is a
        * collection but has no children.
  -     * 
  +     *
        * @param path The path to the desired resource
        */
       public String[] getCollectionMembers(String path) {
  @@ -428,11 +449,11 @@
       /**
        * Set the content of the resource at the specified path. If the resource
        * already exists, its previous content is overwritten. If the resource
  -     * doesn't exist, its immediate parent collection (according to the path 
  +     * doesn't exist, its immediate parent collection (according to the path
        * given) exists, then its created, and the given content is associated
        * with it. Return false if either the resource is a collection, or
        * no parent collection exist.
  -     * 
  +     *
        * @param path The path to the desired resource
        * @param content InputStream to the content to be set
        */
  @@ -445,7 +466,7 @@
        * Create a collection at the specified path. A parent collection for this
        * collection must exist. Return false if a resource already exist at the
        * path specified, or if the parent collection doesn't exist.
  -     * 
  +     *
        * @param path The path to the desired resource
        */
       public boolean createCollection(String path) {
  @@ -456,9 +477,9 @@
       /**
        * Delete the specified resource. Non-empty collections cannot be deleted
        * before deleting all their member resources. Return false is deletion
  -     * fails because either the resource specified doesn't exist, or the 
  +     * fails because either the resource specified doesn't exist, or the
        * resource is a non-empty collection.
  -     * 
  +     *
        * @param path The path to the desired resource
        */
       public boolean deleteResource(String path) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to