You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by yo...@apache.org on 2006/12/26 15:22:14 UTC

svn commit: r490301 - in /tomcat/container/tc5.5.x: catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java webapps/docs/changelog.xml

Author: yoavs
Date: Tue Dec 26 06:22:13 2006
New Revision: 490301

URL: http://svn.apache.org/viewvc?view=rev&rev=490301
Log:
Bugzilla 40160: add to WebdavServlet documentation.  While at it, also change the Throwable caught to Exception, and use the data structure interfaces (List, Map, etc.) where possible instead of the concrete implementation classes (Vector, Hashtable, etc.)

Modified:
    tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml

Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java?view=diff&rev=490301&r1=490300&r2=490301
==============================================================================
--- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java (original)
+++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java Tue Dec 26 06:22:13 2006
@@ -25,9 +25,13 @@
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
+import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.Stack;
 import java.util.TimeZone;
 import java.util.Vector;
@@ -65,17 +69,16 @@
  * Servlet which adds support for WebDAV level 2. All the basic HTTP requests
  * are handled by the DefaultServlet.
  *
+ * Check out http://issues.apache.org/bugzilla/show_bug.cgi?id=40160 for a Filter
+ * that allows you to map this servlet anywhere inside a web application, not just
+ * the /* URL pattern.
+ *
  * @author Remy Maucherat
  * @version $Revision$ $Date$
  */
 
