Package com.sun.identity.common
Class ISLocaleContext
- java.lang.Object
-
- com.sun.identity.common.ISLocaleContext
-
public class ISLocaleContext extends Object
Sets the locale suitable for the given situation. Each response to end-user must be in a well defined locale. Even if the user has not logged in, OpenAM should respond in a locale. Hence OpenAM consults various parameter to find out the locale for any given response. The order and priority of the locale setting is as follows: Priority 0 - OS_LOCALE - value returned by java.util.Locale.getDefault() Priority 1 - PLATFORM_LOCALE - iplanet-am-platform-locale attribute value in iPlanetAMPlatform Service - Global value for entire OpenAM instance Priority 2 - AUTH-LOCALE - iplanet-am-auth-locale attribute value in iPlantAMAuth service - Org specific locale value Priority 3 - USER_LOCALE - preferredlocale - iPlanetAMUser service and it can be configured per org and user level Priority 4 - HTTP_HEADER_LOCALE - Accept-Language header of HTTP Request Priority 5 - URL_LOCALE - locale value passed as URL parameter Usage: There are three key parameters in the request that can decide the locale of a given request. This class expects application to pass all these parameters whenever they are available and use getLocale method to get the current locale. The four key parameters are: - HttpServletRequest - to process Accept-language and URL parameter locale. - HttpContext - to process Accept-language and URL parameter locale. - UserPreferredLocale - user attribute, if user has sucessful login. - OrgDN - DN of the org in which the user resides- it can take take core auth locale of this org.ISLocaleContext is = new ISLocaleContext(); is.setOrgLocale ("o=isp,dc=iplanet,dc=com"); // sets the org locale is.setLocale(req); // get locale from accept-lang,locale param etc // if user logs in is.setUserLocale (loc);
For your response, get the locale using:is.getLocale();
Locale with highest priority takes precedence over lower priority.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CORE_AUTH_LOCALE
static int
HTTP_HEADER_LOCALE
static int
OS_LOCALE
static int
PLATFORM_LOCALE
static int
URL_LOCALE
static int
USER_PREFERRED_LOCALE
-
Constructor Summary
Constructors Constructor Description ISLocaleContext()
InitializesISLocaleContext
to default level It examines OS_LOCALE, PLATFORM_LOCALE, AUTH_LOCALE and initialize them based on their priorityISLocaleContext(String orgDN)
InitializeISLocaleContext
for a given Org It can look into orgs core auth locale value and set the value if it is available
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getJavaCharset()
get java charset to be used for current request This class detectes clientType using Http-Accept-Lang header You should have used setLocale(HttpServletRequest req) before calling this method.Locale
getLocale()
Returns Locale value that has got highest prioirtyint
getLocaleLevel()
get current priority level of localeString
getMIMECharset()
get mime charset to be used for current request This class detectes clientType using Http-Accept-Lang header You should have used setLocale(HttpServletRequest req) before calling this method.void
setLocale(int level, String loc)
Set locale to given level.void
setLocale(int level, Locale loc)
Set locale to given level.void
setLocale(jakarta.servlet.http.HttpServletRequest request)
Set locale based on HTTP Servlet Request.void
setLocale(org.forgerock.json.resource.http.HttpContext context)
Returns the locale based on the Http Context supplied.void
setOrgLocale(String orgDN)
Update locale context based on org locale user locale takes precedence over this localevoid
setUserLocale(String loc)
Set the current locale level toUSER_LOCALE
and sets the value the locale value is separated by underscore characterex:en_US
.void
setUserLocale(Locale loc)
Set the current locale level toUSER_LOCALE
and sets the value if current locale level is greater thanUSER_LOCALE
, this setting will be ignored.
-
-
-
Field Detail
-
OS_LOCALE
public static final int OS_LOCALE
- See Also:
- Constant Field Values
-
PLATFORM_LOCALE
public static final int PLATFORM_LOCALE
- See Also:
- Constant Field Values
-
CORE_AUTH_LOCALE
public static final int CORE_AUTH_LOCALE
- See Also:
- Constant Field Values
-
USER_PREFERRED_LOCALE
public static final int USER_PREFERRED_LOCALE
- See Also:
- Constant Field Values
-
HTTP_HEADER_LOCALE
public static final int HTTP_HEADER_LOCALE
- See Also:
- Constant Field Values
-
URL_LOCALE
public static final int URL_LOCALE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ISLocaleContext
public ISLocaleContext()
InitializesISLocaleContext
to default level It examines OS_LOCALE, PLATFORM_LOCALE, AUTH_LOCALE and initialize them based on their priority
-
ISLocaleContext
public ISLocaleContext(String orgDN)
InitializeISLocaleContext
for a given Org It can look into orgs core auth locale value and set the value if it is available
-
-
Method Detail
-
setLocale
public void setLocale(int level, String loc)
Set locale to given level.- Parameters:
level
- Possible values areOS_LOCALE,PLATFORM_LOCALE
AUTH_LOCALE
,ACCEPT_LOCALE
,USER_PREFERRED_LOCALE
,URL_LOCALE
.loc
- Locale value in string exampleen
,ja_JP. Warning: This method overrides priority lookup mechanism.
-
setLocale
public void setLocale(int level, Locale loc)
Set locale to given level.- Parameters:
level
- Possible values areOS_LOCALE,PLATFORM_LOCALE
AUTH_LOCALE
,ACCEPT_LOCALE
,USER_PREFERRED_LOCALE
,URL_LOCALE
.loc
- Locale value.
-
setLocale
public void setLocale(org.forgerock.json.resource.http.HttpContext context)
Returns the locale based on the Http Context supplied.- Parameters:
context
- TheHttpContext
of the request
-
setLocale
public void setLocale(jakarta.servlet.http.HttpServletRequest request)
Set locale based on HTTP Servlet Request.- Parameters:
request
- Analyze HttpHeader and look for URL parameter called locale . If it is set, it takes high precedence. Else look foraccept-language
header and set the locale if it is present.
-
setUserLocale
public void setUserLocale(Locale loc)
Set the current locale level toUSER_LOCALE
and sets the value if current locale level is greater thanUSER_LOCALE
, this setting will be ignored.- Parameters:
loc
- Locale.
-
setUserLocale
public void setUserLocale(String loc)
Set the current locale level toUSER_LOCALE
and sets the value the locale value is separated by underscore characterex:en_US
.- Parameters:
loc
- Locale.
-
getLocale
public Locale getLocale()
Returns Locale value that has got highest prioirty- Returns:
- locale.
-
getLocaleLevel
public int getLocaleLevel()
get current priority level of locale- Returns:
- localeLevel
-
setOrgLocale
public void setOrgLocale(String orgDN)
Update locale context based on org locale user locale takes precedence over this locale- Parameters:
orgDN
- - Distinguished Name of Organization
-
getMIMECharset
public String getMIMECharset()
get mime charset to be used for current request This class detectes clientType using Http-Accept-Lang header You should have used setLocale(HttpServletRequest req) before calling this method. Otherwise it will use default clientType configured by client detection service All http headers should have mime charset. For example use this API whenever you set http header using setContentType()- Returns:
- mime charset to be used for current request
-
getJavaCharset
public String getJavaCharset()
get java charset to be used for current request This class detectes clientType using Http-Accept-Lang header You should have used setLocale(HttpServletRequest req) before calling this method. Otherwise it will use default clientType configured by client detection service. Most of the cases Javas codeset converter understands MIME charset names withsome exceptions. It is recommended to use this API to set form hidden field such as gx_charset- Returns:
- java charset to be used for current request
-
-