You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/07/23 15:23:42 UTC

svn commit: r424736 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/asset/AssetService.java test/org/apache/tapestry/asset/TestUnprotectedAsset.java

Author: jkuhnert
Date: Sun Jul 23 06:23:42 2006
New Revision: 424736

URL: http://svn.apache.org/viewvc?rev=424736&view=rev
Log:
Another fix for asset .. path resolution

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java?rev=424736&r1=424735&r2=424736&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java Sun Jul 23 06:23:42 2006
@@ -242,7 +242,7 @@
                 return;
             }
             
-            URL resourceURL = _classResolver.getResource(FilenameUtils.normalize(translateCssPath(path)));
+            URL resourceURL = _classResolver.getResource(translatePath(path));
             
             if (resourceURL == null)
                 throw new ApplicationRuntimeException(AssetMessages.noSuchResource(path));
@@ -265,28 +265,32 @@
 
     /**
      * Utility that helps to resolve css file relative resources included
-     * in a css temlpate via "url('../images/foo.gif')" style css.
+     * in a css temlpate via "url('../images/foo.gif')" or fix paths containing 
+     * relative resource ".." style notation.
      * 
-     * @param path The incoming path to check for css resource relativity
+     * @param path The incoming path to check for relativity.
      * @return The path unchanged if not containing a css relative path, otherwise
      *          returns the path without the css filename in it so the resource is resolvable
      *          directly from the path.
      */
-    String translateCssPath(String path)
+    String translatePath(String path)
     {
         if (path == null) return null;
         
+        String ret = FilenameUtils.normalize(path);
+        ret = FilenameUtils.separatorsToUnix(ret);
+        
         // don't parse out actual css files
-        if (path.endsWith(".css")) return path;
+        if (ret.endsWith(".css")) return ret;
         
-        int index = path.lastIndexOf(".css");
-        if (index <= -1) return path;
+        int index = ret.lastIndexOf(".css");
+        if (index <= -1) return ret;
         
         // now need to parse out whatever css file was referenced to get the real path
-        int pathEnd = path.lastIndexOf("/", index);
-        if (pathEnd <= -1) return path;
+        int pathEnd = ret.lastIndexOf("/", index);
+        if (pathEnd <= -1) return ret;
         
-        return path.substring(0, pathEnd + 1) + path.substring(index + 4, path.length());
+        return ret.substring(0, pathEnd + 1) + ret.substring(index + 4, ret.length());
     }
     
     /**
@@ -300,7 +304,7 @@
      * @since 4.1
      */
     
-    protected boolean cachedResource(URL resourceURL)
+    boolean cachedResource(URL resourceURL)
     {
         File resource = new File(resourceURL.getFile());
         if (!resource.exists()) return false;

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java?rev=424736&r1=424735&r2=424736&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/TestUnprotectedAsset.java Sun Jul 23 06:23:42 2006
@@ -168,14 +168,14 @@
         AssetService service = new AssetService();
         String path = "/dojo/src/widget/template/HtmlComboBox.cssimages/foo.gif";
         
-        assertEquals("/dojo/src/widget/template/images/foo.gif", service.translateCssPath(path));
+        assertEquals("/dojo/src/widget/template/images/foo.gif", service.translatePath(path));
         assertEquals("/boo/templates/things/", 
-                service.translateCssPath("/boo/templates/somethingdumb.cssthings/"));
+                service.translatePath("/boo/templates/somethingdumb.cssthings/"));
         assertEquals("/foo/path/css/images.png", 
-                service.translateCssPath("/foo/path/css/images.png"));
+                service.translatePath("/foo/path/css/images.png"));
         assertEquals("/things/mytemplate.css",
-                service.translateCssPath("/things/mytemplate.css"));
-        assertNull(service.translateCssPath(null));
+                service.translatePath("/things/mytemplate.css"));
+        assertNull(service.translatePath(null));
     }
     
     public void test_Resource_Link_Paths()