3 // Copyright (C) 2015 Christian Jaekl
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;
11 import net.jaekl.qd.QDBundleFactory;
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 CANNOT_SEND_MAIL = "cannot.send.mail";
19 public static final String CFB = "cfb";
20 public static final String CFB_MAIL_SUBJECT = "cfb.mail.subject";
21 public static final String CFB_REPORT = "cfb.report";
22 public static final String COMPARING_RUNS = "comparing.runs";
23 public static final String COMPARING_VERSIONS = "comparing.versions";
24 public static final String FIXED_BUGS = "fixed.bugs";
25 public static final String NEW_BUGS = "new.bugs";
26 public static final String NEW_VERSION = "new.version";
27 public static final String NUM_BUGS = "num.bugs";
28 public static final String NUM_BUGS_OLD = "num.bugs.old";
29 public static final String OLD_BUGS = "old.bugs";
30 public static final String OLD_VERSION = "old.version";
31 public static final String STDERR_WAS = "stderr.was";
32 public static final String STDOUT_WAS = "stdout.was";
33 public static final String VERSION_NUM = "version.num";
35 final static String BUNDLE_NAME = "cfb";
37 static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
39 ResourceBundle m_bundle;
41 public static CfbBundle getInst(Locale locale) {
42 CfbBundle result = m_bundleMap.get(locale);
44 synchronized(CfbBundle.class) {
45 result = m_bundleMap.get(locale);
47 result = new CfbBundle(locale);
49 m_bundleMap.put(locale, result);
55 private CfbBundle(Locale locale) {
56 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale);
59 public String get(String key, Object... arguments) {
61 if (null != m_bundle) {
62 String pattern = m_bundle.getString(key);
63 return MessageFormat.format(pattern, arguments);
66 catch (MissingResourceException exc) {
67 // Make it clear that something has gone wrong.
68 exc.printStackTrace();
69 // Fall through to the fallback behaviour below
72 StringBuilder sb = new StringBuilder("[" + key + "]");
73 for (Object obj : arguments) {
74 sb.append("[" + obj + "]");