org.spiffyui.server.i18n
Class BasicBestLocaleMatcher

java.lang.Object
  extended by org.spiffyui.server.i18n.BasicBestLocaleMatcher

public final class BasicBestLocaleMatcher
extends java.lang.Object

A basic implementation for matching a list of locales from the request and finding a best corresponding supported locale.


Method Summary
static java.util.Locale getBestMatchLocale(HttpServletRequest request, HttpServletResponse response, java.util.List<java.util.Locale> supportedLocales)
          Return the best match locale by getting a list of requested locales from the request and matching it to the provided list of supported locales.
static java.util.Locale getBestMatchLocale(HttpServletRequest request, HttpServletResponse response, ServletContext context)
          Return the best match locale for JavaScript dates by getting a list of requested locales from the request.
static java.util.Locale getLocaleFromCode(java.lang.String localeCode)
          Creates a Locale object from the xml:lang attribute format or the Java standard (as returned by Locale.toString()) for specifying locales.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBestMatchLocale

public static java.util.Locale getBestMatchLocale(HttpServletRequest request,
                                                  HttpServletResponse response,
                                                  ServletContext context)

Return the best match locale for JavaScript dates by getting a list of requested locales from the request.

This methods builds the list of supported locales based on the JavaScript date and time localization classes included in the Spiffy UI framework. It will loop through the list of locales and attempt to match first exactly, then by language and country, then by country. If no match is found it will default to English.

This method should almost never be called by classes outside of the Spiffy UI framework.

If your application supports a different list of locales, and most of them do, then you should call the version of this method passing a list of supported locales.

Parameters:
request - - the HttpServletRequest
response - - the HttpServletResponse
context - - the ServletContext
Returns:
the best match Locale

getBestMatchLocale

public static java.util.Locale getBestMatchLocale(HttpServletRequest request,
                                                  HttpServletResponse response,
                                                  java.util.List<java.util.Locale> supportedLocales)

Return the best match locale by getting a list of requested locales from the request and matching it to the provided list of supported locales.

This method will loop through the list of locales and attempt to match first exactly, then by language and country, then by country. If no match is found it will default to English.

Parameters:
request - - the HttpServletRequest
response - - the HttpServletResponse
supportedLocales - - the list of available locales to choose from
Returns:
the best match Locale

getLocaleFromCode

public static java.util.Locale getLocaleFromCode(java.lang.String localeCode)
Creates a Locale object from the xml:lang attribute format or the Java standard (as returned by Locale.toString()) for specifying locales.

Parameters:
localeCode - String code that conforms to the RFC 3066 standard or the Java standard (as returned by Locale.toString()).
Returns:
Locale object converted from the localeCode passed in.