Add unit tests. Make DbStore handle cases where the bug type or category
[cfb.git] / prod / net / jaekl / cfb / CfbBundle.java
1 package net.jaekl.cfb;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.text.MessageFormat;
6 import java.util.Locale;
7 import java.util.MissingResourceException;
8 import java.util.ResourceBundle;
9 import java.util.concurrent.ConcurrentHashMap;
10
11 import net.jaekl.qd.QDBundleFactory;
12
13 public class CfbBundle {
14         public static final String ANALYSIS_FAILED = "analysis.failed";
15         public static final String ANALYZED_AT = "analyzed.at";
16         public static final String BUG_CATEGORY_UNKNOWN = "bug.category.unknown";
17         public static final String BUG_TYPE_UNKNOWN = "bug.type.unknown";
18         public static final String CANNOT_CONNECT = "cannot.connect.to.db";
19         public static final String CANNOT_EXEC = "cannot.exec";
20         public static final String CANNOT_SEND_MAIL = "cannot.send.mail";
21         public static final String CFB = "cfb";
22         public static final String CFB_MAIL_SUBJECT = "cfb.mail.subject";
23         public static final String CFB_REPORT = "cfb.report";
24         public static final String COMPARING_RUNS = "comparing.runs";
25         public static final String COMPARING_VERSIONS = "comparing.versions";
26         public static final String FIXED_BUGS = "fixed.bugs";
27         public static final String NEW_BUGS = "new.bugs";
28         public static final String NEW_VERSION = "new.version";
29         public static final String NUM_BUGS = "num.bugs";
30         public static final String NUM_BUGS_OLD = "num.bugs.old";
31         public static final String OLD_BUGS = "old.bugs";
32         public static final String OLD_VERSION = "old.version";
33         public static final String STDERR_WAS = "stderr.was";
34         public static final String STDOUT_WAS = "stdout.was";
35         public static final String VERSION_NUM = "version.num";
36         
37         final static String BUNDLE_NAME = "cfb";
38         
39         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
40         
41         ResourceBundle m_bundle;
42         
43         public static CfbBundle getInst(Locale locale) {
44                 CfbBundle result = m_bundleMap.get(locale);
45                 if (null == result) {
46                         synchronized(CfbBundle.class) {
47                                 result = m_bundleMap.get(locale);
48                                 if (null == result) {
49                                         result = new CfbBundle(locale); 
50                                 }
51                                 m_bundleMap.put(locale, result);
52                         }
53                 }
54                 return result;
55         }
56         
57         private CfbBundle(Locale locale) {
58                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
59         }
60         
61         public String get(String key, Object... arguments) {
62                 try {
63                         if (null != m_bundle) {
64                                 String pattern = m_bundle.getString(key);
65                                 return MessageFormat.format(pattern, arguments);
66                         }
67                 }
68                 catch (MissingResourceException exc) {
69                         // Make it clear that something has gone wrong.
70                         exc.printStackTrace();  
71                         // Fall through to the fallback behaviour below
72                 }
73                 
74                 StringBuilder sb = new StringBuilder("[" + key + "]");
75                 for (Object obj : arguments) {
76                         sb.append("[" + obj + "]");
77                 }
78                 return sb.toString();
79         }
80 }