click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r824949 - /incubator/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java
Date Tue, 13 Oct 2009 22:12:35 GMT
Author: sabob
Date: Tue Oct 13 22:12:35 2009
New Revision: 824949

URL: http://svn.apache.org/viewvc?rev=824949&view=rev
Log:
updated table exporter

Modified:
    incubator/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java?rev=824949&r1=824948&r2=824949&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java
Tue Oct 13 22:12:35 2009
@@ -18,6 +18,10 @@
  */
 package org.apache.click.examples.util;
 
+import java.util.Currency;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
 import org.apache.click.Context;
 
 /**
@@ -27,6 +31,8 @@
  */
 public class ExampleUtils {
 
+    private static final Map<Currency, String> CURRENCY_SYMBOLS = new HashMap<Currency,
String>();
+
     @SuppressWarnings("unchecked")
     public static Object getSessionObject(Class aClass) {
         if (aClass == null) {
@@ -56,6 +62,38 @@
         }
     }
 
+    public static String getCurrencySymbol(Currency currency) {
+        if(currency == null) {
+            return "";
+        }
+
+        String symbol = CURRENCY_SYMBOLS.get(currency);
+        if(symbol != null) {
+            return symbol;
+        }
+
+        String currencyCode = currency.getCurrencyCode();
+
+        Locale locale = Locale.getDefault();
+        symbol = currency.getSymbol(locale);
+        if(!symbol.equals(currencyCode)) {
+            CURRENCY_SYMBOLS.put(currency, symbol);
+            return symbol;
+        }
+
+        Locale[] allLocales = Locale.getAvailableLocales();
+        for (int i = 0; i < allLocales.length; i++) {
+            symbol = currency.getSymbol(allLocales[i]);
+            if(!symbol.equals(currencyCode)) {
+                CURRENCY_SYMBOLS.put(currency, symbol);
+                return symbol;
+            }
+        }
+
+        CURRENCY_SYMBOLS.put(currency, currencyCode);
+        return currencyCode;
+    }
+
     private static Context getContext() {
         return Context.getThreadLocalContext();
     }



Mime
View raw message