org.apache.turbine.services.localization
Interface LocalizationService

All Superinterfaces:
Initable, Service
All Known Implementing Classes:
TurbineLocalizationService

public interface LocalizationService
extends Service

Provides localization functionality using the interface provided by ResourceBundle, plus leverages a "search path" style traversal of the ResourceBundle objects named by the locale.default.bundles to discover a value for a given key.

It is suggested that one handle dealing with concatenated messages using MessageFormat and properties files.

Version:
$Id: LocalizationService.java 534527 2007-05-02 16:10:59Z tv $
Author:
Jon S. Stevens, Daniel Rall, Leonard Richardson

Field Summary
static java.lang.String ACCEPT_LANGUAGE
          A constant for the HTTP Accept-Language header.
static java.lang.String SERVICE_NAME
          The name of this service.
 
Method Summary
 java.lang.String format(java.lang.String bundleName, java.util.Locale locale, java.lang.String key, java.lang.Object arg1)
          Formats a localized value using the provided object.
 java.lang.String format(java.lang.String bundleName, java.util.Locale locale, java.lang.String key, java.lang.Object[] args)
          Formats a localized value using the provided objects.
 java.lang.String format(java.lang.String bundleName, java.util.Locale locale, java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
          Formats a localized value using the provided objects.
 java.util.ResourceBundle getBundle()
          Convenience method to get a default ResourceBundle.
 java.util.ResourceBundle getBundle(javax.servlet.http.HttpServletRequest req)
          Convenience method to get a ResourceBundle based on HTTP Accept-Language header in HttpServletRequest.
 java.util.ResourceBundle getBundle(java.lang.String bundleName)
          Returns a ResourceBundle given the bundle name and the default locale information supplied by the configuration.
 java.util.ResourceBundle getBundle(java.lang.String bundleName, javax.servlet.http.HttpServletRequest req)
          Convenience method to get a ResourceBundle based on name and HTTP Accept-Language header in HttpServletRequest.
 java.util.ResourceBundle getBundle(java.lang.String bundleName, java.util.Locale locale)
          Convenience method to get a ResourceBundle based on name and Locale.
 java.util.ResourceBundle getBundle(java.lang.String bundleName, java.lang.String languageHeader)
          Convenience method to get a ResourceBundle based on name and HTTP Accept-Language header.
 java.lang.String[] getBundleNames()
          Retrieves the list of names of bundles to search by default for ResourceBundle keys (as specified in the config file).
 java.lang.String getDefaultBundleName()
          Retrieves the name of the default bundle (as specified in the config file), or the first in the list if there are more than one.
 java.lang.String getDefaultCountry()
          Retrieves the default country (as specified in the config file).
 java.lang.String getDefaultLanguage()
          Retrieves the default language (as specified in the config file).
 java.util.Locale getLocale(javax.servlet.http.HttpServletRequest req)
          Attempts to pull the Accept-Language header out of the HttpServletRequest object and then parse it.
 java.util.Locale getLocale(java.lang.String languageHeader)
          This method parses the Accept-Language header and attempts to create a Locale out of it.
 java.lang.String getString(java.lang.String bundleName, java.util.Locale locale, java.lang.String key)
          Tries very hard to return a value, looking first in the specified bundle, then searching list of default bundles (giving precedence to earlier bundles over later bundles).
 void setBundle(java.lang.String defaultBundle)
          This method sets the name of the defaultBundle.
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, init, setInitableBroker, shutdown
 

Field Detail

SERVICE_NAME

public static final java.lang.String SERVICE_NAME
The name of this service.

See Also:
Constant Field Values

ACCEPT_LANGUAGE

public static final java.lang.String ACCEPT_LANGUAGE
A constant for the HTTP Accept-Language header.

See Also:
Constant Field Values
Method Detail

getDefaultLanguage

public java.lang.String getDefaultLanguage()
Retrieves the default language (as specified in the config file).


getDefaultCountry

public java.lang.String getDefaultCountry()
Retrieves the default country (as specified in the config file).


getDefaultBundleName

public java.lang.String getDefaultBundleName()
Retrieves the name of the default bundle (as specified in the config file), or the first in the list if there are more than one.


getBundleNames

public java.lang.String[] getBundleNames()
Retrieves the list of names of bundles to search by default for ResourceBundle keys (as specified in the config file).

Returns:
The list of configured bundle names.

getBundle

public java.util.ResourceBundle getBundle()
Convenience method to get a default ResourceBundle.

Returns:
A localized ResourceBundle.

getBundle

public java.util.ResourceBundle getBundle(java.lang.String bundleName)
Returns a ResourceBundle given the bundle name and the default locale information supplied by the configuration.

Parameters:
bundleName - Name of bundle.
Returns:
A localized ResourceBundle.

getBundle

public java.util.ResourceBundle getBundle(java.lang.String bundleName,
                                          java.lang.String languageHeader)
Convenience method to get a ResourceBundle based on name and HTTP Accept-Language header.

Parameters:
bundleName - Name of bundle.
languageHeader - A String with the language header.
Returns:
A localized ResourceBundle.

getBundle

public java.util.ResourceBundle getBundle(javax.servlet.http.HttpServletRequest req)
Convenience method to get a ResourceBundle based on HTTP Accept-Language header in HttpServletRequest.

Parameters:
req - The HTTP request to parse the Accept-Language of.
Returns:
A localized ResourceBundle.

getBundle

public java.util.ResourceBundle getBundle(java.lang.String bundleName,
                                          javax.servlet.http.HttpServletRequest req)
Convenience method to get a ResourceBundle based on name and HTTP Accept-Language header in HttpServletRequest.

Parameters:
bundleName - Name of bundle.
req - The HTTP request to parse the Accept-Language of.
Returns:
A localized ResourceBundle.

getBundle

public java.util.ResourceBundle getBundle(java.lang.String bundleName,
                                          java.util.Locale locale)
Convenience method to get a ResourceBundle based on name and Locale.

Parameters:
bundleName - Name of bundle.
locale - A Locale.
Returns:
A localized ResourceBundle.

getLocale

public java.util.Locale getLocale(javax.servlet.http.HttpServletRequest req)
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.

Parameters:
req - The HTTP request to parse the Accept-Language of.
Returns:
The parsed locale.

getLocale

public java.util.Locale getLocale(java.lang.String languageHeader)
This method parses the Accept-Language header and attempts to create a Locale out of it.

Parameters:
languageHeader - The Accept-Language HTTP header.
Returns:
The parsed locale.

setBundle

public void setBundle(java.lang.String defaultBundle)
This method sets the name of the defaultBundle.

Parameters:
defaultBundle - Name of default bundle.

getString

public java.lang.String getString(java.lang.String bundleName,
                                  java.util.Locale locale,
                                  java.lang.String key)
Tries very hard to return a value, looking first in the specified bundle, then searching list of default bundles (giving precedence to earlier bundles over later bundles).

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.

format

public java.lang.String format(java.lang.String bundleName,
                               java.util.Locale locale,
                               java.lang.String key,
                               java.lang.Object arg1)
Formats a localized value using the provided object.

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.
Returns:
Formatted localized text.
See Also:
format(String, Locale, String, Object[])

format

public java.lang.String format(java.lang.String bundleName,
                               java.util.Locale locale,
                               java.lang.String key,
                               java.lang.Object arg1,
                               java.lang.Object arg2)
Formats a localized value using the provided objects.

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(String, Locale, String, Object[])

format

public java.lang.String format(java.lang.String bundleName,
                               java.util.Locale locale,
                               java.lang.String key,
                               java.lang.Object[] args)
Formats a localized value using the provided objects.

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:
Formatted localized text.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.