- java.lang.Object
-
- org.tentackle.common.LocaleProvider
-
@Service(LocaleProvider.class) public class LocaleProvider extends java.lang.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.java.util.LocalegetCurrentLocale()Gets the locale used by the current thread.java.util.LocalegetEffectiveLocale()Gets the effective locale for the current locale.java.util.LocalegetEffectiveLocale(java.util.Locale locale)Gets the effective locale.
This is application-specific and allows narrowing the locales to the effectively supported locales.static LocaleProvidergetInstance()The singleton.java.util.LocalegetLocale()Gets the locale.voidsetCurrentLocale(java.util.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 java.util.Locale getCurrentLocale()
Gets the locale used by the current thread.- Returns:
- the locale, null if no thread-local Locale set
-
getLocale
public java.util.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(java.util.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 java.util.Locale getEffectiveLocale(java.util.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 java.util.Locale getEffectiveLocale()
Gets the effective locale for the current locale.- Returns:
- the mapped locale
-
-