pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.service.request
Class LocaleManager

java.lang.Object
  extended by org.torweg.pulse.service.request.LocaleManager
All Implemented Interfaces:
java.io.Serializable

public class LocaleManager
extends java.lang.Object
implements java.io.Serializable

manages the registered locales and maps user locales to the best matching registered locale.

Version:
$Revision: 1726 $
Author:
Thomas Weber
See Also:
Serialized Form

Constructor Summary
protected LocaleManager(ServiceRequestImplConfig conf)
          creates a new LocaleManager.
 
Method Summary
 java.util.Locale findBestMatchingLocale(java.util.Locale locale, ServiceRequest request)
          returns the best matching locale for the given parameters.
 java.util.Locale findBestMatchingLocale(java.lang.String localeString, ServiceRequest request)
          returns the best matching locale for the given parameters.
 java.util.Locale findLocaleByGivenValues(java.lang.String language, java.lang.String country, java.lang.String variant)
          tries to find a known Locale which best matches the given values for language, country and variant.
 java.util.Locale getDefaultLocale()
          returns the default locale, if set.
static LocaleManager getInstance()
          returns the LocaleManager instance.
 java.util.Collection<Locale> getLocales()
          returns the configured locales.
protected  boolean hasDefault()
          returns whether the LocaleManager has a default locale.
static java.util.Locale localeToLocale(Locale l)
          builds a java.util.Locale matching an org.torweg.pulse.service.Locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocaleManager

protected LocaleManager(ServiceRequestImplConfig conf)
creates a new LocaleManager.

Parameters:
conf - the configuration
Method Detail

getLocales

public final java.util.Collection<Locale> getLocales()
returns the configured locales.

Returns:
the configured locales

getDefaultLocale

public final java.util.Locale getDefaultLocale()
returns the default locale, if set.

Returns:
the default locale, if set

findBestMatchingLocale

public final java.util.Locale findBestMatchingLocale(java.lang.String localeString, ServiceRequest request)
returns the best matching locale for the given parameters.

Parameters:
localeString - the preferred locale (may be null)
request - the current request (may be null)
Returns:
the best matching locale

findBestMatchingLocale

public final java.util.Locale findBestMatchingLocale(java.util.Locale locale, ServiceRequest request)
returns the best matching locale for the given parameters.

Parameters:
locale - the preferred locale (may be null)
request - the current request (may be null)
Returns:
the best matching locale

findLocaleByGivenValues

public final java.util.Locale findLocaleByGivenValues(java.lang.String language,
                                                      java.lang.String country,
                                                      java.lang.String variant)
tries to find a known Locale which best matches the given values for language, country and variant.

Parameters:
language - the given language
country - the given country
variant - the given variant
Returns:
a matching Locale or null, if no matching Locale could be found

localeToLocale

public static final java.util.Locale localeToLocale(Locale l)
builds a java.util.Locale matching an org.torweg.pulse.service.Locale.

Parameters:
l - the org.torweg.pulse.service.Locale
Returns:
the java.util.Locale

getInstance

public static final LocaleManager getInstance()
returns the LocaleManager instance.

Returns:
the LocaleManager

hasDefault

protected final boolean hasDefault()
returns whether the LocaleManager has a default locale.

Returns:
whether the LocaleManager has a default locale