Add ability to output HTML report of differences found between two versions.
[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 CANNOT_CONNECT = "cannot.connect.to.db";
17         public static final String CANNOT_EXEC = "cannot.exec";
18         public static final String CFB = "cfb";
19         public static final String CFB_REPORT = "cfb.report";
20         public static final String COMPARING_RUNS = "comparing.runs";
21         public static final String COMPARING_VERSIONS = "comparing.versions";
22         public static final String FIXED_BUGS = "fixed.bugs";
23         public static final String NEW_BUGS = "new.bugs";
24         public static final String NEW_VERSION = "new.version";
25         public static final String NUM_BUGS = "num.bugs";
26         public static final String NUM_BUGS_OLD = "num.bugs.old";
27         public static final String OLD_BUGS = "old.bugs";
28         public static final String OLD_VERSION = "old.version";
29         public static final String STDERR_WAS = "stderr.was";
30         public static final String STDOUT_WAS = "stdout.was";
31         public static final String VERSION_NUM = "version.num";
32         
33         final static String BUNDLE_NAME = "cfb";
34         
35         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
36         
37         ResourceBundle m_bundle;
38         
39         public static CfbBundle getInst(Locale locale) {
40                 CfbBundle result = m_bundleMap.get(locale);
41                 if (null == result) {
42                         synchronized(CfbBundle.class) {
43                                 result = m_bundleMap.get(locale);
44                                 if (null == result) {
45                                         result = new CfbBundle(locale); 
46                                 }
47                                 m_bundleMap.put(locale, result);
48                         }
49                 }
50                 return result;
51         }
52         
53         private CfbBundle(Locale locale) {
54                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
55         }
56         
57         public String get(String key, Object... arguments) {
58                 try {
59                         if (null != m_bundle) {
60                                 String pattern = m_bundle.getString(key);
61                                 return MessageFormat.format(pattern, arguments);
62                         }
63                 }
64                 catch (MissingResourceException exc) {
65                         // Make it clear that something has gone wrong.
66                         exc.printStackTrace();  
67                         // Fall through to the fallback behaviour below
68                 }
69                 
70                 StringBuilder sb = new StringBuilder("[" + key + "]");
71                 for (Object obj : arguments) {
72                         sb.append("[" + obj + "]");
73                 }
74                 return sb.toString();
75         }
76 }