-public class WebdavServlet
-    extends DefaultServlet {
-
-
+public class WebdavServlet  extends DefaultServlet {
     // -------------------------------------------------------------- Constants
-
-
     private static final String METHOD_HEAD = "HEAD";
     private static final String METHOD_PROPFIND = "PROPFIND";
     private static final String METHOD_PROPPATCH = "PROPPATCH";
@@ -87,7 +90,7 @@
 
 
     /**
-     * Default depth is infite.
+     * Default depth is infinite.
      */
     private static final int INFINITY = 3; // To limit tree browsing a bit
 
@@ -159,7 +162,7 @@
     protected static final MD5Encoder md5Encoder = new MD5Encoder();
 
 
-
+    /** Static initializers for the GMT time zone. */
     static {
         creationDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
     }
@@ -171,10 +174,10 @@
     /**
      * Repository of the locks put on single resources.
      * <p>
-     * Key : path <br>
+     * Key : path <br />
      * Value : LockInfo
      */
-    private Hashtable resourceLocks = new Hashtable();
+    private Map resourceLocks = new Hashtable();
 
 
     /**
@@ -185,7 +188,7 @@
      * collection. Each element of the Vector is the path associated with
      * the lock-null resource.
      */
-    private Hashtable lockNullResources = new Hashtable();
+    private Map lockNullResources = new Hashtable();
 
 
     /**
@@ -194,7 +197,7 @@
      * Key : path <br>
      * Value : LockInfo
      */
-    private Vector collectionLocks = new Vector();
+    private List collectionLocks = new Vector();
 
 
     /**
@@ -217,10 +220,11 @@
         String value = null;
         try {
             value = getServletConfig().getInitParameter("secret");
-            if (value != null)
+            if (value != null) {
                 secret = value;
-        } catch (Throwable t) {
-            ;
+            }
+        } catch (Exception e) {
+            log("WebdavServlet.init: error reading secret from " + value);
         }
 
 
@@ -365,7 +369,7 @@
         }
 
         // Properties which are to be displayed.
-        Vector properties = null;
+        List properties = null;
         // Propfind depth
         int depth = INFINITY;
         // Propfind type
@@ -440,7 +444,7 @@
                         propertyName = nodeName;
                     }
                     // href is a live property which is handled differently
-                    properties.addElement(propertyName);
+                    properties.add(propertyName);
                     break;
                 }
             }
@@ -456,14 +460,12 @@
             int slash = path.lastIndexOf('/');
             if (slash != -1) {
                 String parentPath = path.substring(0, slash);
-                Vector currentLockNullResources =
-                    (Vector) lockNullResources.get(parentPath);
+                List currentLockNullResources =
+                    (List) lockNullResources.get(parentPath);
                 if (currentLockNullResources != null) {
-                    Enumeration lockNullResourcesList =
-                        currentLockNullResources.elements();
-                    while (lockNullResourcesList.hasMoreElements()) {
-                        String lockNullPath = (String)
-                            lockNullResourcesList.nextElement();
+                    Iterator iter = currentLockNullResources.iterator();
+                    while (iter.hasNext()) {
+                        String lockNullPath = (String) iter.next();
                         if (lockNullPath.equals(path)) {
                             resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
                             resp.setContentType("text/xml; charset=UTF-8");
@@ -542,6 +544,7 @@
                             stackBelow.push(newPath);
                         }
                     } catch (NamingException e) {
+                        log("WebdavServlet: naming exception processing " + currentPath);
                         resp.sendError
                             (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                              path);
@@ -554,14 +557,12 @@
                     if (lockPath.endsWith("/"))
                         lockPath =
                             lockPath.substring(0, lockPath.length() - 1);
-                    Vector currentLockNullResources =
-                        (Vector) lockNullResources.get(lockPath);
+                    List currentLockNullResources =
+                        (List) lockNullResources.get(lockPath);
                     if (currentLockNullResources != null) {
-                        Enumeration lockNullResourcesList =
-                            currentLockNullResources.elements();
-                        while (lockNullResourcesList.hasMoreElements()) {
-                            String lockNullPath = (String)
-                                lockNullResourcesList.nextElement();
+                        Iterator iter = currentLockNullResources.iterator();
+                        while (iter.hasNext()) {
+                            String lockNullPath = (String) iter.next();
                             parseLockNullProperties
                                 (req, generatedXML, lockNullPath, type,
                                  properties);
@@ -1001,8 +1002,6 @@
             exists = false;
         }
 
-        Enumeration locksList = null;
-
         if (lockRequestType == LOCK_CREATION) {
 
             // Generating lock id
@@ -1021,10 +1020,11 @@
 
                 // Checking if a child resource of this collection is
                 // already locked
-                Vector lockPaths = new Vector();
-                locksList = collectionLocks.elements();
-                while (locksList.hasMoreElements()) {
-                    LockInfo currentLock = (LockInfo) locksList.nextElement();
+                List lockPaths = new Vector();
+
+                Iterator iter = collectionLocks.iterator();
+                while (iter.hasNext()) {
+                    LockInfo currentLock = (LockInfo) iter.next();
                     if (currentLock.hasExpired()) {
                         resourceLocks.remove(currentLock.path);
                         continue;
@@ -1033,10 +1033,14 @@
                          ((currentLock.isExclusive()) ||
                           (lock.isExclusive())) ) {
                         // A child collection of this collection is locked
-                        lockPaths.addElement(currentLock.path);
+                        lockPaths.add(currentLock.path);
                     }
                 }
-                locksList = resourceLocks.elements();
+
+                // Yikes: modifying the collection not by the iterator's object,
+                // but by one of its attributes.  That means we can't use a
+                // normal java.util.Iterator here, because Iterator is fail-fast. ;(
+                Enumeration locksList = Collections.enumeration(resourceLocks.values());
                 while (locksList.hasMoreElements()) {
                     LockInfo currentLock = (LockInfo) locksList.nextElement();
                     if (currentLock.hasExpired()) {
@@ -1047,17 +1051,13 @@
                          ((currentLock.isExclusive()) ||
                           (lock.isExclusive())) ) {
                         // A child resource of this collection is locked
-                        lockPaths.addElement(currentLock.path);
+                        lockPaths.add(currentLock.path);
                     }
                 }
 
                 if (!lockPaths.isEmpty()) {
-
                     // One of the child paths was locked
                     // We generate a multistatus error report
-
-                    Enumeration lockPathsList = lockPaths.elements();
-
                     resp.setStatus(WebdavStatus.SC_CONFLICT);
 
                     XMLWriter generatedXML = new XMLWriter();
@@ -1067,13 +1067,15 @@
                         (null, "multistatus" + generateNamespaceDeclarations(),
                          XMLWriter.OPENING);
 
-                    while (lockPathsList.hasMoreElements()) {
+
+                    iter = lockPaths.iterator();
+                    while (iter.hasNext()) {
                         generatedXML.writeElement(null, "response",
                                                   XMLWriter.OPENING);
                         generatedXML.writeElement(null, "href",
                                                   XMLWriter.OPENING);
                         generatedXML
-                            .writeText((String) lockPathsList.nextElement());
+                            .writeText((String) iter.next());
                         generatedXML.writeElement(null, "href",
                                                   XMLWriter.CLOSING);
                         generatedXML.writeElement(null, "status",
@@ -1103,12 +1105,10 @@
                 boolean addLock = true;
 
                 // Checking if there is already a shared lock on this path
-                locksList = collectionLocks.elements();
-                while (locksList.hasMoreElements()) {
-
-                    LockInfo currentLock = (LockInfo) locksList.nextElement();
+                iter = collectionLocks.iterator();
+                while (iter.hasNext()) {
+                    LockInfo currentLock = (LockInfo) iter.next();
                     if (currentLock.path.equals(lock.path)) {
-
                         if (currentLock.isExclusive()) {
                             resp.sendError(WebdavStatus.SC_LOCKED);
                             return;
@@ -1119,17 +1119,15 @@
                             }
                         }
 
-                        currentLock.tokens.addElement(lockToken);
+                        currentLock.tokens.add(lockToken);
                         lock = currentLock;
                         addLock = false;
-
                     }
-
                 }
 
                 if (addLock) {
-                    lock.tokens.addElement(lockToken);
-                    collectionLocks.addElement(lock);
+                    lock.tokens.add(lockToken);
+                    collectionLocks.add(lock);
                 }
 
             } else {
@@ -1146,13 +1144,13 @@
                         resp.sendError(WebdavStatus.SC_PRECONDITION_FAILED);
                         return;
                     } else {
-                        presentLock.tokens.addElement(lockToken);
+                        presentLock.tokens.add(lockToken);
                         lock = presentLock;
                     }
 
                 } else {
 
-                    lock.tokens.addElement(lockToken);
+                    lock.tokens.add(lockToken);
                     resourceLocks.put(lock.path, lock);
 
                     // Checking if a resource exists at this path
@@ -1168,14 +1166,14 @@
                         int slash = lock.path.lastIndexOf('/');
                         String parentPath = lock.path.substring(0, slash);
 
-                        Vector lockNulls =
-                            (Vector) lockNullResources.get(parentPath);
+                        List lockNulls =
+                            (List) lockNullResources.get(parentPath);
                         if (lockNulls == null) {
                             lockNulls = new Vector();
                             lockNullResources.put(parentPath, lockNulls);
                         }
 
-                        lockNulls.addElement(lock.path);
+                        lockNulls.add(lock.path);
 
                     }
                     // Add the Lock-Token header as by RFC 2518 8.10.1
@@ -1197,14 +1195,11 @@
             // Checking resource locks
 
             LockInfo toRenew = (LockInfo) resourceLocks.get(path);
-            Enumeration tokenList = null;
             if (lock != null) {
-
                 // At least one of the tokens of the locks must have been given
-
-                tokenList = toRenew.tokens.elements();
-                while (tokenList.hasMoreElements()) {
-                    String token = (String) tokenList.nextElement();
+                Iterator iter = toRenew.tokens.iterator();
+                while (iter.hasNext()) {
+                    String token = (String) iter.next();
                     if (ifHeader.indexOf(token) != -1) {
                         toRenew.expiresAt = lock.expiresAt;
                         lock = toRenew;
@@ -1214,15 +1209,13 @@
             }
 
             // Checking inheritable collection locks
-
-            Enumeration collectionLocksList = collectionLocks.elements();
-            while (collectionLocksList.hasMoreElements()) {
-                toRenew = (LockInfo) collectionLocksList.nextElement();
+            Iterator iter = collectionLocks.iterator();
+            while (iter.hasNext()) {
+                toRenew = (LockInfo) iter.next();
                 if (path.equals(toRenew.path)) {
-
-                    tokenList = toRenew.tokens.elements();
-                    while (tokenList.hasMoreElements()) {
-                        String token = (String) tokenList.nextElement();
+                    Iterator tokenIter = toRenew.tokens.iterator();
+                    while (tokenIter.hasNext()) {
+                        String token = (String) tokenIter.next();
                         if (ifHeader.indexOf(token) != -1) {
                             toRenew.expiresAt = lock.expiresAt;
                             lock = toRenew;
@@ -1286,16 +1279,14 @@
         // Checking resource locks
 
         LockInfo lock = (LockInfo) resourceLocks.get(path);
-        Enumeration tokenList = null;
+        Iterator iter = null;
         if (lock != null) {
-
             // At least one of the tokens of the locks must have been given
-
-            tokenList = lock.tokens.elements();
-            while (tokenList.hasMoreElements()) {
-                String token = (String) tokenList.nextElement();
+            iter = lock.tokens.iterator();
+            while (iter.hasNext()) {
+                String token = (String) iter.next();
                 if (lockTokenHeader.indexOf(token) != -1) {
-                    lock.tokens.removeElement(token);
+                    iter.remove();
                 }
             }
 
@@ -1308,23 +1299,21 @@
         }
 
         // Checking inheritable collection locks
-
-        Enumeration collectionLocksList = collectionLocks.elements();
-        while (collectionLocksList.hasMoreElements()) {
-            lock = (LockInfo) collectionLocksList.nextElement();
+        iter = collectionLocks.iterator();
+        while (iter.hasNext()) {
+            lock = (LockInfo) iter.next();
             if (path.equals(lock.path)) {
-
-                tokenList = lock.tokens.elements();
-                while (tokenList.hasMoreElements()) {
-                    String token = (String) tokenList.nextElement();
+                Iterator tokenIter = lock.tokens.iterator();
+                while (tokenIter.hasNext()) {
+                    String token = (String) tokenIter.next();
                     if (lockTokenHeader.indexOf(token) != -1) {
-                        lock.tokens.removeElement(token);
+                        tokenIter.remove();
                         break;
                     }
                 }
 
                 if (lock.tokens.isEmpty()) {
-                    collectionLocks.removeElement(lock);
+                    iter.remove();
                     // Removing any lock-null resource which would be present
                     lockNullResources.remove(path);
                 }
@@ -1333,7 +1322,6 @@
         }
 
         resp.setStatus(WebdavStatus.SC_NO_CONTENT);
-
     }
 
     /**
@@ -1346,30 +1334,32 @@
      * @param path Path to be normalized
      */
     protected String normalize(String path) {
-
-        if (path == null)
+        if (path == null) {
             return null;
+        }
 
         // Create a place for the normalized path
         String normalized = path;
 
-        if (normalized == null)
-            return (null);
-
-        if (normalized.equals("/."))
+        if (normalized.equals("/.")) {
             return "/";
+        }
 
         // Normalize the slashes and add leading slash if necessary
-        if (normalized.indexOf('\\') >= 0)
+        if (normalized.indexOf('\\') >= 0) {
             normalized = normalized.replace('\\', '/');
-        if (!normalized.startsWith("/"))
+        }
+
+        if (!normalized.startsWith("/")) {
             normalized = "/" + normalized;
+        }
 
         // Resolve occurrences of "//" in the normalized path
         while (true) {
             int index = normalized.indexOf("//");
-            if (index < 0)
+            if (index < 0) {
                 break;
+            }
             normalized = normalized.substring(0, index) +
                 normalized.substring(index + 1);
         }
@@ -1377,8 +1367,9 @@
         // Resolve occurrences of "/./" in the normalized path
         while (true) {
             int index = normalized.indexOf("/./");
-            if (index < 0)
+            if (index < 0) {
                 break;
+            }
             normalized = normalized.substring(0, index) +
                 normalized.substring(index + 2);
         }
@@ -1386,10 +1377,13 @@
         // Resolve occurrences of "/../" in the normalized path
         while (true) {
             int index = normalized.indexOf("/../");
-            if (index < 0)
+            if (index < 0) {
                 break;
-            if (index == 0)
+            }
+            if (index == 0) {
                 return (null);  // Trying to go outside our context
+            }
+
             int index2 = normalized.lastIndexOf('/', index - 1);
             normalized = normalized.substring(0, index2) +
                 normalized.substring(index + 3);
@@ -1397,7 +1391,6 @@
 
         // Return the normalized path that we have completed
         return (normalized);
-
     }
 
 
@@ -1422,19 +1415,19 @@
      * are present on the resource).
      */
     private boolean isLocked(HttpServletRequest req) {
-
         String path = getRelativePath(req);
 
         String ifHeader = req.getHeader("If");
-        if (ifHeader == null)
+        if (ifHeader == null) {
             ifHeader = "";
+        }
 
         String lockTokenHeader = req.getHeader("Lock-Token");
-        if (lockTokenHeader == null)
+        if (lockTokenHeader == null) {
             lockTokenHeader = "";
+        }
 
         return isLocked(path, ifHeader + lockTokenHeader);
-
     }
 
 
@@ -1448,53 +1441,49 @@
      * are present on the resource).
      */
     private boolean isLocked(String path, String ifHeader) {
-
         // Checking resource locks
-
         LockInfo lock = (LockInfo) resourceLocks.get(path);
-        Enumeration tokenList = null;
         if ((lock != null) && (lock.hasExpired())) {
             resourceLocks.remove(path);
         } else if (lock != null) {
-
             // At least one of the tokens of the locks must have been given
-
-            tokenList = lock.tokens.elements();
+            Iterator iter = lock.tokens.iterator();
             boolean tokenMatch = false;
-            while (tokenList.hasMoreElements()) {
-                String token = (String) tokenList.nextElement();
-                if (ifHeader.indexOf(token) != -1)
+            while (iter.hasNext()) {
+                String token = (String) iter.next();
+                if (ifHeader.indexOf(token) != -1) {
                     tokenMatch = true;
+                }
             }
-            if (!tokenMatch)
-                return true;
 
+            if (!tokenMatch) {
+                return true;
+            }
         }
 
         // Checking inheritable collection locks
-
-        Enumeration collectionLocksList = collectionLocks.elements();
-        while (collectionLocksList.hasMoreElements()) {
-            lock = (LockInfo) collectionLocksList.nextElement();
+        Iterator iter = collectionLocks.iterator();
+        while (iter.hasNext()) {
+            lock = (LockInfo) iter.next();
             if (lock.hasExpired()) {
-                collectionLocks.removeElement(lock);
+                iter.remove();
             } else if (path.startsWith(lock.path)) {
-
-                tokenList = lock.tokens.elements();
+                Iterator tokenIter = lock.tokens.iterator();
                 boolean tokenMatch = false;
-                while (tokenList.hasMoreElements()) {
-                    String token = (String) tokenList.nextElement();
-                    if (ifHeader.indexOf(token) != -1)
+                while (tokenIter.hasNext()) {
+                    String token = (String) tokenIter.next();
+                    if (ifHeader.indexOf(token) != -1) {
                         tokenMatch = true;
+                    }
                 }
-                if (!tokenMatch)
-                    return true;
 
+                if (!tokenMatch) {
+                    return true;
+                }
             }
         }
 
         return false;
-
     }
 
 
@@ -1869,6 +1858,7 @@
         try {
             enumeration = resources.list(path);
         } catch (NamingException e) {
+            log("WebdavServlet: naming exception listing resources for " + path);
             errorList.put(path, new Integer
                 (WebdavStatus.SC_INTERNAL_SERVER_ERROR));
             return;
@@ -1877,16 +1867,14 @@
         while (enumeration.hasMoreElements()) {
             NameClassPair ncPair = (NameClassPair) enumeration.nextElement();
             String childName = path;
-            if (!childName.equals("/"))
+            if (!childName.equals("/")) {
                 childName += "/";
-            childName += ncPair.getName();
+            }
 
+            childName += ncPair.getName();
             if (isLocked(childName, ifHeader + lockTokenHeader)) {
-
                 errorList.put(childName, new Integer(WebdavStatus.SC_LOCKED));
-
             } else {
-
                 try {
                     Object object = resources.lookup(childName);
                     if (object instanceof DirContext) {
@@ -1922,10 +1910,10 @@
      *
      * @param req Servlet request
      * @param resp Servlet response
-     * @param errorList List of error to be displayed
+     * @param errors The errors to be displayed
      */
     private void sendReport(HttpServletRequest req, HttpServletResponse resp,
-                            Hashtable errorList)
+                            Map errors)
         throws ServletException, IOException {
 
         resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
@@ -1940,18 +1928,18 @@
                                   + generateNamespaceDeclarations(),
                                   XMLWriter.OPENING);
 
-        Enumeration pathList = errorList.keys();
-        while (pathList.hasMoreElements()) {
-
-            String errorPath = (String) pathList.nextElement();
-            int errorCode = ((Integer) errorList.get(errorPath)).intValue();
+        Iterator iter = errors.keySet().iterator();
+        while (iter.hasNext()) {
+            String errorPath = (String) iter.next();
+            int errorCode = ((Integer) errors.get(errorPath)).intValue();
 
             generatedXML.writeElement(null, "response", XMLWriter.OPENING);
 
             generatedXML.writeElement(null, "href", XMLWriter.OPENING);
             String toAppend = errorPath.substring(relativePath.length());
-            if (!toAppend.startsWith("/"))
+            if (!toAppend.startsWith("/")) {
                 toAppend = "/" + toAppend;
+            }
             generatedXML.writeText(absoluteUri + toAppend);
             generatedXML.writeElement(null, "href", XMLWriter.CLOSING);
             generatedXML.writeElement(null, "status", XMLWriter.OPENING);
@@ -1961,7 +1949,6 @@
             generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
 
             generatedXML.writeElement(null, "response", XMLWriter.CLOSING);
-
         }
 
         generatedXML.writeElement(null, "multistatus", XMLWriter.CLOSING);
@@ -1987,7 +1974,7 @@
     private void parseProperties(HttpServletRequest req,
                                  XMLWriter generatedXML,
                                  String path, int type,
-                                 Vector propertiesVector) {
+                                 List propertiesVector) {
 
         // Exclude any resource in the /WEB-INF and /META-INF subdirectories
         // (the "toUpperCase()" avoids problems on Windows systems)
@@ -2123,18 +2110,16 @@
 
         case FIND_BY_PROPERTY :
 
-            Vector propertiesNotFound = new Vector();
+            List propertiesNotFound = new Vector();
 
             // Parse the list of properties
 
             generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
             generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
 
-            Enumeration properties = propertiesVector.elements();
-
-            while (properties.hasMoreElements()) {
-
-                String property = (String) properties.nextElement();
+            Iterator iter = propertiesVector.iterator();
+            while (iter.hasNext()) {
+                String property = (String) iter.next();
 
                 if (property.equals("creationdate")) {
                     generatedXML.writeProperty
@@ -2148,14 +2133,14 @@
                         (null, "displayname", XMLWriter.CLOSING);
                 } else if (property.equals("getcontentlanguage")) {
                     if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                     } else {
                         generatedXML.writeElement(null, "getcontentlanguage",
                                                   XMLWriter.NO_CONTENT);
                     }
                 } else if (property.equals("getcontentlength")) {
                     if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                     } else {
                         generatedXML.writeProperty
                             (null, "getcontentlength",
@@ -2163,7 +2148,7 @@
                     }
                 } else if (property.equals("getcontenttype")) {
                     if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                     } else {
                         generatedXML.writeProperty
                             (null, "getcontenttype",
@@ -2172,14 +2157,14 @@
                     }
                 } else if (property.equals("getetag")) {
                     if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                     } else {
                         generatedXML.writeProperty
                             (null, "getetag", getETag(cacheEntry.attributes));
                     }
                 } else if (property.equals("getlastmodified")) {
                     if (cacheEntry.context != null) {
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                     } else {
                         generatedXML.writeProperty
                             (null, "getlastmodified", FastHttpDateFormat.formatDate
@@ -2214,9 +2199,9 @@
                                               XMLWriter.CLOSING);
                 } else if (property.equals("lockdiscovery")) {
                     if (!generateLockDiscovery(path, generatedXML))
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                 } else {
-                    propertiesNotFound.addElement(property);
+                    propertiesNotFound.add(property);
                 }
 
             }
@@ -2227,20 +2212,18 @@
             generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
             generatedXML.writeElement(null, "propstat", XMLWriter.CLOSING);
 
-            Enumeration propertiesNotFoundList = propertiesNotFound.elements();
-
-            if (propertiesNotFoundList.hasMoreElements()) {
-
+            if (propertiesNotFound.size() > 0) {
                 status = new String("HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND
                                     + " " + WebdavStatus.getStatusText
                                     (WebdavStatus.SC_NOT_FOUND));
-
+                
                 generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
                 generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
-
-                while (propertiesNotFoundList.hasMoreElements()) {
+                
+                Iterator notFoundIter = propertiesNotFound.iterator();
+                while (notFoundIter.hasNext()) {
                     generatedXML.writeElement
-                        (null, (String) propertiesNotFoundList.nextElement(),
+                        (null, (String) notFoundIter.next(),
                          XMLWriter.NO_CONTENT);
                 }
 
@@ -2274,7 +2257,7 @@
     private void parseLockNullProperties(HttpServletRequest req,
                                          XMLWriter generatedXML,
                                          String path, int type,
-                                         Vector propertiesVector) {
+                                         List propertiesVector) {
 
         // Exclude any resource in the /WEB-INF and /META-INF subdirectories
         // (the "toUpperCase()" avoids problems on Windows systems)
@@ -2400,18 +2383,16 @@
 
         case FIND_BY_PROPERTY :
 
-            Vector propertiesNotFound = new Vector();
+            List propertiesNotFound = new Vector();
 
             // Parse the list of properties
 
             generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
             generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
 
-            Enumeration properties = propertiesVector.elements();
-
-            while (properties.hasMoreElements()) {
-
-                String property = (String) properties.nextElement();
+            Iterator iter = propertiesVector.iterator();
+            while (iter.hasNext()) {
+                String property = (String) iter.next();
 
                 if (property.equals("creationdate")) {
                     generatedXML.writeProperty
@@ -2463,9 +2444,9 @@
                                               XMLWriter.CLOSING);
                 } else if (property.equals("lockdiscovery")) {
                     if (!generateLockDiscovery(path, generatedXML))
-                        propertiesNotFound.addElement(property);
+                        propertiesNotFound.add(property);
                 } else {
-                    propertiesNotFound.addElement(property);
+                    propertiesNotFound.add(property);
                 }
 
             }
@@ -2476,10 +2457,7 @@
             generatedXML.writeElement(null, "status", XMLWriter.CLOSING);
             generatedXML.writeElement(null, "propstat", XMLWriter.CLOSING);
 
-            Enumeration propertiesNotFoundList = propertiesNotFound.elements();
-
-            if (propertiesNotFoundList.hasMoreElements()) {
-
+            if (propertiesNotFound.size() > 0) {
                 status = new String("HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND
                                     + " " + WebdavStatus.getStatusText
                                     (WebdavStatus.SC_NOT_FOUND));
@@ -2487,9 +2465,10 @@
                 generatedXML.writeElement(null, "propstat", XMLWriter.OPENING);
                 generatedXML.writeElement(null, "prop", XMLWriter.OPENING);
 
-                while (propertiesNotFoundList.hasMoreElements()) {
+                Iterator notFoundIter = propertiesNotFound.iterator();
+                while (notFoundIter.hasNext()) {
                     generatedXML.writeElement
-                        (null, (String) propertiesNotFoundList.nextElement(),
+                        (null, (String) notFoundIter.next(),
                          XMLWriter.NO_CONTENT);
                 }
 
@@ -2519,12 +2498,9 @@
      */
     private boolean generateLockDiscovery
         (String path, XMLWriter generatedXML) {
-
-        LockInfo resourceLock = (LockInfo) resourceLocks.get(path);
-        Enumeration collectionLocksList = collectionLocks.elements();
-
         boolean wroteStart = false;
 
+        LockInfo resourceLock = (LockInfo) resourceLocks.get(path);
         if (resourceLock != null) {
             wroteStart = true;
             generatedXML.writeElement(null, "lockdiscovery",
@@ -2532,9 +2508,9 @@
             resourceLock.toXML(generatedXML);
         }
 
-        while (collectionLocksList.hasMoreElements()) {
-            LockInfo currentLock =
-                (LockInfo) collectionLocksList.nextElement();
+        Iterator iter = collectionLocks.iterator();
+        while (iter.hasNext()) {
+            LockInfo currentLock = (LockInfo) iter.next();
             if (path.startsWith(currentLock.path)) {
                 if (!wroteStart) {
                     wroteStart = true;
@@ -2649,7 +2625,7 @@
         String scope = "exclusive";
         int depth = 0;
         String owner = "";
-        Vector tokens = new Vector();
+        List tokens = new Vector();
         long expiresAt = 0;
         Date creationDate = new Date();
 
@@ -2668,12 +2644,12 @@
             result += "Owner:" + owner + "\n";
             result += "Expiration:"
                 + FastHttpDateFormat.formatDate(expiresAt, null) + "\n";
-            Enumeration tokensList = tokens.elements();
-            while (tokensList.hasMoreElements()) {
-                result += "Token:" + tokensList.nextElement() + "\n";
+
+            Iterator iter = tokens.iterator();
+            while (iter.hasNext()) {
+                result += "Token:" + iter.next() + "\n";
             }
             return result;
-
         }
 
 
@@ -2729,11 +2705,12 @@
             generatedXML.writeElement(null, "timeout", XMLWriter.CLOSING);
 
             generatedXML.writeElement(null, "locktoken", XMLWriter.OPENING);
-            Enumeration tokensList = tokens.elements();
-            while (tokensList.hasMoreElements()) {
+
+            Iterator iter = tokens.iterator();
+            while (iter.hasNext()) {
                 generatedXML.writeElement(null, "href", XMLWriter.OPENING);
                 generatedXML.writeText("opaquelocktoken:"
-                                       + tokensList.nextElement());
+                                       + iter.next());
                 generatedXML.writeElement(null, "href", XMLWriter.CLOSING);
             }
             generatedXML.writeElement(null, "locktoken", XMLWriter.CLOSING);

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?view=diff&rev=490301&r1=490300&r2=490301
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Tue Dec 26 06:22:13 2006
@@ -293,6 +293,11 @@
         <bug>40257</bug>: Update Manager webapp howto on remote deployment to reflect
         need for explicit path in one specific use-case.  Thank to Venkatesh Jayaraman. (yoavs)
       </fix>
+      <update>
+        <bug>40160</bug>: add reference to the Filter proposed in this Bugzilla item to the WebdavServlet.
+        While at it, give the WebdavServlet some long-overdue TLC by cleaning up some of the old data
+        structures in favor of modern (but still JDK 1.4-compliant) interfaces. (yoavs)
+      </update>
     </changelog>
   </subsection> 
   <subsection name="Cluster">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org