You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/04/29 22:15:37 UTC

svn commit: r652084 - /velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java

Author: nbubna
Date: Tue Apr 29 13:15:37 2008
New Revision: 652084

URL: http://svn.apache.org/viewvc?rev=652084&view=rev
Log:
add convenience get() methods that take objects and convert them to strings

Modified:
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java?rev=652084&r1=652083&r2=652084&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java Tue Apr 29 13:15:37 2008
@@ -120,6 +120,15 @@
     }
 
 
+    /**
+     * Accepts objects and uses their string value as the key.
+     */
+    public Key get(Object k)
+    {
+        String key = k == null ? null : String.valueOf(k);
+        return get(key);
+    }
+
     public Key get(String key)
     {
         return new Key(key, this.bundles, getLocale(), null);
@@ -161,12 +170,13 @@
      * the specified basename and locale.  If no such resource can be
      * found, no errors are thrown and {@code null} is returned.
      */
-    public Object get(String key, String baseName, Locale locale)
+    public Object get(Object k, String baseName, Locale locale)
     {
-        if (baseName == null || key == null)
+        if (baseName == null || k == null)
         {
             return null;
         }
+        String key = k == null ? null : String.valueOf(k);
         if (locale == null)
         {
             locale = getLocale();
@@ -193,8 +203,9 @@
      * If no resource is found, no exception will be thrown and {@code null}
      * will be returned.
      */
-    public Object get(String key, String[] bundles, Locale locale)
+    public Object get(Object k, String[] bundles, Locale locale)
     {
+        String key = k == null ? null : String.valueOf(k);
         for (int i=0; i < bundles.length; i++)
         {
             Object resource = get(key, bundles[i], locale);
@@ -252,6 +263,11 @@
 
         // ----- mutators (these return an altered duplicate) ---
 
+        public Key get(Object k)
+        {
+            return get(String.valueOf(k));
+        }
+
         public Key get(String key)
         {
             String newKey;