Package org.apache.fulcrum.localization
Class SimpleLocalizationServiceImpl
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
- All Implemented Interfaces:
- org.apache.avalon.framework.activity.Initializable,- org.apache.avalon.framework.configuration.Configurable,- org.apache.avalon.framework.logger.LogEnabled,- SimpleLocalizationService
- Direct Known Subclasses:
- DefaultLocalizationService
public class SimpleLocalizationServiceImpl
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements SimpleLocalizationService, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable
This class is the single point of access to all localization resources. It caches different ResourceBundles for different Locales.
Usage example:
 
 SimpleLocalizationService ls = (SimpleLocalizationService) TurbineServices
     .getInstance().getService(SimpleLocalizationService.SERVICE_NAME);
 
 
 
 Then call getString(String, Locale, String), or one of
 two methods to retrieve a ResourceBundle:
 
- getBundle("MyBundleName")
- getBundle("MyBundleName", Locale)
- etc.
- Version:
- $Id: DefaultLocalizationService.java 535465 2007-05-05 06:58:06Z tv $ avalon.component name="localization" lifestyle="singleton" avalon.service type="org.apache.fulcrum.localization.SimpleLocalizationService"
- Author:
- Jonas Maurus, Jon S. Stevens, Frank Y. Kim, Daniel Rall, Leonard Richardson, Stephen McConnell, Thomas Vandahl
- 
Field SummaryFields inherited from interface org.apache.fulcrum.localization.SimpleLocalizationServiceROLE, SERVICE_NAME
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidconfigure(org.apache.avalon.framework.configuration.Configuration conf) Avalon lifecycle methodConfigurableLooks up the value forkeyin theResourceBundlereferenced bybundleName, then formats that value for the specifiedLocaleusingargs.Formats a localized value using the provided objects.Convenience method to get the defaultResourceBundle.Returns a ResourceBundle given the bundle name and the default locale information supplied by the configuration.Convenience method to get a ResourceBundle based on name and Locale.String[]Retrieves the default country (specified in the config file).Retrieves the default language (specified in the config file).Retrieves the default Locale (as created from default language and default country).Returns the value for the key in the default bundle and the default locale.protected final StringgetStringOrNull(ResourceBundle rb, String key) Gets localized text from a bundle if it's there.protected voidinitBundleNames(String[] intBundleNames) Initialize list of default bundle names.voidCalled the first time the Service is used.voidThis method sets the name of the first bundle in the search list (the "default" bundle).Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabledenableLogging, getLogger, setupLogger, setupLogger, setupLogger
- 
Constructor Details- 
SimpleLocalizationServiceImplpublic SimpleLocalizationServiceImpl()Creates a new instance.
 
- 
- 
Method Details- 
configurepublic void configure(org.apache.avalon.framework.configuration.Configuration conf) throws org.apache.avalon.framework.configuration.ConfigurationException Avalon lifecycle methodConfigurable- Specified by:
- configurein interface- org.apache.avalon.framework.configuration.Configurable
- Parameters:
- conf- the configuration
- Throws:
- org.apache.avalon.framework.configuration.ConfigurationException- if failed to configure
 
- 
initializeCalled the first time the Service is used.- Specified by:
- initializein interface- org.apache.avalon.framework.activity.Initializable
- Throws:
- Exception- generic exception
 
- 
initBundleNamesInitialize list of default bundle names.- Parameters:
- intBundleNames- set bundle names
 
- 
getDefaultLanguageRetrieves the default language (specified in the config file).- Specified by:
- getDefaultLanguagein interface- SimpleLocalizationService
- Returns:
- the default language
 
- 
getDefaultCountryRetrieves the default country (specified in the config file).- Specified by:
- getDefaultCountryin interface- SimpleLocalizationService
- Returns:
- the default country
 
- 
getDefaultLocaleRetrieves the default Locale (as created from default language and default country).- Specified by:
- getDefaultLocalein interface- SimpleLocalizationService
- Returns:
- the default locale
 
