Package org.codehaus.plexus.i18n
Class DefaultI18N
java.lang.Object
org.codehaus.plexus.logging.AbstractLogEnabled
org.codehaus.plexus.i18n.DefaultI18N
- All Implemented Interfaces:
I18N
,org.codehaus.plexus.logging.LogEnabled
,org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
public class DefaultI18N
extends org.codehaus.plexus.logging.AbstractLogEnabled
implements I18N, org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]
private HashMap
private String
private String
private String
private Locale
private boolean
private static final Object[]
Fields inherited from interface org.codehaus.plexus.i18n.I18N
ACCEPT_LANGUAGE, ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ResourceBundle
cacheBundle
(String bundleName, Locale locale) Caches the named bundle for fast lookups.private ResourceBundle
findBundleByLocale
(String bundleName, Locale locale, Map bundlesByLocale) Retrieves the bundle most closely matching first against the supplied inputs, then against the defaults.Looks up the value forkey
in theResourceBundle
referenced bybundleName
, then formats that value for the specifiedLocale
usingargs
.This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.This method returns a ResourceBundle for the given bundle name and the given Locale.private ResourceBundle
getBundleIgnoreException
(String bundleName, Locale locale) Retrieves the bundle using theResourceBundle.getBundle(String, Locale)
method, returningnull
instead of throwingMissingResourceException
.String[]
protected final String
getStringOrNull
(ResourceBundle rb, String key) Gets localized text from a bundle if it's there.void
Called the first time the Service is used.protected void
Methods inherited from class org.codehaus.plexus.logging.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
NO_ARGS
-
bundles
-
bundleNames
-
defaultBundleName
-
defaultLocale
-
defaultLanguage
-
defaultCountry
-
devMode
private boolean devMode
-
-
Constructor Details
-
DefaultI18N
public DefaultI18N()
-
-
Method Details
-
getDefaultLanguage
- Specified by:
getDefaultLanguage
in interfaceI18N
-
getDefaultCountry
- Specified by:
getDefaultCountry
in interfaceI18N
-
getDefaultBundleName
- Specified by:
getDefaultBundleName
in interfaceI18N
-
getBundleNames
- Specified by:
getBundleNames
in interfaceI18N
-
getBundle
-
getBundle
-
getBundle
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header. -
getBundle
This method returns a ResourceBundle for the given bundle name and the given Locale. -
getLocale
-
getString
-
getString
-
getString
- Specified by:
getString
in interfaceI18N
- Throws:
MissingResourceException
- Specified key cannot be matched.- See Also:
-
format
-
format
-
format
-
format
-
format
Looks up the value forkey
in theResourceBundle
referenced bybundleName
, then formats that value for the specifiedLocale
usingargs
. -
initialize
public void initialize() throws org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExceptionCalled the first time the Service is used.- Specified by:
initialize
in interfaceorg.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
- Throws:
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
-
initializeBundleNames
protected void initializeBundleNames() -
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.- Throws:
MissingResourceException
- Bundle not found.
-
findBundleByLocale
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
. -
getBundleIgnoreException
Retrieves the bundle using theResourceBundle.getBundle(String, Locale)
method, returningnull
instead of throwingMissingResourceException
. -
getStringOrNull
Gets localized text from a bundle if it's there. Otherwise, returnsnull
(ignoring a possibleMissingResourceException
).
-