Package org.apache.fulcrum.localization
Class DefaultLocalizationService
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
org.apache.fulcrum.localization.DefaultLocalizationService
- All Implemented Interfaces:
org.apache.avalon.framework.activity.Initializable
,org.apache.avalon.framework.configuration.Configurable
,org.apache.avalon.framework.logger.LogEnabled
,LocalizationService
,SimpleLocalizationService
public class DefaultLocalizationService
extends SimpleLocalizationServiceImpl
implements LocalizationService
This class is the single point of access to all localization resources. It caches different ResourceBundles for different Locales.
Usage example:
LocalizationService ls = (LocalizationService) TurbineServices
.getInstance().getService(LocalizationService.SERVICE_NAME);
Then call SimpleLocalizationServiceImpl.getString(String, Locale, String)
, or one of
four methods to retrieve a ResourceBundle:
- getBundle("MyBundleName")
- getBundle("MyBundleName", httpAcceptLanguageHeader)
- etBundle("MyBundleName", HttpServletRequest)
- getBundle("MyBundleName", Locale)
- etc.
- Version:
- $Id$ avalon.component name="localization" lifestyle="singleton" avalon.service type="org.apache.fulcrum.localization.LocalizationService"
- 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.LocalizationService
ACCEPT_LANGUAGE, ROLE, SERVICE_NAME
Fields inherited from interface org.apache.fulcrum.localization.SimpleLocalizationService
ROLE, SERVICE_NAME
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBundle
(jakarta.servlet.http.HttpServletRequest req) This method returns a ResourceBundle given the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest.Convenience method to get aResourceBundle
based on name and HTTPAccept-Language
header from aHttpServletRequest
.This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.getLocale
(jakarta.servlet.http.HttpServletRequest req) Attempts to pull theAccept-Language
header out of theHttpServletRequest
object and then parse it.Parses theAccept-Language
header and attempts to create aLocale
from it.Methods inherited from class org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
configure, format, format, format, getBundle, getBundle, getBundle, getBundleNames, getDefaultBundleName, getDefaultCountry, getDefaultLanguage, getDefaultLocale, getString, getString, getStringOrNull, initBundleNames, initialize, setBundle
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.fulcrum.localization.SimpleLocalizationService
format, format, format, getBundle, getBundle, getBundle, getBundleNames, getDefaultBundleName, getDefaultCountry, getDefaultLanguage, getDefaultLocale, getString, getString, setBundle
-
Constructor Details
-
DefaultLocalizationService
public DefaultLocalizationService()Creates a new instance.
-
-
Method Details
-
getBundle
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.- Specified by:
getBundle
in interfaceLocalizationService
- Parameters:
bundleName
- Name of bundle.languageHeader
- A String with the language header.- Returns:
- A localized ResourceBundle.
- See Also:
-
getBundle
This method returns a ResourceBundle given the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest.- Specified by:
getBundle
in interfaceLocalizationService
- Parameters:
req
- HttpServletRequest.- Returns:
- A localized ResourceBundle.
-
getBundle
Description copied from interface:LocalizationService
Convenience method to get aResourceBundle
based on name and HTTPAccept-Language
header from aHttpServletRequest
.- Specified by:
getBundle
in interfaceLocalizationService
- Parameters:
bundleName
- Name of the bundle to use if the request's locale cannot be resolved.req
- HttpServletRequest.- Returns:
- A localized ResourceBundle.
- See Also:
-
getLocale
Description copied from interface:LocalizationService
Attempts to pull theAccept-Language
header out of theHttpServletRequest
object and then parse it. If the header is not present, it will return anull
Locale
.- Specified by:
getLocale
in interfaceLocalizationService
- Parameters:
req
- The HTTP request to parse theAccept-Language
of.- Returns:
- The parsed locale.
-
getLocale
Description copied from interface:LocalizationService
Parses theAccept-Language
header and attempts to create aLocale
from it.- Specified by:
getLocale
in interfaceLocalizationService
- Parameters:
header
- The language header (i.e.en, es;q=0.8, zh-TW;q=0.1
), ornull
for the locale corresponding to the default language and country.- Returns:
- The parsed locale, or a locale corresponding to the language and country defaults.
-