Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BibliomaniaUtil |
|
| 11.0;11 |
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 | 0 | public class BibliomaniaUtil { |
12 | ||
13 | public static Locale makeLocale(String localeString) { | |
14 | 0 | Locale locale = null; |
15 | 0 | if (localeString == null) { |
16 | 0 | locale = Locale.US; |
17 | } else { | |
18 | 0 | if (localeString.equals("en-gb")) return locale = Locale.UK; |
19 | 0 | if (localeString.equals("en-us")) return locale = Locale.US; |
20 | //String language = ""; | |
21 | 0 | String country = ""; |
22 | 0 | int i = localeString.indexOf("-"); |
23 | //if (i == -1) { | |
24 | // language = localeString; | |
25 | //} else { | |
26 | // language = localeString.substring(0,i); | |
27 | //} | |
28 | 0 | if (localeString.length() > i) country = localeString.substring(i+1, localeString.length()); |
29 | 0 | 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 | 0 | locale = new Locale("en", "IE", "EURO"); |
35 | } | |
36 | } | |
37 | 0 | System.err.println("made locale: " + locale); |
38 | 0 | if (locale == null) locale = Locale.US; |
39 | 0 | return locale; |
40 | } | |
41 | ||
42 | public static String euroFormat(Locale locale, double value) { | |
43 | 0 | String formatted = NumberFormat.getCurrencyInstance(locale).format(value); |
44 | 0 | StringBuffer out = new StringBuffer(); |
45 | 0 | for (int i=0; i<formatted.length(); i++) { |
46 | 0 | char c = formatted.charAt(i); |
47 | 0 | if (c == '\u20AC') { |
48 | 0 | out.append("€"); |
49 | } else { | |
50 | 0 | out.append(c); |
51 | } | |
52 | } | |
53 | 0 | return out.toString(); |
54 | } | |
55 | ||
56 | } |