BrightSide Workbench Full Report + Source Code
Currencies.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.zkoss.locale;
19 
20 import java.util.ArrayList;
21 import java.util.Currency;
22 import java.util.List;
23 import java.util.Locale;
24 import java.util.MissingResourceException;
25 import org.turro.string.Strings;
26 import org.turro.elephant.context.Application;
27 
32 public class Currencies {
33 
34  public static List<Currency> getAvailable() {
35  List<Currency> list = new ArrayList<Currency>();
36  for(Locale l : Locale.getAvailableLocales()) {
37  if(hasValidCountry(l)) {
38  Currency c = Currency.getInstance(l);
39  if(!list.contains(c)) {
40  list.add(c);
41  }
42  }
43  }
44  return list;
45  }
46 
47  public static Currency getDefault() {
48  Currency c = getDefault(Application.getUsedLocale());
49  return c == null ? Currency.getInstance("EUR") : c;
50  }
51 
52  public static Currency getDefault(Locale l) {
53  if(hasValidCountry(l)) {
54  return Currency.getInstance(l);
55  }
56  return null;
57  }
58 
59  public static boolean hasValidCountry(Locale l) {
60  try {
61  return !Strings.isBlank(l.getISO3Country());
62  } catch(MissingResourceException mre) {
63  return false;
64  }
65  }
66 
67  private Currencies() {
68  }
69 
70 }
static List< Currency > getAvailable()
Definition: Currencies.java:34
static Currency getDefault(Locale l)
Definition: Currencies.java:52
static boolean hasValidCountry(Locale l)
Definition: Currencies.java:59