tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r481048 - in /tapestry/tapestry5/tapestry-ioc/trunk/src: main/java/org/apache/tapestry/ioc/internal/util/AbstractResource.java test/java/org/apache/tapestry/ioc/internal/util/ClasspathResourceTest.java
Date Thu, 30 Nov 2006 19:47:06 GMT
Author: hlship
Date: Thu Nov 30 11:47:05 2006
New Revision: 481048

URL: http://svn.apache.org/viewvc?view=rev&rev=481048
Log:
Allow for "root resources" (with a path of "" or "/") and properly handler resources relative
to such root resources.

Modified:
    tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/AbstractResource.java
    tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/util/ClasspathResourceTest.java

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/AbstractResource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/AbstractResource.java?view=diff&rev=481048&r1=481047&r2=481048
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/AbstractResource.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/main/java/org/apache/tapestry/ioc/internal/util/AbstractResource.java
Thu Nov 30 11:47:05 2006
@@ -54,9 +54,7 @@
     {
         int slashx = _path.lastIndexOf('/');
 
-        // TODO: Incorrect for file in root folder
-
-        return _path.substring(0, slashx);
+        return (slashx < 0) ? "" : _path.substring(0, slashx);
     }
 
     public final Resource forFile(String relativePath)
@@ -90,7 +88,8 @@
             // name of a folder, since a Resource should be a file within
             // a folder.
 
-            builder.append("/");
+            if (builder.length() > 0) builder.append("/");
+
             builder.append(term);
         }
 

Modified: tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/util/ClasspathResourceTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/util/ClasspathResourceTest.java?view=diff&rev=481048&r1=481047&r2=481048
==============================================================================
--- tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/util/ClasspathResourceTest.java
(original)
+++ tapestry/tapestry5/tapestry-ioc/trunk/src/test/java/org/apache/tapestry/ioc/internal/util/ClasspathResourceTest.java
Thu Nov 30 11:47:05 2006
@@ -27,6 +27,8 @@
 
 public class ClasspathResourceTest extends Assert
 {
+    private static final String RESOURCE_TXT_CONTENT = "content from resource.txt";
+
     private static final String FOLDER = "org/apache/tapestry/ioc/internal/util";
 
     private static final String PATH = FOLDER + "/resource.txt";
@@ -36,7 +38,31 @@
     {
         Resource r = new ClasspathResource(PATH);
 
-        assertEquals(content(r), "content from resource.txt");
+        assertEquals(content(r), RESOURCE_TXT_CONTENT);
+    }
+
+    @Test
+    public void relative_to_root_resource() throws Exception
+    {
+        Resource r = new ClasspathResource("").forFile(PATH);
+
+        assertEquals(content(r), RESOURCE_TXT_CONTENT);
+    }
+
+    @Test
+    public void relative_to_root_resource_using_leading_slash() throws Exception
+    {
+        Resource r = new ClasspathResource("/").forFile(PATH);
+
+        assertEquals(content(r), RESOURCE_TXT_CONTENT);
+    }
+
+    @Test
+    public void leading_slash_on_path_relative_to_root_doesnt_matter() throws Exception
+    {
+        Resource r = new ClasspathResource("/").forFile("/" + PATH);
+
+        assertEquals(content(r), RESOURCE_TXT_CONTENT);
     }
 
     @Test



Mime
View raw message