atg.core.i18n
Class LocaleTools

java.lang.Object
  extended by atg.core.i18n.LocaleTools

public class LocaleTools
extends java.lang.Object

A utility class used to obtain an array of all available locales and a user preferred locale to be used for UI representation of dates. The representation of dates are based on the pre-existing styles defined within SimpleDateFormat.java as follows: DEFAULT, FULL, LONG, MEDIUM, SHORT


Nested Class Summary
 class LocaleTools.LocaleHelper
          UI helper class implementing utility methods on the locale object.
 
Field Summary
static java.lang.String CLASS_VERSION
           
static java.lang.String LOCALE_TOOLS_PATH
           
 
Constructor Summary
LocaleTools()
          Class constructor.
 
Method Summary
 LocaleTools.LocaleHelper[] getAvailableLocaleHelpers()
          Returns an array of LocaleHelper for all available locales.
 java.lang.String getDateStyle()
          Returns the locale date pattern style.
 java.lang.String getDateTimeStyle()
          Returns the locale dateTime pattern style.
static LocaleTools getInstance()
          Resolves LocaleTools component instance by path, if there is DynamoHttpServletRequest object associated with the current thread.
static java.util.Locale getLocale(java.lang.String pLocale)
          The pLocale argument represents the entire locale, with the language, country and variant separated by underbars.
 java.lang.String getProfileLocalePropertyName()
          Returns the property on the user profile that holds the user preferred locale for representing dates.
 java.lang.String getTimeStyle()
          Returns the locale time pattern style.
 boolean getUseNumberGrouping()
          Returns true if grouping is being used with number formatting.
 LocaleTools.LocaleHelper getUserFormattingLocaleHelper()
          Returns a LocaleHelper for the user preferred locale to be used when displaying formatted dates.
 LocaleTools.LocaleHelper getUserLocaleHelper()
          Returns the LocaleHelper to use when looking up localized messages for display to the user.
 void setDateStyle(java.lang.String pStyle)
          Defines the locale date pattern style to use for subsequent calls to LocaleHelper.getDatePattern().
 void setDateTimeStyle(java.lang.String pStyle)
          Defines the locale dateTime pattern style to use for subsequent calls to LocaleHelper.getDateTimePattern().
 void setProfileLocalePropertyName(java.lang.String pProfileLocalePropertyName)
          Sets the property on the user profile that holds the user preferred locale for representing dates.
 void setTimeStyle(java.lang.String pStyle)
          Defines the locale time pattern style to use for subsequent calls to LocaleHelper.getTimePattern().
 void setUseNumberGrouping(boolean pUseNumberGrouping)
          Set whether grouping is being used with number formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION

LOCALE_TOOLS_PATH

public static final java.lang.String LOCALE_TOOLS_PATH
See Also:
Constant Field Values
Constructor Detail

LocaleTools

public LocaleTools()
Class constructor. Initialises allowable date styles by making a call onto the setStyles method. Allowable styles are based upon constants defined within SimpleDateFormat.java. The following styles are defined: "DEFAULT", "FULL", "LONG", "MEDIUM", "SHORT"

See Also:
SimpleDateFormat
Method Detail

getInstance

public static LocaleTools getInstance()
Resolves LocaleTools component instance by path, if there is DynamoHttpServletRequest object associated with the current thread.

Returns:
LocaleTools component instance, if there is DynamoHttpServletRequest associated with the current thread, otherwise null

setProfileLocalePropertyName

public void setProfileLocalePropertyName(java.lang.String pProfileLocalePropertyName)
Sets the property on the user profile that holds the user preferred locale for representing dates.

Parameters:
pProfileLocalePropertyName - The property on the user profile that holds the user preferred locale for representing dates.

getProfileLocalePropertyName

public java.lang.String getProfileLocalePropertyName()
Returns the property on the user profile that holds the user preferred locale for representing dates.

Returns:
The property on the user profile that holds the user preferred locale for representing dates

setDateStyle

