org.apache.fulcrum.localization
Class DefaultLocalizationService

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
          extended by 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:

Version:
$Id: DefaultLocalizationService.java 645885 2008-04-08 12:50:57Z tv $
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
 
Constructor Summary
DefaultLocalizationService()
          Creates a new instance.
 
Method Summary
 ResourceBundle getBundle(javax.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.
 ResourceBundle getBundle(String bundleName, javax.servlet.http.HttpServletRequest req)
          This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest.
 ResourceBundle getBundle(String bundleName, String languageHeader)
          This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.
 Locale getLocale(javax.servlet.http.HttpServletRequest req)
          Attempts to pull the Accept-Language header out of the HttpServletRequest object and then parse it.
 Locale getLocale(String header)
          Parses the Accept-Language header and attempts to create a Locale from it.
 
Methods inherited from class org.apache.fulcrum.localization.SimpleLocalizationServiceImpl
configure, format, format, format, getBundle, getBundle, getBundle, getBundleNames, getDefaultBundleName, getDefaultCountry, getDefaultLanguage, getDefaultLocale, 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, setBundle
 

Constructor Detail

DefaultLocalizationService

public DefaultLocalizationService()
Creates a new instance.

Method Detail

getBundle

public ResourceBundle getBundle(String bundleName,
                                String languageHeader)
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header.

Specified by:
getBundle in interface LocalizationService
Parameters:
bundleName - Name of bundle.
languageHeader - A String with the language header.
Returns:
A localized ResourceBundle.

getBundle

public ResourceBundle getBundle(javax.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.

Specified by:
getBundle in interface LocalizationService
Parameters:
req - HttpServletRequest.
Returns:
A localized ResourceBundle.

getBundle

public ResourceBundle getBundle(String bundleName,
                                javax.servlet.http.HttpServletRequest req)
This method returns a ResourceBundle given the bundle name and the Locale information supplied in the HTTP "Accept-Language" header which is stored in HttpServletRequest.

Specified by:
getBundle in interface LocalizationService
Parameters:
bundleName - Name of the bundle to use if the request's locale cannot be resolved.
req - HttpServletRequest.
Returns:
A localized ResourceBundle.

getLocale

public Locale getLocale(javax.servlet.http.HttpServletRequest req)
Description copied from interface: LocalizationService
Attempts to pull the Accept-Language header out of the HttpServletRequest object and then parse it. If the header is not present, it will return a null Locale.

Specified by:
getLocale in interface LocalizationService
Parameters:
req - The HTTP request to parse the Accept-Language of.
Returns:
The parsed locale.
See Also:
LocalizationService.getLocale(HttpServletRequest)

getLocale

public Locale getLocale(String header)
Description copied from interface: LocalizationService
Parses the Accept-Language header and attempts to create a Locale from it.

Specified by:
getLocale in interface LocalizationService
Returns:
The parsed locale, or a locale corresponding to the language and country defaults.
See Also:
LocalizationService.getLocale(String)


Copyright © 2005-2009 The Apache Software Foundation. All Rights Reserved.