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 HashMapprivate Stringprivate Stringprivate Stringprivate Localeprivate booleanprivate static final Object[]Fields inherited from interface I18N
ACCEPT_LANGUAGE, ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ResourceBundlecacheBundle(String bundleName, Locale locale) Caches the named bundle for fast lookups.private ResourceBundlefindBundleByLocale(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 forkeyin theResourceBundlereferenced bybundleName, then formats that value for the specifiedLocaleusingargs.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 ResourceBundlegetBundleIgnoreException(String bundleName, Locale locale) Retrieves the bundle using theResourceBundle.getBundle(String, Locale)method, returningnullinstead of throwingMissingResourceException.String[]protected final StringgetStringOrNull(ResourceBundle rb, String key) Gets localized text from a bundle if it's there.voidCalled the first time the Service is used.protected voidMethods 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:
getDefaultLanguagein interfaceI18N
-
getDefaultCountry
- Specified by:
getDefaultCountryin interfaceI18N
-
getDefaultBundleName
- Specified by:
getDefaultBundleNamein interfaceI18N
-
getBundleNames
- Specified by:
getBundleNamesin 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
-
format
-
format
-
format
-
format
-
format
Looks up the value forkeyin theResourceBundlereferenced bybundleName, then formats that value for the specifiedLocaleusingargs. -
initialize
public void initialize() throws org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExceptionCalled the first time the Service is used.- Specified by:
initializein 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, returningnullinstead of throwingMissingResourceException. -
getStringOrNull
Gets localized text from a bundle if it's there. Otherwise, returnsnull(ignoring a possibleMissingResourceException).
-