]> jaekl.net Git - frank.git/blob - prod/net/jaekl/frank/FrankBundle.java
f0889ba1e519b342459105cd6bf8b37511fc95cd
[frank.git] / prod / net / jaekl / frank / FrankBundle.java
1 package net.jaekl.frank;
2
3 import java.util.Locale;
4 import java.util.MissingResourceException;
5 import java.util.ResourceBundle;
6 import java.util.concurrent.ConcurrentHashMap;
7
8 import net.jaekl.qd.QDBundleFactory;
9
10 public class FrankBundle {
11         public static final String DATA_COLLECTED = "data.collected";
12         public static final String DESTINATION = "destination";
13         public static final String ERROR_PAGE = "error.page";
14         public static final String ETA = "eta";
15         public static final String FRANK = "frank";
16         public static final String GPS_OFF = "gps.off";
17         public static final String GPS_READ = "gps.read";
18         public static final String MINUTES = "m";       // suffix (abbreviated) for minutes
19         public static final String REMAIN = "remain";
20         public static final String ROUTE = "route";
21         public static final String SECONDS = "s";
22         public static final String UNEXPECTED_ERROR = "unexpected.error";
23         
24         final static String BUNDLE_NAME = "frank";
25         
26         static ConcurrentHashMap<Locale, FrankBundle> m_bundleMap = new ConcurrentHashMap<Locale, FrankBundle>();
27         
28         ResourceBundle m_bundle;
29         
30         public static FrankBundle getInst(Locale locale) {
31                 FrankBundle result = m_bundleMap.get(locale);
32                 if (null == result) {
33                         synchronized(FrankBundle.class) {
34                                 result = m_bundleMap.get(locale);
35                                 if (null == result) {
36                                         result = new FrankBundle(locale); 
37                                 }
38                                 m_bundleMap.put(locale, result);
39                         }
40                 }
41                 return result;
42         }
43         
44         private FrankBundle(Locale locale) {
45                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
46         }
47         
48         public String get(String key) {
49                 try {
50                         if (null != m_bundle) {
51                                 return m_bundle.getString(key);
52                         }
53                 }
54                 catch (MissingResourceException e) {
55                         // Make it clear that something has gone wrong.
56                         e.printStackTrace();    
57                         // Fall through to the fallback behaviour below
58                 }
59                 return "[" + key + "]";
60         }
61 }