public void setDateStyle(java.lang.String pStyle)
Defines the locale date pattern style to use for subsequent calls to LocaleHelper.getDatePattern(). This can be used from within a jsp for example as follows:
 
 <dsp:importbean bean="/atg/core/i18n/LocaleTools"/>
 <dsp:setvalue bean="LocaleTools.dateStyle" value="short"/>
 <fmt:formatDate value="${date}" pattern="${LocaleTools.userPreferredLocale.datePattern}"/>
 
 

Parameters:
pStyle - The locale date pattern style.

getDateStyle

public java.lang.String getDateStyle()
Returns the locale date pattern style.

Returns:
The locale date pattern style.

setDateTimeStyle

public void setDateTimeStyle(java.lang.String pStyle)
Defines the locale dateTime pattern style to use for subsequent calls to LocaleHelper.getDateTimePattern(). This can be used from within a jsp for example as follows:

 
 <dsp:importbean bean="/atg/core/i18n/LocaleTools"/>
 <dsp:setvalue bean="LocaleTools.dateTimeStyle" value="short"/>
 <fmt:formatDate value="${dateTime}" pattern="${LocaleTools.userPreferredLocale.dateTimePattern}"/>
 
 

Parameters:
pStyle - The locale dateTime pattern style.

getDateTimeStyle

public java.lang.String getDateTimeStyle()
Returns the locale dateTime pattern style.

Returns:
The locale dateTime pattern style.

setTimeStyle

public void setTimeStyle(java.lang.String pStyle)
Defines the locale time pattern style to use for subsequent calls to LocaleHelper.getTimePattern(). This can be used from within a jsp for example as follows:
 
 <dsp:importbean bean="/atg/core/i18n/LocaleTools"/>
 <dsp:setvalue bean="LocaleTools.timeStyle" value="short"/>
 <fmt:formatDate value="${time}" pattern="${LocaleTools.userPreferredLocale.timePattern}"/>
 
 

Parameters:
pStyle - The locale time pattern style.

getTimeStyle

public java.lang.String getTimeStyle()
Returns the locale time pattern style.

Returns:
The locale time pattern style.

setUseNumberGrouping

public void setUseNumberGrouping(boolean pUseNumberGrouping)
Set whether grouping is being used with number formatting.

Parameters:
pUseNumberGrouping - boolean

getUseNumberGrouping

public boolean getUseNumberGrouping()
Returns true if grouping is being used with number formatting.

Returns:
boolean

getAvailableLocaleHelpers

public LocaleTools.LocaleHelper[] getAvailableLocaleHelpers()
Returns an array of LocaleHelper for all available locales.

Returns:
An array of LocaleHelper for all available locales.
See Also:
DateFormat.getAvailableLocales()

getUserLocaleHelper

public LocaleTools.LocaleHelper getUserLocaleHelper()
Returns the LocaleHelper to use when looking up localized messages for display to the user. The locale returned will be from the request or the default server locale if no request locale exists.

Returns:
The locale to use when looking up localized messages.
See Also:
ServletUtil.getUserLocale()

getUserFormattingLocaleHelper

public LocaleTools.LocaleHelper getUserFormattingLocaleHelper()
Returns a LocaleHelper for the user preferred locale to be used when displaying formatted dates. First looks in the user's profile, then the request, then the server default.

Returns:
The user preferred locale to be used when displaying formatted dates.

getLocale

public static java.util.Locale getLocale(java.lang.String pLocale)
The pLocale argument represents the entire locale, with the language, country and variant separated by underbars. Language is always lower case, and country is always upper case. If the language is missing, the string will begin with an underbar. If both the language and country fields are missing, this function will return the empty string, even if the variant field is filled in (you can't have a locale with just a variant-- the variant must accompany a valid language or country code). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC" Language code is a valid ISO Language Code. These codes are the lower-case, two-letter codes as defined by ISO-639. You can find a full list of these codes at a number of sites, such as:
http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt Country cope is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:
http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html

Returns:
Locale associated with the language, null if could not be found