org.apache.turbine.services.localization
Class Localization

java.lang.Object
  extended byorg.apache.turbine.services.localization.Localization

public abstract class Localization
extends java.lang.Object

Wrapper around the TurbineLocalization Service that makes it easy to grab something from the service and make the code cleaner.

Instead of typing:
((LocalizationService)TurbineServices.getInstance()
.getService(LocalizationService.SERVICE_NAME))
.getBundle(data)
.getString(str)
Now you only need to type:
Localization.getString(str)

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

Constructor Summary
Localization()
           
 
Method Summary
static 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.
static 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.
static 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.
static java.util.ResourceBundle getBundle(javax.servlet.http.HttpServletRequest req)
          Convenience method to get a ResourceBundle based on name and HTTP Accept-Language header in HttpServletRequest.
static java.util.ResourceBundle getBundle(java.lang.String bundleName)
          Convenience method to get a ResourceBundle based on name.
static 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.
static java.util.ResourceBundle getBundle(java.lang.String bundleName, java.util.Locale locale)
          Convenience method to get a ResourceBundle based on name and Locale.
static java.util.ResourceBundle getBundle(java.lang.String bundleName, RunData data)
          Deprecated. Call getBundle(bundleName, data.getRequest()) instead.
static 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.
static java.lang.String getDefaultBundleName()
           
static 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.
static java.util.Locale getLocale(java.lang.String languageHeader)
          This method parses the Accept-Language header and attempts to create a Locale out of it.
protected static LocalizationService getService()
          Gets the LocalizationService implementation.
static java.lang.String getString(RunData data, java.lang.String key)
          Deprecated. Call getString(key, data.getRequest()) instead.
static java.lang.String getString(java.lang.String key)
          Pulls a string out of the LocalizationService with the default locale values of what is defined in the TurbineResources.properties file for the locale.default.language and locale.default.country property values.
static java.lang.String getString(java.lang.String key, javax.servlet.http.HttpServletRequest req)
          Pulls a string out of the LocalizationService and attempts to determine the Locale by the Accept-Language header.
static java.lang.String getString(java.lang.String key, java.util.Locale locale)
           
static java.lang.String getString(java.lang.String bundleName, java.util.Locale locale, java.lang.String key)
          Fetches the localized text from the specified bundle, ignoring any default bundles.
static java.lang.String getString(java.lang.String key, java.lang.String lang)
          Convenience method that pulls a localized string off the LocalizationService using the default ResourceBundle name defined in the TurbineResources.properties file and the specified language name in ISO format.
static void setBundle(java.lang.String defaultBundle)
          This method sets the name of the default bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Localization

public Localization()
Method Detail

getString

public static java.lang.String getString(java.lang.String bundleName,
                                         java.util.Locale locale,
                                         java.lang.String key)
Fetches the localized text from the specified bundle, ignoring any default bundles.

See Also:
LocalizationService.getString(String, Locale, String)

getString

public static java.lang.String getString(java.lang.String key)
Pulls a string out of the LocalizationService with the default locale values of what is defined in the TurbineResources.properties file for the locale.default.language and locale.default.country property values. If those cannot be found, then the JVM defaults are used.

Parameters:
key - Name of string.
Returns:
A localized String.

getString

public static java.lang.String getString(java.lang.String key,
                                         java.util.Locale locale)
Parameters:
key - Name of the text to retrieve.
locale - Locale to get text for.
Returns:
Localized text.

getString

public static java.lang.String getString(java.lang.String key,
                                         javax.servlet.http.HttpServletRequest req)
Pulls a string out of the LocalizationService and attempts to determine the Locale by the Accept-Language header. If that header is not present, it will fall back to using the locale values of what is defined in the TurbineResources.properties file for the locale.default.language and locale.default.country property values. If those cannot be found, then the JVM defaults are used.

Parameters:
req - HttpServletRequest information.
key - Name of string.
Returns:
A localized String.

getString

public static java.lang.String getString(java.lang.String key,
                                         java.lang.String lang)
Convenience method that pulls a localized string off the LocalizationService using the default ResourceBundle name defined in the TurbineResources.properties file and the specified language name in ISO format.

Parameters:
key - Name of string.
lang - Desired language for the localized string.
Returns:
A localized string.

getBundle

public static java.util.ResourceBundle getBundle(java.lang.String bundleName)
Convenience method to get a ResourceBundle based on name.

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

getBundle

public static 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 static java.util.ResourceBundle getBundle(javax.servlet.http.HttpServletRequest req)
Convenience method to get a ResourceBundle based on name and HTTP Accept-Language header in HttpServletRequest.

Parameters:
req - HttpServletRequest.
Returns:
A localized ResourceBundle.

getBundle

public static 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 - HttpServletRequest.
Returns:
A localized ResourceBundle.

getBundle

public static 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.

setBundle

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

Parameters:
defaultBundle - Name of default bundle.

getLocale

public static 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 - HttpServletRequest.
Returns:
A Locale.

getLocale

public static 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 - A String with the language header.
Returns:
A Locale.

getDefaultBundleName

public static java.lang.String getDefaultBundleName()
See Also:
org.apache.turbine.services.localization.LocalizationService#getDefaultBundle()

format

public static 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 static 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 static 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.

getService

protected static final LocalizationService getService()
Gets the LocalizationService implementation.

Returns:
the LocalizationService implementation.

getString

public static java.lang.String getString(RunData data,
                                         java.lang.String key)
Deprecated. Call getString(key, data.getRequest()) instead.


getBundle

public static java.util.ResourceBundle getBundle(java.lang.String bundleName,
                                                 RunData data)
Deprecated. Call getBundle(bundleName, data.getRequest()) instead.



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