Improve XML parsing to handle attributes as well.
[cfb.git] / prod / net / jaekl / cfb / CfbBundle.java
1 package net.jaekl.cfb;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.util.Locale;
6 import java.util.MissingResourceException;
7 import java.util.ResourceBundle;
8 import java.util.concurrent.ConcurrentHashMap;
9
10 import net.jaekl.qd.QDBundleFactory;
11
12 public class CfbBundle {
13         public static final String CANNOT_CONNECT = "cannot.connect.to.db";
14         public static final String CANNOT_EXEC = "cannot.exec";
15         public static final String STDERR_WAS = "stderr.was";
16         public static final String STDOUT_WAS = "stdout.was";
17         
18         final static String BUNDLE_NAME = "cfb";
19         
20         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
21         
22         ResourceBundle m_bundle;
23         
24         public static CfbBundle getInst(Locale locale) {
25                 CfbBundle result = m_bundleMap.get(locale);
26                 if (null == result) {
27                         synchronized(CfbBundle.class) {
28                                 result = m_bundleMap.get(locale);
29                                 if (null == result) {
30                                         result = new CfbBundle(locale); 
31                                 }
32                                 m_bundleMap.put(locale, result);
33                         }
34                 }
35                 return result;
36         }
37         
38         private CfbBundle(Locale locale) {
39                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
40         }
41         
42         public String get(String key) {
43                 try {
44                         if (null != m_bundle) {
45                                 return m_bundle.getString(key);
46                         }
47                 }
48                 catch (MissingResourceException exc) {
49                         // Make it clear that something has gone wrong.
50                         exc.printStackTrace();  
51                         // Fall through to the fallback behaviour below
52                 }
53                 return "[" + key + "]";
54         }
55 }