You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/01/23 20:36:44 UTC

svn commit: r614636 - /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/util/URLChangeTracker.java

Author: hlship
Date: Wed Jan 23 11:36:42 2008
New Revision: 614636

URL: http://svn.apache.org/viewvc?rev=614636&view=rev
Log:
TAPESTRY-2074: Tapestry fails with URISyntaxException when the project folder contains spaces

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/util/URLChangeTracker.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/util/URLChangeTracker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/util/URLChangeTracker.java?rev=614636&r1=614635&r2=614636&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/util/URLChangeTracker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/util/URLChangeTracker.java Wed Jan 23 11:36:42 2008
@@ -17,17 +17,16 @@
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newConcurrentMap;
 
 import java.io.File;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Map;
 
 /**
- * Given a (growing) set of URLs, can periodically check to see if any of the underlying resources
- * has changed. This class is capable of using either millisecond-level granularity or second-level
- * granularity. Millisecond-level granularity is used by default. Second-level granularity is
- * provided for compatibility with browsers vis-a-vis resource caching -- that's how granular they
- * get with their "If-Modified-Since", "Last-Modified" and "Expires" headers.
+ * Given a (growing) set of URLs, can periodically check to see if any of the underlying resources has changed. This
+ * class is capable of using either millisecond-level granularity or second-level granularity. Millisecond-level
+ * granularity is used by default. Second-level granularity is provided for compatibility with browsers vis-a-vis
+ * resource caching -- that's how granular they get with their "If-Modified-Since", "Last-Modified" and "Expires"
+ * headers.
  */
 public class URLChangeTracker
 {
@@ -46,8 +45,7 @@
     }
 
     /**
-     * Creates a new URL change tracker, using either millisecond-level granularity or second-level
-     * granularity.
+     * Creates a new URL change tracker, using either millisecond-level granularity or second-level granularity.
      *
      * @param granularitySeconds whether or not to use second-level granularity
      */
@@ -57,8 +55,8 @@
     }
 
     /**
-     * Stores a new URL into the tracker, or returns the previous time stamp for a previously added
-     * URL. Filters out all non-file URLs.
+     * Stores a new URL into the tracker, or returns the previous time stamp for a previously added URL. Filters out all
+     * non-file URLs.
      *
      * @param url of the resource to add
      * @return the current timestamp for the URL, or 0 if not a file URL
@@ -67,34 +65,40 @@
     {
         if (!url.getProtocol().equals("file")) return 0;
 
-        try
-        {
-            URI resourceURI = url.toURI();
-            File resourceFile = new File(resourceURI);
+        File resourceFile = toFile(url);
 
-            if (_fileToTimestamp.containsKey(resourceFile)) return _fileToTimestamp.get(resourceFile);
+        if (_fileToTimestamp.containsKey(resourceFile)) return _fileToTimestamp.get(resourceFile);
 
-            long timestamp = readTimestamp(resourceFile);
+        long timestamp = readTimestamp(resourceFile);
 
-            // A quick and imperfect fix for TAPESTRY-1918.  When a file
-            // is added, add the directory containing the file as well.
+        // A quick and imperfect fix for TAPESTRY-1918.  When a file
+        // is added, add the directory containing the file as well.
 
-            _fileToTimestamp.put(resourceFile, timestamp);
+        _fileToTimestamp.put(resourceFile, timestamp);
 
-            File dir = resourceFile.getParentFile();
+        File dir = resourceFile.getParentFile();
 
-            if (!_fileToTimestamp.containsKey(dir))
-            {
-                long dirTimestamp = readTimestamp(dir);
-                _fileToTimestamp.put(dir, dirTimestamp);
-            }
+        if (!_fileToTimestamp.containsKey(dir))
+        {
+            long dirTimestamp = readTimestamp(dir);
+            _fileToTimestamp.put(dir, dirTimestamp);
+        }
 
 
-            return timestamp;
+        return timestamp;
+    }
+
+    private File toFile(URL url)
+    {
+        // http://weblogs.java.net/blog/kohsuke/archive/2007/04/how_to_convert.html
+
+        try
+        {
+            return new File(url.toURI());
         }
         catch (URISyntaxException ex)
         {
-            throw new RuntimeException(ex);
+            return new File(url.getPath());
         }
     }
 
@@ -107,8 +111,7 @@
     }
 
     /**
-     * Re-acquires the last updated timestamp for each URL and returns true if any timestamp has
-     * changed.
+     * Re-acquires the last updated timestamp for each URL and returns true if any timestamp has changed.
      */
     public boolean containsChanges()
     {
@@ -133,8 +136,7 @@
     }
 
     /**
-     * Returns the time that the specified file was last modified, possibly rounded down to the
-     * nearest second.
+     * Returns the time that the specified file was last modified, possibly rounded down to the nearest second.
      */
     private long readTimestamp(File file)
     {
@@ -153,8 +155,7 @@
     }
 
     /**
-     * Needed for testing; changes file timestamps so that a change will be detected by
-     * {@link #containsChanges()}.
+     * Needed for testing; changes file timestamps so that a change will be detected by {@link #containsChanges()}.
      */
     public void forceChange()
     {