|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.plexus.logging.AbstractLogEnabled
org.codehaus.plexus.i18n.DefaultI18N
Field Summary | |
private java.lang.String[] |
bundleNames
|
private java.util.HashMap |
bundles
|
private java.lang.String |
defaultBundleName
|
private java.lang.String |
defaultCountry
|
private java.lang.String |
defaultLanguage
|
private java.util.Locale |
defaultLocale
|
private boolean |
devMode
|
private static java.lang.Object[] |
NO_ARGS
|
Fields inherited from class org.codehaus.plexus.logging.AbstractLogEnabled |
|
Fields inherited from interface org.codehaus.plexus.i18n.I18N |
ACCEPT_LANGUAGE, ROLE |
Constructor Summary | |
DefaultI18N()
|
Method Summary | |
private java.util.ResourceBundle |
cacheBundle(java.lang.String bundleName,
java.util.Locale locale)
Caches the named bundle for fast lookups. |
private java.util.ResourceBundle |
findBundleByLocale(java.lang.String bundleName,
java.util.Locale locale,
java.util.Map bundlesByLocale)
Retrieves the bundle most closely matching first against the supplied inputs, then against the defaults. |
java.lang.String |
format(java.lang.String bundleName,
java.util.Locale locale,
java.lang.String key,
java.lang.Object arg1)
|
java.lang.String |
format(java.lang.String bundleName,
java.util.Locale locale,
java.lang.String key,
java.lang.Object[] args)
Looks up the value for key in the
ResourceBundle referenced by
bundleName , then formats that value for the
specified Locale using args . |
java.lang.String |
format(java.lang.String bundleName,
java.util.Locale locale,
java.lang.String key,
java.lang.Object arg1,
java.lang.Object arg2)
|
java.lang.String |
format(java.lang.String key,
java.lang.Object arg1)
|
java.lang.String |
format(java.lang.String key,
java.lang.Object arg1,
java.lang.Object arg2)
|
java.util.ResourceBundle |
getBundle()
|
java.util.ResourceBundle |
getBundle(java.lang.String bundleName)
|
java.util.ResourceBundle |
getBundle(java.lang.String bundleName,
java.util.Locale locale)
This method returns a ResourceBundle for the given bundle name and the given Locale. |
java.util.ResourceBundle |
getBundle(java.lang.String bundleName,
java.lang.String languageHeader)
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header. |
private java.util.ResourceBundle |
getBundleIgnoreException(java.lang.String bundleName,
java.util.Locale locale)
Retrieves the bundle using the ResourceBundle.getBundle(String, Locale) method,
returning null instead of throwing
MissingResourceException . |
java.lang.String[] |
getBundleNames()
|
java.lang.String |
getDefaultBundleName()
|
java.lang.String |
getDefaultCountry()
|
java.lang.String |
getDefaultLanguage()
|
java.util.Locale |
getLocale(java.lang.String header)
|
java.lang.String |
getString(java.lang.String key)
|
java.lang.String |
getString(java.lang.String key,
java.util.Locale locale)
|
java.lang.String |
getString(java.lang.String bundleName,
java.util.Locale locale,
java.lang.String key)
|
protected java.lang.String |
getStringOrNull(java.util.ResourceBundle rb,
java.lang.String key)
Gets localized text from a bundle if it's there. |
void |
initialize()
Called the first time the Service is used. |
protected void |
initializeBundleNames()
|
Methods inherited from class org.codehaus.plexus.logging.AbstractLogEnabled |
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final java.lang.Object[] NO_ARGS
private java.util.HashMap bundles
private java.lang.String[] bundleNames
private java.lang.String defaultBundleName
private java.util.Locale defaultLocale
private java.lang.String defaultLanguage
private java.lang.String defaultCountry
private boolean devMode
Constructor Detail |
public DefaultI18N()
Method Detail |
public java.lang.String getDefaultLanguage()
getDefaultLanguage
in interface I18N
public java.lang.String getDefaultCountry()
getDefaultCountry
in interface I18N
public java.lang.String getDefaultBundleName()
getDefaultBundleName
in interface I18N
public java.lang.String[] getBundleNames()
getBundleNames
in interface I18N
public java.util.ResourceBundle getBundle()
getBundle
in interface I18N
public java.util.ResourceBundle getBundle(java.lang.String bundleName)
getBundle
in interface I18N
public java.util.ResourceBundle getBundle(java.lang.String bundleName, java.lang.String languageHeader)
getBundle
in interface I18N
bundleName
- Name of bundle.languageHeader
- A String with the language header.
public java.util.ResourceBundle getBundle(java.lang.String bundleName, java.util.Locale 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).
public java.util.Locale getLocale(java.lang.String header)
getLocale
in interface I18N
I18N.getLocale(String)
public java.lang.String getString(java.lang.String key)
getString
in interface I18N
public java.lang.String getString(java.lang.String key, java.util.Locale locale)
getString
in interface I18N
public java.lang.String getString(java.lang.String bundleName, java.util.Locale locale, java.lang.String key)
getString
in interface I18N
java.util.MissingResourceException
- Specified key cannot be matched.I18N.getString(String, Locale, String)
public java.lang.String format(java.lang.String key, java.lang.Object arg1)
format
in interface I18N
public java.lang.String format(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
format
in interface I18N
public java.lang.String format(java.lang.String bundleName, java.util.Locale locale, java.lang.String key, java.lang.Object arg1)
format
in interface I18N
I18N.format(String, Locale, String, Object)
public java.lang.String format(java.lang.String bundleName, java.util.Locale locale, java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
format
in interface I18N
I18N.format(String, Locale, String, Object, Object)
public java.lang.String format(java.lang.String bundleName, java.util.Locale locale, java.lang.String key, java.lang.Object[] args)
key
in the
ResourceBundle
referenced by
bundleName
, then formats that value for the
specified Locale
using args
.
format
in interface I18N
key
.public void initialize() throws org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
initialize
in interface org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
protected void initializeBundleNames()
private java.util.ResourceBundle cacheBundle(java.lang.String bundleName, java.util.Locale locale) throws java.util.MissingResourceException
java.util.MissingResourceException
- Bundle not found.private java.util.ResourceBundle findBundleByLocale(java.lang.String bundleName, java.util.Locale locale, java.util.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
.
private java.util.ResourceBundle getBundleIgnoreException(java.lang.String bundleName, java.util.Locale locale)
ResourceBundle.getBundle(String, Locale)
method,
returning null
instead of throwing
MissingResourceException
.
protected final java.lang.String getStringOrNull(java.util.ResourceBundle rb, java.lang.String key)
null
(ignoring a possible
MissingResourceException
).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |