Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.util
Class LocaleUtils

java.lang.Object
  extended by com.jivesoftware.util.LocaleUtils

public class LocaleUtils
extends java.lang.Object

A set of methods for retrieving and converting locale specific strings and numbers.


Method Summary
static java.lang.String getDateFormatPattern(java.util.Locale locale)
          Returns the DateFormat pattern for the given locale
static java.util.Map getISO639LanguageMap()
          Returns a map of ISO-639 languages.
static java.lang.String getLocaleAlignment(java.util.Locale locale)
          Returns the alignment direction for a given locale.
static java.lang.String getLocalizedNumber(double number)
          Returns a number formatted to the rules of the default Jive Forums locale.
static java.lang.String getLocalizedNumber(double number, java.util.Locale locale)
          Returns a number formatted to the rules of the given locale.
static java.lang.String getLocalizedNumber(long number)
          Returns a number formatted to the rules of the default Jive Forums locale.
static java.lang.String getLocalizedNumber(long number, java.util.Locale locale)
          Returns a number formatted to the rules of the given locale.
static java.lang.String getLocalizedString(java.lang.String key)
          Returns an internationalized string loaded from a resource bundle.
static java.lang.String getLocalizedString(java.lang.String key, java.util.List arguments)
          Returns an internationalized string loaded from a resource bundle using the locale specified by JiveGlobals.getLocale() substituting the passed in arguments.
static java.lang.String getLocalizedString(java.lang.String key, java.util.Locale locale)
          Returns an internationalized string loaded from a resource bundle using the passed in Locale.
static java.lang.String getLocalizedString(java.lang.String key, java.util.Locale locale, java.util.List arguments)
          Returns an internationalized string loaded from a resource bundle using the passed in Locale substituting the passed in arguments.
static java.lang.String getLocalizedString(java.lang.String key, java.util.Locale locale, java.util.List arguments, java.util.ResourceBundle bundle)
          Returns an internationalized string loaded from a resource bundle using the passed in Locale substituting the passed in arguments.
static java.lang.String getLocalizedString(java.lang.String key, java.lang.String pluginName)
          Returns an internationalized string loaded from a resource bundle from the passed in plugin.
static java.lang.String getLocalizedString(java.lang.String key, java.lang.String pluginName, java.util.List arguments)
          Returns an internationalized string loaded from a resource bundle from the passed in plugin.
static java.util.ResourceBundle getResourceBundle(java.lang.String baseName)
          Wrapper method to get a resource bundle for the default locale.
static java.util.ResourceBundle getResourceBundle(java.lang.String baseName, java.util.Locale locale)
          Deprecated. Use just ResourceBundle.getBundle(String,Locale) instead.
static java.lang.String getShortDateFormatPattern(java.util.Locale locale)
           
static java.util.TimeZone getTimeZone(javax.servlet.http.HttpServletRequest request, User user)
          Returns the time zone for a user according to their time zone preferences (if they exist).
static java.lang.String[][] getTimeZoneList()
          Returns a list of all available time zone's as a String [][].
static java.lang.String[][] getTimeZoneList(java.util.Locale locale)
          Returns the list of all available time zone's as a String [][], based on the specified locale.
static java.util.Locale getUserLocale(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String sessionKey)
          Returns the user's locale.
static java.util.Locale getUserLocale(javax.servlet.http.HttpServletRequest request, User user)
          Returns the page user's locale.
static java.util.Locale getUserLocale(java.lang.String sessionKey)
          Returns the user's locale using the authtoken from the HttpSession.
static boolean isValidCharacterEncoding(java.lang.String encoding)
          Returns true if the given character encoding is valid, false otherwise.
static java.util.Locale localeCodeToLocale(java.lang.String localeCode)
          Converts a locale string like "en", "en_US" or "en_US_win" to a Java locale object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

localeCodeToLocale

public static java.util.Locale localeCodeToLocale(java.lang.String localeCode)
Converts a locale string like "en", "en_US" or "en_US_win" to a Java locale object. If the conversion fails, null is returned.

Parameters:
localeCode - the locale code for a Java locale. See the Locale class for more details.

isValidCharacterEncoding

public static boolean isValidCharacterEncoding(java.lang.String encoding)
Returns true if the given character encoding is valid, false otherwise.

Parameters:
encoding - the encoding to test.
Returns:
true if the encoding is valid, false otherwise.

getISO639LanguageMap

public static java.util.Map getISO639LanguageMap()
Returns a map of ISO-639 languages. The key for each map element is the ISO-639 language code, and the value is the ISO-639 language name.

Returns:
a map of ISO-639 languages keyed by language code.

getTimeZoneList

public static java.lang.String[][] getTimeZoneList()
Returns a list of all available time zone's as a String [][]. The first entry in each list item is the timeZoneID, and the second is the display name.

The list of time zones attempts to be inclusive of all of the worlds zones while being as concise as possible. For "en" language locales the name is a friendly english name. For non-"en" language locales the standard JDK name is used for the given Locale. The GMT+/- time is also included for readability.

Returns:
a list of time zones, as a tuple of the zime zone ID, and its display name.

getTimeZoneList

public static java.lang.String[][] getTimeZoneList(java.util.Locale locale)
Returns the list of all available time zone's as a String [][], based on the specified locale. Does not use the global locale, as with getTimeZoneList().

Parameters:
locale - for localizing the time zone.
Returns:
a list of time zones, as a tuple of the zime zone ID, and its display name.

getUserLocale

public static java.util.Locale getUserLocale(javax.servlet.http.HttpServletRequest request,
                                             User user)
Returns the page user's locale. If the user is logged in and users are allowed to specify their own locales then the user's locale preference is checked and if that is a valid locale, it is returned. If the user is not logged in and users are allowed to specify their own locales then this method will attempt to retrieve the locale setting out of the guest's cookie.

If any locale lookups fail, the default Jive locale will be used.

Returns:
the page user's locale
See Also:
JiveGlobals.getLocale(), Locale

getUserLocale

public static java.util.Locale getUserLocale(javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response,
                                             java.lang.String sessionKey)
Returns the user's locale. If found, otherwise return the system default. This is used as a convenience method over getUserLocale(request, user), when the User object is not immediately available.

Parameters:
request - the current request.
response - the current response.
sessionKey - the key to the HttpSession for the authToken to be obtained from.
Returns:
the user's locale if found, otherwise the system default
See Also:
JiveGlobals.getLocale(), Locale

getUserLocale

public static java.util.Locale getUserLocale(java.lang.String sessionKey)
Returns the user's locale using the authtoken from the HttpSession. If found, otherwise return the system default. This is used as a convenience method over getUserLocale(request, user), when the User object and HttpRequest is not immediately available.

Parameters:
sessionKey - the key to the HttpSession for the authToken to be obtained from.
Returns:
the user's locale if found, otherwise the system default
See Also:
JiveGlobals.getLocale(), Locale

getTimeZone

public static java.util.TimeZone getTimeZone(javax.servlet.http.HttpServletRequest request,
                                             User user)
Returns the time zone for a user according to their time zone preferences (if they exist). Timezones preferences for users are stored in the user property jiveTimeZoneID, while timezones for anonymous users are stored in the cookie named jiveTimeZoneID. If no preferences are found, the default Jive timezone is used (JiveGlobals.getTimeZone()).

Parameters:
request - the servlet request object for looking up a timezone cookie for anonymous users. This can be null.
user - the User that the date is being formatted for, or null if an anonymous user.
Returns:
a time zone object.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key)
Returns an internationalized string loaded from a resource bundle. The locale used will be the locale specified by JiveGlobals.getLocale().

By default, this loads the resource bundle with the basename of 'jive_forums_i18n' to preserve backwards compatibility. To override this, call ResourceBundle.getBundle(String) and specify the name of bundle to load. Then call the getString() method on returned bundle object.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
Returns:
the localized string.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.lang.String pluginName)
Returns an internationalized string loaded from a resource bundle from the passed in plugin. If the plugin name is null, the key will be looked up using the standard resource bundle.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
pluginName - the name of the plugin to load the require resource bundle from.
Returns:
the localized string.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.lang.String pluginName,
                                                  java.util.List arguments)
Returns an internationalized string loaded from a resource bundle from the passed in plugin. If the plugin name is null, the key will be looked up using the standard resource bundle.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
pluginName - the name of the plugin to load the require resource bundle from.
arguments - a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.
Returns:
the localized string.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.util.Locale locale,
                                                  java.util.List arguments,
                                                  java.util.ResourceBundle bundle)
Returns an internationalized string loaded from a resource bundle using the passed in Locale substituting the passed in arguments. Substitution is handled using the MessageFormat class.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
locale - the locale to use for retrieving the appropriate locale-specific string.
arguments - a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.
Returns:
the localized string.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.util.Locale locale)
Returns an internationalized string loaded from a resource bundle using the passed in Locale.

By default, this loads the resource bundle with the basename of 'jive_forums_i18n' to preserve backwards compatibility. To override this, call ResourceBundle.getBundle(String,Locale) and specify the name of bundle to load. Then call the getString() method on returned bundle object.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
locale - the locale to use for retrieving the appropriate locale-specific string.
Returns:
the localized string.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.util.List arguments)
Returns an internationalized string loaded from a resource bundle using the locale specified by JiveGlobals.getLocale() substituting the passed in arguments. Substitution is handled using the MessageFormat class.

By default, this loads the resource bundle with the basename of 'jive_forums_i18n' to preserve backwards compatibility. To override this, call ResourceBundle.getBundle(String,Locale) and specify the name of bundle to load. Then call the getString() method on returned bundle object. To handle the argument list, see the MessageFormat class.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
arguments - a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.
Returns:
the localized string.

getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String key,
                                                  java.util.Locale locale,
                                                  java.util.List arguments)
Returns an internationalized string loaded from a resource bundle using the passed in Locale substituting the passed in arguments. Substitution is handled using the MessageFormat class.

Parameters:
key - the key to use for retrieving the string from the appropriate resource bundle.
locale - the locale to use for retrieving the appropriate locale-specific string.
arguments - a list of objects to use which are formatted, then inserted into the pattern at the appropriate places.
Returns:
the localized string.

getLocalizedNumber

public static java.lang.String getLocalizedNumber(long number)
Returns a number formatted to the rules of the default Jive Forums locale. If the number passed in is 1238462 then a formatted number might look like "1,238,462".

Parameters:
number - the number to format.
Returns:
a String representation of the formatted number.

getLocalizedNumber

public static java.lang.String getLocalizedNumber(long number,
                                                  java.util.Locale locale)
Returns a number formatted to the rules of the given locale. If the number passed in is 1238462 then a formatted number might look like "1,238,462".

Parameters:
number - the number to format.
locale - the locale to use when formatting this number.
Returns:
a String representation of the formatted number.

getLocalizedNumber

public static java.lang.String getLocalizedNumber(double number)
Returns a number formatted to the rules of the default Jive Forums locale. If the number passed in is 1238462.03 then a formatted number might look like "1,238,462.03".

Parameters:
number - the number to format.
Returns:
a String representation of the formatted number.

getLocalizedNumber

public static java.lang.String getLocalizedNumber(double number,
                                                  java.util.Locale locale)
Returns a number formatted to the rules of the given locale. If the number passed in is 1238462.03 then a formatted number might look like "1,238,462.03".

Parameters:
number - the number to format.
locale - the locale to use when formatting this number.
Returns:
a String representation of the formatted number.

getResourceBundle

public static java.util.ResourceBundle getResourceBundle(java.lang.String baseName,
                                                         java.util.Locale locale)
Deprecated. Use just ResourceBundle.getBundle(String,Locale) instead.

Returns the specified resource bundle, which is a properties file that aids in localization of skins. This method is handy since it uses the class loader that other Jive classes are loaded from (hence, it can load bundles that are stored in any of the Jive JARs).

Parameters:
baseName - the name of the resource bundle to load.
locale - the desired Locale.
Returns:
the specified resource bundle, if it exists.

getResourceBundle

public static java.util.ResourceBundle getResourceBundle(java.lang.String baseName)
Wrapper method to get a resource bundle for the default locale. This wrapper is basically only useful because it catches the MissingResourceException that could possibly be thrown and logs it.

Parameters:
baseName - the base name of the resource bundle to lookup
Returns:
the resource bundle, or null if it was not found.

getDateFormatPattern

public static java.lang.String getDateFormatPattern(java.util.Locale locale)
Returns the DateFormat pattern for the given locale

Parameters:
locale - Java locale for which to lookup the DateFormat pattern
Returns:
String DateFormat pattern DateFormat

getShortDateFormatPattern

public static java.lang.String getShortDateFormatPattern(java.util.Locale locale)

getLocaleAlignment

public static java.lang.String getLocaleAlignment(java.util.Locale locale)
Returns the alignment direction for a given locale.

Parameters:
locale - the locale to check the all
Returns:
left for RTL and right for LTR

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.