- java.lang.Object
-
- org.tentackle.common.LocaleProvider
-
@Service(LocaleProvider.class) public class LocaleProvider extends Object
A provider for the Locale.- Author:
- harald
-
-
Constructor Summary
Constructors Constructor Description LocaleProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertCurrentLocaleValid()Asserts that a thread local Locale is set.LocalegetCurrentLocale()Gets the locale used by the current thread.LocalegetEffectiveLocale()Gets the effective locale for the current locale.LocalegetEffectiveLocale(Locale locale)Gets the effective locale.
This is application-specific and allows narrowing the locales to the effectively supported locales.static LocaleProvidergetInstance()The singleton.LocalegetLocale()Gets the locale.voidsetCurrentLocale(Locale locale)Sets the session used by the current thread.
The session is stored asThreadLocal.
-
-
-
Method Detail
-
getInstance
public static LocaleProvider getInstance()
The singleton.- Returns:
- the singleton
-
getCurrentLocale
public Locale getCurrentLocale()
Gets the locale used by the current thread.- Returns:
- the locale, null if no thread-local Locale set
-
getLocale
public Locale getLocale()
Gets the locale.If there is no thread-local Locale, the default Locale is returned.
- Returns:
- the current locale, never null
-
setCurrentLocale
public void setCurrentLocale(Locale locale)
Sets the session used by the current thread.
The session is stored asThreadLocal.- Parameters:
locale- the locale
-
assertCurrentLocaleValid
public void assertCurrentLocaleValid()
Asserts that a thread local Locale is set.- Throws:
TentackleRuntimeException- if thread-local locale is null
-
getEffectiveLocale
public Locale getEffectiveLocale(Locale locale)
Gets the effective locale.
This is application-specific and allows narrowing the locales to the effectively supported locales. If, for example, the default language in all resource bundles is "en" and there is a second language "de", then all locales beginning with "de" will map to "de" and all others to "en".- Parameters:
locale- the requested locale- Returns:
- the mapped locale
-
getEffectiveLocale
public Locale getEffectiveLocale()
Gets the effective locale for the current locale.- Returns:
- the mapped locale
-
-