- 
getDefaultBundleName- Specified by:
- getDefaultBundleNamein interface- SimpleLocalizationService
- Returns:
- the default bundle name
 
- 
getBundleNames- Specified by:
- getBundleNamesin interface- SimpleLocalizationService
- Returns:
- list of bundle names available
 
- 
getBundleDescription copied from interface:SimpleLocalizationServiceConvenience method to get the defaultResourceBundle.- Specified by:
- getBundlein interface- SimpleLocalizationService
- Returns:
- the default resource bundle
- See Also:
 
- 
getBundleDescription copied from interface:SimpleLocalizationServiceReturns a ResourceBundle given the bundle name and the default locale information supplied by the configuration.- Specified by:
- getBundlein interface- SimpleLocalizationService
- Parameters:
- bundleName- the name of a bundle
- Returns:
- the resource bundle
- See Also:
 
- 
getBundleDescription copied from interface:SimpleLocalizationServiceConvenience method to get a ResourceBundle based on name and Locale.- Specified by:
- getBundlein interface- SimpleLocalizationService
- Parameters:
- bundleName- Name of bundle (or- nullfor the default bundle).
- locale- The locale (or- nullfor the locale indicated by the default language and country).
- Returns:
- A localized ResourceBundle.
- See Also:
 
- 
setBundleThis method sets the name of the first bundle in the search list (the "default" bundle).- Specified by:
- setBundlein interface- SimpleLocalizationService
- Parameters:
- defaultBundle- Name of default bundle.
 
- 
getStringpublic String getString(String bundleName, Locale locale, String key) throws MissingResourceException - Specified by:
- getStringin interface- SimpleLocalizationService
- Parameters:
- bundleName- Name of the bundle to look in first.
- locale- Locale to get text for.
- key- Name of the text to retrieve.
- Returns:
- Localized text.
- Throws:
- MissingResourceException- Specified key cannot be matched.
 
- 
getStringReturns the value for the key in the default bundle and the default locale.- Specified by:
- getStringin interface- SimpleLocalizationService
- Parameters:
- key- The key to retrieve the value for.
- Returns:
- The value mapped to the key.
 
- 
getStringOrNullGets localized text from a bundle if it's there. Otherwise, returnsnull(ignoring a possibleMissingResourceException).- Parameters:
- rb- resource bundle
- key- The key to retrieve the value for.
- Returns:
- name of resource
 
- 
format- Specified by:
- formatin interface- SimpleLocalizationService
- Parameters:
- bundleName- the bundle name
- locale- locale
- key- key to lookup
- arg1- bundle arguments
- Returns:
- Formatted localized text.
- See Also:
 
- 
formatDescription copied from interface:SimpleLocalizationServiceFormats a localized value using the provided objects.- Specified by:
- formatin interface- SimpleLocalizationService
- Parameters:
- bundleName- The bundle in which to look for the localizable text.
- locale- The locale for which to format the text.
- key- The identifier for the localized text to retrieve,
- arg1- The object to use as {0} when formatting the localized text.
- arg2- The object to use as {1} when formatting the localized text.
- Returns:
- Formatted localized text.
- See Also:
 
- 
formatLooks up the value forkeyin theResourceBundlereferenced bybundleName, then formats that value for the specifiedLocaleusingargs. Iflocaleisnull,getDefaultLocale()will be checked. IfbundleNameisnull,getDefaultBundleName()will be checked (cft.getBundle(String, Locale).- Specified by:
- formatin interface- SimpleLocalizationService
- Parameters:
- bundleName- The bundle in which to look for the localizable text.
- locale- The locale for which to format the text.
- key- The identifier for the localized text to retrieve,
- args- The objects to use as {0}, {1}, etc. when formatting the localized text.
- Returns:
- Localized, formatted text identified by
 key.
 
 
-