java.lang.Object
org.tentackle.common.LocaleProvider
A provider for the Locale.
- Author:
- harald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAsserts that a thread-local Locale is set.Gets the locale used by the current thread.Gets the effective locale for the current locale.getEffectiveLocale(Locale locale) Gets the effective locale.
This is application-specific and allows narrowing the locales to the effectively supported locales.static LocaleProviderThe singleton.Gets the locale.voidsetCurrentLocale(Locale locale) Sets the session used by the current thread.
The session is stored asThreadLocal.
-
Constructor Details
-
LocaleProvider
public LocaleProvider()
-
-
Method Details
-
getInstance
The singleton.- Returns:
- the singleton
-
getCurrentLocale
Gets the locale used by the current thread.- Returns:
- the locale, null if no thread-local Locale set
-
getLocale
Gets the locale.If there is no thread-local Locale, the default Locale is returned.
- Returns:
- the current locale, never null
-
setCurrentLocale
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
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
Gets the effective locale for the current locale.- Returns:
- the mapped locale
-