velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r591902 - in /velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools: ConversionUtils.java generic/ConversionTool.java
Date Mon, 05 Nov 2007 07:40:24 GMT
Author: cbrisson
Date: Sun Nov  4 23:40:23 2007
New Revision: 591902

URL: http://svn.apache.org/viewvc?rev=591902&view=rev
Log:
move the toLocale() method to ConversionUtils

Modified:
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ConversionUtils.java
    velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ConversionUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ConversionUtils.java?rev=591902&r1=591901&r2=591902&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ConversionUtils.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/ConversionUtils.java
Sun Nov  4 23:40:23 2007
@@ -541,4 +541,32 @@
         return cal;
     }
 
+    /**
+     * Converts a string to  a {@link Locale}
+     *
+     * @param value - the string to parse
+     * @return the {@link Locale} or <code>null</code> if the
+     *         parsing fails
+     */
+    public static Locale toLocale(String value) {
+        if (value.indexOf('_') < 0)
+        {
+            return new Locale(value);
+        }
+
+        String[] params = value.split("_");
+        if (params.length == 2)
+        {
+            return new Locale(params[0], params[1]);
+        }
+        else if (params.length == 3)
+        {
+            return new Locale(params[0], params[1], params[2]);
+        }
+        else
+        {
+            // there's only 3 possible params, so this must be invalid
+            return null;
+        }
+    }
 }

Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java?rev=591902&r1=591901&r2=591902&view=diff
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
(original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/generic/ConversionTool.java
Sun Nov  4 23:40:23 2007
@@ -660,25 +660,7 @@
      */
     protected Locale parseLocale(String value)
     {
-        if (value.indexOf('_') < 0)
-        {
-            return new Locale(value);
-        }
-
-        String[] params = value.split("_");
-        if (params.length == 2)
-        {
-            return new Locale(params[0], params[1]);
-        }
-        else if (params.length == 3)
-        {
-            return new Locale(params[0], params[1], params[2]);
-        }
-        else
-        {
-            // there's only 3 possible params, so this must be invalid
-            return null;
-        }
+        return ConversionUtils.toLocale(value);
     }
 
 



Mime
View raw message