View Javadoc

1   
2   package org.paneris.bibliomania.util;
3   
4   import java.text.NumberFormat;
5   import java.util.Locale;
6   
7   /**
8    * BibliomaniaUtil is a place where useful Static methods can be put.
9    */
10  
11  public class BibliomaniaUtil {
12  
13    public static Locale makeLocale(String localeString) {
14      Locale locale = null;
15      if (localeString == null) {
16        locale = Locale.US;
17      } else {
18        if (localeString.equals("en-gb")) return locale = Locale.UK;
19        if (localeString.equals("en-us")) return locale = Locale.US;
20        //String language = "";
21        String country = "";
22        int i = localeString.indexOf("-");
23        //if (i == -1) { 
24        //  language = localeString; 
25        //} else {
26        //  language = localeString.substring(0,i);
27        //}
28        if (localeString.length() > i) country = localeString.substring(i+1, localeString.length());
29        if (country.equals("at") || country.equals("de") || country.equals("lu") ||
30            country.equals("ie") || country.equals("es") || country.equals("fl") ||
31            country.equals("be") || country.equals("fr") || country.equals("it") ||
32            country.equals("nl") || country.equals("pt")
33            ) {
34              locale = new Locale("en", "IE", "EURO");
35        }
36      }
37      System.err.println("made locale: " + locale);
38      if (locale == null) locale = Locale.US;
39      return locale;
40    }
41     
42    public static String euroFormat(Locale locale, double value) {
43      String formatted = NumberFormat.getCurrencyInstance(locale).format(value);
44      StringBuffer out = new StringBuffer();
45      for (int i=0; i<formatted.length(); i++) {
46        char c = formatted.charAt(i);
47        if (c == '\u20AC') {
48          out.append("&euro;");
49        } else { 
50          out.append(c);
51        }
52      }
53      return out.toString();
54    }
55  
56  }