You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@locus.apache.org on 2000/07/31 01:20:25 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources DirectoryBean.java FileResources.java JarResources.java ResourcesBase.java StandardResources.java
remm 00/07/30 16:20:24
Modified: proposals/catalina/src/share/org/apache/tomcat/resources
DirectoryBean.java FileResources.java
JarResources.java ResourcesBase.java
Removed: proposals/catalina/src/share/org/apache/tomcat/resources
StandardResources.java
Log:
- Numerous fixes to make the directory browser work
- StandardResources is not used anymore
- FileResources has been updated to support the new methods
in the Resources interface
- JarResources is out of sync (but contains empty implementations
so it compiles)
- ResourcesBase.validate doesn't like Jasper urls on
Windows machines, so Jasper is broken right now
Revision Changes Path
1.2 +13 -6 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/DirectoryBean.java
Index: DirectoryBean.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/DirectoryBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DirectoryBean.java 2000/07/26 20:04:52 1.1
+++ DirectoryBean.java 2000/07/30 23:20:22 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/DirectoryBean.java,v 1.1 2000/07/26 20:04:52 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/07/26 20:04:52 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/DirectoryBean.java,v 1.2 2000/07/30 23:20:22 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/07/30 23:20:22 $
*
* ====================================================================
*
@@ -91,7 +91,7 @@
* manner. No internal synchronization is performed.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/07/26 20:04:52 $
+ * @version $Revision: 1.2 $ $Date: 2000/07/30 23:20:22 $
*/
public final class DirectoryBean extends ResourceBean {
@@ -250,12 +250,19 @@
writer.print("</strong>\r\n</font></td></tr>\r\n");
// Render the link to our parent (if required)
- int slash = name.lastIndexOf("/");
- if (slash > 0) {
+ String parentDirectory = name;
+ if (parentDirectory.endsWith("/")) {
+ parentDirectory =
+ parentDirectory.substring(0, parentDirectory.length() - 1);
+ }
+ int slash = parentDirectory.lastIndexOf("/");
+ if (slash >= 0) {
String parent = name.substring(0, slash);
writer.print("<tr><td colspan=\"3\" bgcolor=\"#ffffff\">\r\n");
writer.print("<a href=\"");
writer.print(contextPath);
+ if (parent.equals(""))
+ parent = "/";
writer.print(parent);
writer.print("\">");
writer.print(sm.getString("directory.parent", parent));
1.3 +247 -7 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/FileResources.java
Index: FileResources.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/FileResources.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileResources.java 2000/07/26 21:09:21 1.2
+++ FileResources.java 2000/07/30 23:20:22 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/FileResources.java,v 1.2 2000/07/26 21:09:21 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/07/26 21:09:21 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/FileResources.java,v 1.3 2000/07/30 23:20:22 remm Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/07/30 23:20:22 $
*
* ====================================================================
*
@@ -89,7 +89,7 @@
* since they were cached.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/07/26 21:09:21 $
+ * @version $Revision: 1.3 $ $Date: 2000/07/30 23:20:22 $
*/
public final class FileResources extends ResourcesBase {
@@ -203,6 +203,63 @@
/**
+ * Get the ResourceBean object associated with the given path.
+ *
+ * @param path The path to the desired resource
+ */
+ /*
+ public ResourceBean getResourceBean(String path) {
+
+ validate(path);
+
+ // Look up the cached resource entry (if it exists) for this path
+ String normalized = normalize(path);
+ if (normalized == null)
+ return (null);
+ ResourceBean resource = null;
+ synchronized (resourcesCache) {
+ resource = (ResourceBean) resourcesCache.get(normalized);
+ }
+ if (resource != null)
+ return (resource);
+
+ // Create a File object referencing the requested resource
+ File file = file(normalized);
+ if ((file == null) || !file.exists() || !file.canRead())
+ return (null);
+
+ // Special handling for directories
+ if (file.isDirectory()) {
+ String contextPath =
+ ((Context) container).getPath();
+ if (contextPath == null)
+ contextPath = "";
+ DirectoryBean directory = new DirectoryBean(normalized, file);
+ ; // FIXME - Populate it with ResourceBean entries
+ return (directory.render(contextPath));
+ }
+
+ // Cache the data for this resource (if appropriate and not yet done)
+ if (cacheable(normalized, file.length())) {
+ resource = new ResourceBean(normalized, file);
+ try {
+ resource.cache(inputStream(resource.getName()));
+ } catch (IOException e) {
+ log(sm.getString("resources.input", resource.getName()), e);
+ return (null);
+ }
+ synchronized (resourcesCache) {
+ resourcesCache.put(resource.getName(), resource);
+ resourcesCount++;
+ }
+ return (new ByteArrayInputStream(resource.getData()));
+ }
+
+ }
+ */
+
+
+ /**
* Return an InputStream to the contents of the resource specified
* by the given virtual path, or <code>null</code> if no resource
* exists at the specified path.
@@ -232,14 +289,30 @@
if ((file == null) || !file.exists() || !file.canRead())
return (null);
- // Special handling for directories
+ // Special handling for directories
if (file.isDirectory()) {
String contextPath =
((Context) container).getPath();
if (contextPath == null)
contextPath = "";
DirectoryBean directory = new DirectoryBean(normalized, file);
- ; // FIXME - Populate it with ResourceBean entries
+ File[] fileList = file.listFiles();
+ for (int i=0; i<fileList.length; i++) {
+ File currentFile = fileList[i];
+ ResourceBean newEntry = null;
+ if (currentFile.isDirectory()) {
+ newEntry =
+ new DirectoryBean(normalize(normalized + "/"
+ + currentFile.getName()),
+ currentFile);
+ } else {
+ newEntry =
+ new ResourceBean(normalize(normalized + "/"
+ + currentFile.getName()),
+ currentFile);
+ }
+ directory.addResource(newEntry);
+ }
return (directory.render(contextPath));
}
@@ -287,12 +360,179 @@
public long getResourceModified(String path) {
validate(path);
+
+ String contextPath = ((Context) container).getPath();
+ File file = file(normalize(path));
+ if (file != null)
+ return (file.lastModified());
+ else
+ return (-1L);
+
+ }
+
+
+ /**
+ * 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
+ * implementation should return getResourceModified(path).
+ * <p>
+ * <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.
+ *
+ * @param path Context-relative path starting with '/'
+ *
+ * @exception IllegalArgumentException if the path argument is null
+ * or does not start with a '/'
+ */
+ public long getResourceCreated(String path) {
+
+ validate(path);
- File file = new File(normalize(path));
+ File file = file(normalize(path));
if (file != null)
return (file.lastModified());
else
return (-1L);
+
+ }
+
+
+ /**
+ * Return the content length 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 the content length
+ * 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
+ */
+ public long getResourceLength(String path) {
+
+ validate(path);
+
+ // Look up the cached resource entry (if it exists) for this path
+ String normalized = normalize(path);
+ if (normalized == null)
+ return (-1L);
+ ResourceBean resource = null;
+ synchronized (resourcesCache) {
+ resource = (ResourceBean) resourcesCache.get(normalized);
+ }
+ if (resource != null) {
+ return (resource.getSize());
+ }
+
+ // No entry was found in the cache
+ File file = file(normalize(path));
+ 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
+ * contains child resources.
+ *
+ * @param path The path to the desired resource
+ */
+ public boolean isCollection(String path) {
+
+ validate(path);
+
+ File file = file(normalize(path));
+ if (file != null)
+ 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
+ * collection but has no children.
+ *
+ * @param path The path to the desired resource
+ */
+ public String[] getCollectionMembers(String path) {
+
+ validate(path);
+
+ File file = file(normalize(path));
+ if (file != null)
+ return (file.list());
+ else
+ return (null);
+
+ }
+
+
+ /**
+ * 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
+ * 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) {
+
+ // TODO : Implement it !
+ return false;
+
+ }
+
+
+ /**
+ * 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) {
+
+ validate(path);
+
+ File file = file(normalize(path));
+ if (file != null)
+ return (file.mkdir());
+ else
+ return (false);
+
+ }
+
+
+ /**
+ * 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
+ * resource is a non-empty collection.
+ *
+ * @param path The path to the desired resource
+ */
+ public boolean deleteResource(String path) {
+
+ validate(path);
+
+ File file = file(normalize(path));
+ if (file != null)
+ return (file.delete());
+ else
+ return (false);
}
1.2 +99 -4 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/JarResources.java
Index: JarResources.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/JarResources.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JarResources.java 2000/07/26 20:04:52 1.1
+++ JarResources.java 2000/07/30 23:20:22 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/JarResources.java,v 1.1 2000/07/26 20:04:52 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/07/26 20:04:52 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/JarResources.java,v 1.2 2000/07/30 23:20:22 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/07/30 23:20:22 $
*
* ====================================================================
*
@@ -104,7 +104,7 @@
* requested the first time (and passes the "cacheable" test).
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/07/26 20:04:52 $
+ * @version $Revision: 1.2 $ $Date: 2000/07/30 23:20:22 $
*/
public final class JarResources extends ResourcesBase {
@@ -340,6 +340,101 @@
else
return (-1L);
+ }
+
+
+ /**
+ * 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
+ * implementation should return getResourceModified(path).
+ *
+ * @param path The path to the desired resource
+ */
+ public long getResourceCreated(String path) {
+ return 0;
+ }
+
+
+ /**
+ * Return the content length 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 the content length
+ * 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
+ */
+ public long getResourceLength(String path) {
+ return -1;
+ }
+
+
+ /**
+ * 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
+ * contains child resources.
+ *
+ * @param path The path to the desired resource
+ */
+ public boolean isCollection(String path) {
+ 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
+ * collection but has no children.
+ *
+ * @param path The path to the desired resource
+ */
+ public String[] getCollectionMembers(String path) {
+ return null;
+ }
+
+
+ /**
+ * 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
+ * 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) {
+ return false;
+ }
+
+
+ /**
+ * 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) {
+ return false;
+ }
+
+
+ /**
+ * 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
+ * resource is a non-empty collection.
+ *
+ * @param path The path to the desired resource
+ */
+ public boolean deleteResource(String path) {
+ return false;
}
1.2 +94 -5 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/ResourcesBase.java
Index: ResourcesBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/ResourcesBase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourcesBase.java 2000/07/26 20:04:53 1.1
+++ ResourcesBase.java 2000/07/30 23:20:23 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/ResourcesBase.java,v 1.1 2000/07/26 20:04:53 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/07/26 20:04:53 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/resources/ResourcesBase.java,v 1.2 2000/07/30 23:20:23 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/07/30 23:20:23 $
*
* ====================================================================
*
@@ -101,7 +101,7 @@
* (such as a local or remote JAR file).
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/07/26 20:04:53 $
+ * @version $Revision: 1.2 $ $Date: 2000/07/30 23:20:23 $
*/
public abstract class ResourcesBase
@@ -593,6 +593,14 @@
/**
+ * Get the ResourceBean object associated with the given path.
+ *
+ * @param path The path to the desired resource
+ */
+ //public abstract ResourceBean getResourceBean(String path);
+
+
+ /**
* Return the resource located at the named path as an
* <code>InputStream</code> object.
* <p>
@@ -638,6 +646,87 @@
/**
+ * 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
+ * implementation should return getResourceModified(path).
+ *
+ * @param path The path to the desired resource
+ */
+ public abstract long getResourceCreated(String path);
+
+
+ /**
+ * Return the content length 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 the content length
+ * 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
+ */
+ public abstract long getResourceLength(String path);
+
+
+ /**
+ * 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
+ * contains child resources.
+ *
+ * @param path The path to the desired resource
+ */
+ public abstract boolean isCollection(String path);
+
+
+ /**
+ * 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
+ * collection but has no children.
+ *
+ * @param path The path to the desired resource
+ */
+ public abstract String[] getCollectionMembers(String path);
+
+
+ /**
+ * 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
+ * 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 abstract boolean setResource(String path, InputStream content);
+
+
+ /**
+ * 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 abstract boolean createCollection(String path);
+
+
+ /**
+ * 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
+ * resource is a non-empty collection.
+ *
+ * @param path The path to the desired resource
+ */
+ public abstract boolean deleteResource(String path);
+
+
+ /**
* Remove a property change listener from this component.
*
* @param listener The listener to remove
@@ -871,7 +960,7 @@
protected String normalize(String path) {
// Normalize the slashes and add leading slash if necessary
- String normalized = null;
+ String normalized = path;
if (normalized.indexOf('\\') >= 0)
normalized = normalized.replace('\\', '/');
if (!normalized.startsWith("/"))