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 Summary
Fields inherited from interface org.apache.fulcrum.localization.SimpleLocalizationService
ROLE, SERVICE_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier 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.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Constructor Details
-
SimpleLocalizationServiceImpl
public SimpleLocalizationServiceImpl()Creates a new instance.
-
-
Method Details
-
configure
public void configure(org.apache.avalon.framework.configuration.Configuration conf) throws org.apache.avalon.framework.configuration.ConfigurationException Avalon lifecycle methodConfigurable- Specified by:
configurein interfaceorg.apache.avalon.framework.configuration.Configurable- Parameters:
conf- the configuration- Throws:
org.apache.avalon.framework.configuration.ConfigurationException- if failed to configure
-
initialize
Called the first time the Service is used.- Specified by:
initializein interfaceorg.apache.avalon.framework.activity.Initializable- Throws:
Exception- generic exception
-
initBundleNames
Initialize list of default bundle names.- Parameters:
intBundleNames- set bundle names
-
getDefaultLanguage
Retrieves the default language (specified in the config file).- Specified by:
getDefaultLanguagein interfaceSimpleLocalizationService- Returns:
- the default language
-
getDefaultCountry
Retrieves the default country (specified in the config file).- Specified by:
getDefaultCountryin interfaceSimpleLocalizationService- Returns:
- the default country
-
getDefaultLocale
Retrieves the default Locale (as created from default language and default country).- Specified by:
getDefaultLocalein interfaceSimpleLocalizationService- Returns:
- the default locale
-
getDefaultBundleName
- Specified by:
getDefaultBundleNamein interfaceSimpleLocalizationService- Returns:
- the default bundle name
-
getBundleNames
- Specified by:
getBundleNamesin interfaceSimpleLocalizationService- Returns:
- list of bundle names available
-
getBundle
Description copied from interface:SimpleLocalizationServiceConvenience method to get the defaultResourceBundle.- Specified by:
getBundlein interfaceSimpleLocalizationService- Returns:
- the default resource bundle
- See Also:
-
getBundle
Description copied from interface:SimpleLocalizationServiceReturns a ResourceBundle given the bundle name and the default locale information supplied by the configuration.- Specified by:
getBundlein interfaceSimpleLocalizationService- Parameters:
bundleName- the name of a bundle- Returns:
- the resource bundle
- See Also:
-
getBundle
Description copied from interface:SimpleLocalizationServiceConvenience method to get a ResourceBundle based on name and Locale.- Specified by:
getBundlein interfaceSimpleLocalizationService- Parameters:
bundleName- Name of bundle (ornullfor the default bundle).locale- The locale (ornullfor the locale indicated by the default language and country).- Returns:
- A localized ResourceBundle.
- See Also:
-
setBundle
This method sets the name of the first bundle in the search list (the "default" bundle).- Specified by:
setBundlein interfaceSimpleLocalizationService- Parameters:
defaultBundle- Name of default bundle.
-
getString
public String getString(String bundleName, Locale locale, String key) throws MissingResourceException - Specified by:
getStringin interfaceSimpleLocalizationService- 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.
-
getString
Returns the value for the key in the default bundle and the default locale.- Specified by:
getStringin interfaceSimpleLocalizationService- Parameters:
key- The key to retrieve the value for.- Returns:
- The value mapped to the key.
-
getStringOrNull
Gets localized text from a bundle if it's there. Otherwise, returnsnull(ignoring a possibleMissingResourceException).- Parameters:
rb- resource bundlekey- The key to retrieve the value for.- Returns:
- name of resource
-
format
- Specified by:
formatin interfaceSimpleLocalizationService- Parameters:
bundleName- the bundle namelocale- localekey- key to lookuparg1- bundle arguments- Returns:
- Formatted localized text.
- See Also:
-
format
Description copied from interface:SimpleLocalizationServiceFormats a localized value using the provided objects.- Specified by:
formatin interfaceSimpleLocalizationService- 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:
-
format
Looks 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 interfaceSimpleLocalizationService- 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.
-