1 package com
.googlecode
.lanterna
.bundle
;
3 import java
.security
.PrivilegedAction
;
4 import java
.text
.MessageFormat
;
5 import java
.util
.HashMap
;
6 import java
.util
.Locale
;
8 import java
.util
.ResourceBundle
;
11 * This class permits to deal easily with bundles.
14 public abstract class BundleLocator
{
16 private final String bundleName
;
17 private static final ClassLoader loader
= BundleLocator
.class.getClassLoader();
21 * @param bundleName the name of the bundle.
23 protected BundleLocator(final String bundleName
) {
24 this.bundleName
= bundleName
;
28 * Method that centralizes the way to get the value associated to a bundle key.
29 * @param locale the locale.
30 * @param key the key searched for.
31 * @param parameters the parameters to apply to the value associated to the key.
32 * @return the formatted value associated to the given key. Empty string if no value exists for
35 protected String
getBundleKeyValue(Locale locale
, String key
, Object
... parameters
) {
38 value
= getBundle(locale
).getString(key
);
39 } catch (Exception ignore
) {
41 return value
!= null ? MessageFormat
.format(value
, parameters
) : null;
45 * Gets the right bundle.<br/>
46 * A cache is handled as well as the concurrent accesses.
47 * @param locale the locale.
48 * @return the instance of the bundle.
50 private ResourceBundle
getBundle(Locale locale
) {
51 return ResourceBundle
.getBundle(bundleName
, locale
, loader
);