Add email notifications.
[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 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";
34         
35         final static String BUNDLE_NAME = "cfb";
36         
37         static ConcurrentHashMap<Locale, CfbBundle> m_bundleMap = new ConcurrentHashMap<Locale, CfbBundle>();
38         
39         ResourceBundle m_bundle;
40         
41         public static CfbBundle getInst(Locale locale) {
42                 CfbBundle result = m_bundleMap.get(locale);
43                 if (null == result) {
44                         synchronized(CfbBundle.class) {
45                                 result = m_bundleMap.get(locale);
46                                 if (null == result) {
47                                         result = new CfbBundle(locale); 
48                                 }
49                                 m_bundleMap.put(locale, result);
50                         }
51                 }
52                 return result;
53         }
54         
55         private CfbBundle(Locale locale) {
56                 m_bundle = QDBundleFactory.getInst().getBundle(BUNDLE_NAME, locale); 
57         }
58         
59         public String get(String key, Object... arguments) {
60                 try {
61                         if (null != m_bundle) {
62                                 String pattern = m_bundle.getString(key);
63                                 return MessageFormat.format(pattern, arguments);
64                         }
65                 }
66                 catch (MissingResourceException exc) {
67                         // Make it clear that something has gone wrong.
68                         exc.printStackTrace();  
69                         // Fall through to the fallback behaviour below
70                 }
71                 
72                 StringBuilder sb = new StringBuilder("[" + key + "]");
73                 for (Object obj : arguments) {
74                         sb.append("[" + obj + "]");
75                 }
76                 return sb.toString();
77         }
78 }