NO_ARGS
private static final Object[] NO_ARGS
bundleNames
private String[] bundleNames
bundles
private HashMap bundles
defaultBundleName
private String defaultBundleName
defaultCountry
private String defaultCountry
defaultLanguage
private String defaultLanguage
defaultLocale
private Locale defaultLocale
devMode
private boolean devMode
cacheBundle
private ResourceBundle cacheBundle(String bundleName,
Locale locale)
throws MissingResourceException
Caches the named bundle for fast lookups. This operation is
relatively expesive in terms of memory use, but is optimized
for run-time speed in the usual case.
findBundleByLocale
private ResourceBundle findBundleByLocale(String bundleName,
Locale locale,
Map bundlesByLocale)
Retrieves the bundle most closely matching first against the
supplied inputs, then against the defaults.
Use case: some clients send a HTTP Accept-Language header
with a value of only the language to use
(i.e. "Accept-Language: en"), and neglect to include a country.
When there is no bundle for the requested language, this method
can be called to try the default country (checking internally
to assure the requested criteria matches the default to avoid
disconnects between language and country).
Since we're really just guessing at possible bundles to use,
we don't ever throw
MissingResourceException
.
format
public String format(String bundleName,
Locale locale,
String key,
Object arg1)
- format in interface I18N
format
public String format(String bundleName,
Locale locale,
String key,
Object arg1,
Object arg2)
- format in interface I18N
format
public String format(String bundleName,
Locale locale,
String key,
Object[] args)
Looks up the value for key
in the
ResourceBundle
referenced by
bundleName
, then formats that value for the
specified Locale
using args
.
- format in interface I18N
- Localized, formatted text identified by
key
.
format
public String format(String key,
Object arg1)
- format in interface I18N
format
public String format(String key,
Object arg1,
Object arg2)
- format in interface I18N
getBundle
public ResourceBundle getBundle()
- getBundle in interface I18N
getBundle
public ResourceBundle getBundle(String bundleName)
- getBundle in interface I18N
getBundle
public ResourceBundle getBundle(String bundleName,
Locale locale)
This method returns a ResourceBundle for the given bundle name
and the given Locale.
- getBundle in interface I18N
bundleName
- Name of bundle (or null
for the
default bundle).locale
- The locale (or null
for the locale
indicated by the default language and country).
- A localized ResourceBundle.
getBundle
public ResourceBundle getBundle(String bundleName,
String languageHeader)
This method returns a ResourceBundle given the bundle name and
the Locale information supplied in the HTTP "Accept-Language"
header.
- getBundle in interface I18N
bundleName
- Name of bundle.languageHeader
- A String with the language header.
- A localized ResourceBundle.
getBundleIgnoreException
private ResourceBundle getBundleIgnoreException(String bundleName,
Locale locale)
Retrieves the bundle using the
ResourceBundle.getBundle(String, Locale)
method,
returning null
instead of throwing
MissingResourceException
.
getLocale
public Locale getLocale(String header)
- getLocale in interface I18N
getString
public String getString(String key)
- getString in interface I18N
getString
public String getString(String key,
Locale locale)
- getString in interface I18N
getString
public String getString(String bundleName,
Locale locale,
String key)
- getString in interface I18N
getStringOrNull
protected final String getStringOrNull(ResourceBundle rb,
String key)
Gets localized text from a bundle if it's there. Otherwise,
returns null
(ignoring a possible
MissingResourceException
).
initialize
public void initialize()
throws InitializationException
Called the first time the Service is used.
initializeBundleNames
protected void initializeBundleNames()