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 2011/03/01 20:28:55 UTC

svn commit: r1075987 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java

Author: hlship
Date: Tue Mar  1 19:28:54 2011
New Revision: 1075987

URL: http://svn.apache.org/viewvc?rev=1075987&view=rev
Log:
Add new method for getting the file extension for a file

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java?rev=1075987&r1=1075986&r2=1075987&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/TapestryInternalUtils.java Tue Mar  1 19:28:54 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -589,4 +589,12 @@ public class TapestryInternalUtils
             }
         };
     }
+
+    /** @since 5.3.0 */
+    public static String toFileSuffix(String fileName)
+    {
+        int dotx = fileName.lastIndexOf('.');
+
+        return dotx < 0 ? "" : fileName.substring(dotx + 1);
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java?rev=1075987&r1=1075986&r2=1075987&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/TapestryInternalUtilsTest.java Tue Mar  1 19:28:54 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2011 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
@@ -57,7 +57,6 @@ public class TapestryInternalUtilsTest e
         beanModelSource = null;
     }
 
-
     @Test(dataProvider = "to_user_presentable_data")
     public void to_user_presentable(String input, String expected)
     {
@@ -67,8 +66,12 @@ public class TapestryInternalUtilsTest e
     @DataProvider
     public Object[][] to_user_presentable_data()
     {
-        return new Object[][] { { "hello", "Hello" }, { "userId", "User Id" }, { "useHTML", "Use HTML" },
-                { "underscored_name", "Underscored Name" }, };
+        return new Object[][]
+        {
+        { "hello", "Hello" },
+        { "userId", "User Id" },
+        { "useHTML", "Use HTML" },
+        { "underscored_name", "Underscored Name" }, };
     }
 
     @Test
@@ -265,9 +268,9 @@ public class TapestryInternalUtilsTest e
     {
         assertEquals(TapestryInternalUtils.extractIdFromPropertyExpression("simpleName"), "simpleName");
         assertEquals(TapestryInternalUtils.extractIdFromPropertyExpression("complex.name().withStuff"),
-                     "complexnamewithStuff");
+                "complexnamewithStuff");
         assertEquals(TapestryInternalUtils.extractIdFromPropertyExpression("number99.withABullet"),
-                     "number99withABullet");
+                "number99withABullet");
     }
 
     @Test
@@ -377,16 +380,17 @@ public class TapestryInternalUtilsTest e
     public Object[][] split_at_commas_data()
     {
         return new Object[][]
-                {
-                        { "foo", new String[] { "foo" } },
-                        { "foo, bar", new String[] { "foo", "bar" } },
-                        { "  foo, \nbar\t\t", new String[] { "foo", "bar" } },
-                        { "", new String[0] },
-                        { null, new String[0] }
-                };
+        {
+        { "foo", new String[]
+        { "foo" } },
+        { "foo, bar", new String[]
+        { "foo", "bar" } },
+        { "  foo, \nbar\t\t", new String[]
+        { "foo", "bar" } },
+        { "", new String[0] },
+        { null, new String[0] } };
     }
 
-
     @Test(dataProvider = "split_at_commas_data")
     public void split_at_commas(String input, String[] output)
     {
@@ -397,11 +401,11 @@ public class TapestryInternalUtilsTest e
     @DataProvider
     public Object[][] to_base64_data()
     {
-        return new Object[][] {
-                { 0L, "AA" },
-                { 1L, "AQ" },
-                { 0xab54a98ceb1f0ad2L, "q1SpjOsfCtI" }
-        };
+        return new Object[][]
+        {
+        { 0L, "AA" },
+        { 1L, "AQ" },
+        { 0xab54a98ceb1f0ad2L, "q1SpjOsfCtI" } };
     }
 
     @Test
@@ -439,41 +443,46 @@ public class TapestryInternalUtilsTest e
 
         verify();
     }
-    
-    
+
     @Test
     public void to_internal_property_conduit_no_wrapper_needed()
     {
-    	InternalPropertyConduit conduit2 = newMock(InternalPropertyConduit.class);
-    	
-    	assertSame(TapestryInternalUtils.toInternalPropertyConduit(conduit2), conduit2);
+        InternalPropertyConduit conduit2 = newMock(InternalPropertyConduit.class);
+
+        assertSame(TapestryInternalUtils.toInternalPropertyConduit(conduit2), conduit2);
     }
-    
+
     @Test
     public void to_internal_property_conduit_wrapper()
     {
-    	PropertyConduit conduit = mockPropertyConduit();
-    	
-    	Integer result = 123;
-    	Width width = newMock(Width.class);
-    	
-    	
-    	expect(conduit.get("")).andReturn(result);
-    	expect(conduit.getAnnotation(Width.class)).andReturn(width);
-    	expect(conduit.getPropertyType()).andReturn(Integer.class);
-    	conduit.set("", 345);
-    	
-    	replay();
-    	
-    	InternalPropertyConduit conduit2 = TapestryInternalUtils.toInternalPropertyConduit(conduit);
-    	
-    	assertNull(conduit2.getPropertyName());
-    	
-    	assertSame(conduit2.get(""), result);
-    	assertSame(conduit2.getAnnotation(Width.class), width);
-    	assertSame(conduit2.getPropertyType(), Integer.class);
-    	conduit2.set("", 345);
-    	
-    	verify();
+        PropertyConduit conduit = mockPropertyConduit();
+
+        Integer result = 123;
+        Width width = newMock(Width.class);
+
+        expect(conduit.get("")).andReturn(result);
+        expect(conduit.getAnnotation(Width.class)).andReturn(width);
+        expect(conduit.getPropertyType()).andReturn(Integer.class);
+        conduit.set("", 345);
+
+        replay();
+
+        InternalPropertyConduit conduit2 = TapestryInternalUtils.toInternalPropertyConduit(conduit);
+
+        assertNull(conduit2.getPropertyName());
+
+        assertSame(conduit2.get(""), result);
+        assertSame(conduit2.getAnnotation(Width.class), width);
+        assertSame(conduit2.getPropertyType(), Integer.class);
+        conduit2.set("", 345);
+
+        verify();
+    }
+
+    @Test
+    public void toFileSuffix_tests()
+    {
+        assertEquals(TapestryInternalUtils.toFileSuffix("foo.tar.gz"), "gz");
+        assertEquals(TapestryInternalUtils.toFileSuffix("just-a-file"), "");
     }
 }