hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r231303 - in /jakarta/hivemind/trunk/framework/src: java/org/apache/hivemind/util/ test/org/apache/hivemind/util/
Date Wed, 10 Aug 2005 19:57:04 GMT
Author: ahuegen
Date: Wed Aug 10 12:56:48 2005
New Revision: 231303

URL: http://svn.apache.org/viewcvs?rev=231303&view=rev
Log:
Fix for HIVEMIND-145

Added:
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/empty_fr
Modified:
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedContextResourceFinder.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedFileResourceFinder.java
    jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedResourceFinder.java
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestClasspathResource.java
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestFileResource.java
    jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestLocalizedContextResourceFinder.java

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedContextResourceFinder.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedContextResourceFinder.java?rev=231303&r1=231302&r2=231303&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedContextResourceFinder.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedContextResourceFinder.java
Wed Aug 10 12:56:48 2005
@@ -49,8 +49,18 @@
     public LocalizedResource resolve(String contextPath, Locale locale)
     {
         int dotx = contextPath.lastIndexOf('.');
-        String basePath = contextPath.substring(0, dotx);
-        String suffix = contextPath.substring(dotx);
+        String basePath;
+        String suffix;
+        if (dotx >= 0) {
+        	basePath = contextPath.substring(0, dotx);
+        	suffix = contextPath.substring(dotx);
+        }
+        else
+        {
+        	// Resource without extension
+        	basePath = contextPath;
+        	suffix = "";
+        }
 
         LocalizedNameGenerator generator = new LocalizedNameGenerator(basePath, locale, suffix);
 

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedFileResourceFinder.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedFileResourceFinder.java?rev=231303&r1=231302&r2=231303&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedFileResourceFinder.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedFileResourceFinder.java
Wed Aug 10 12:56:48 2005
@@ -29,8 +29,20 @@
     public String findLocalizedPath(String path, Locale locale)
     {
         int dotx = path.lastIndexOf('.');
-        LocalizedNameGenerator g =
-            new LocalizedNameGenerator(path.substring(0, dotx), locale, path.substring(dotx));
+        String basePath;
+        String suffix;
+        if (dotx >= 0)
+        {
+            basePath = path.substring(0, dotx);
+            suffix = path.substring(dotx);
+        }
+        else
+        {
+            // Resource without extension
+            basePath = path;
+            suffix = "";
+        }
+        LocalizedNameGenerator g = new LocalizedNameGenerator(basePath, locale, suffix);
 
         while (g.more())
         {

Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedResourceFinder.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedResourceFinder.java?rev=231303&r1=231302&r2=231303&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedResourceFinder.java
(original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/util/LocalizedResourceFinder.java
Wed Aug 10 12:56:48 2005
@@ -49,8 +49,18 @@
     public LocalizedResource resolve(String resourcePath, Locale locale)
     {
         int dotx = resourcePath.lastIndexOf('.');
-        String basePath = resourcePath.substring(0, dotx);
-        String suffix = resourcePath.substring(dotx);
+        String basePath;
+        String suffix;
+        if (dotx >= 0) {
+        	basePath = resourcePath.substring(0, dotx);
+        	suffix = resourcePath.substring(dotx);
+        }
+        else
+        {
+        	// Resource without extension
+        	basePath = resourcePath;
+        	suffix = "";
+        }
 
         LocalizedNameGenerator generator = new LocalizedNameGenerator(basePath, locale, suffix);
 

Modified: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestClasspathResource.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestClasspathResource.java?rev=231303&r1=231302&r2=231303&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestClasspathResource.java
(original)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestClasspathResource.java
Wed Aug 10 12:56:48 2005
@@ -131,4 +131,13 @@
 
         assertEquals(expected, actual);
     }
+    
+    public void testLocalizeExtensionless()
+    {
+        Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/empty");
+        Resource expected = new ClasspathResource(_resolver, "/org/apache/hivemind/util/empty_fr");
+        Resource actual = l1.getLocalization(Locale.FRENCH);
+
+        assertEquals(expected, actual);
+    }
 }

Modified: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestFileResource.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestFileResource.java?rev=231303&r1=231302&r2=231303&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestFileResource.java
(original)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestFileResource.java
Wed Aug 10 12:56:48 2005
@@ -129,4 +129,17 @@
 
         assertEquals(path, r.toString());
     }
+    
+    public void testExtensionLess()
+    {
+    	String path = getFrameworkPath(DIR);
+    	// Remove the ./ at the beginning to remove any dot from the path
+    	if (path.startsWith("./"))
+    		path = path.substring(2);
+    	
+        Resource r = new FileResource(path);
+        Resource localized = r.getLocalization(Locale.CHINA);
+
+        assertSame(r, localized);
+    }
 }

Modified: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestLocalizedContextResourceFinder.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestLocalizedContextResourceFinder.java?rev=231303&r1=231302&r2=231303&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestLocalizedContextResourceFinder.java
(original)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/TestLocalizedContextResourceFinder.java
Wed Aug 10 12:56:48 2005
@@ -94,4 +94,24 @@
 
         verifyControls();
     }
+
+    public void testExtensionlessResource() throws Exception
+    {
+        MockControl control = newControl(ServletContext.class);
+        ServletContext sc = (ServletContext) control.getMock();
+
+        sc.getResource("/foo/bar/baz");
+        control.setReturnValue(new URL("http://foo.com"));
+
+        replayControls();
+
+        LocalizedContextResourceFinder f = new LocalizedContextResourceFinder(sc);
+
+        LocalizedResource lr = f.resolve("/foo/bar/baz", null);
+
+        assertEquals("/foo/bar/baz", lr.getResourcePath());
+        assertNull(lr.getResourceLocale());
+
+        verifyControls();
+    }
 }

Added: jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/empty_fr
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/empty_fr?rev=231303&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/empty_fr (added)
+++ jakarta/hivemind/trunk/framework/src/test/org/apache/hivemind/util/empty_fr Wed Aug 10
12:56:48 2005
@@ -0,0 +1 @@
+Test resource for testExtensionLess
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message