Package com.sun.identity.shared.locale
Class Locale
- java.lang.Object
-
- com.sun.identity.shared.locale.Locale
-
@SupportedAll public class Locale extends Object
This classLocale.java
is a utility that provides functionality for applications and services to internationalize their messages.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
DATE_SYNTAX
protected static String
USER_PROPERTIES
-
Constructor Summary
Constructors Constructor Description Locale()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
convertDateString(String srcDateString, Locale srcLocale, Locale dstLocale)
Converts date string from source locale to destination localestatic String
formatMessage(String formatStr, Object obj1)
Formats messages usingMessageFormat
Class.static String
formatMessage(String formatStr, Object[] objs)
Formats to format messages usingMessageFormat
Class.static String
getDateString(Date date, Locale locale)
Gets date string from date with specified locale.static Locale
getDefaultLocale()
Gets the default localestatic ResourceBundle
getInstallResourceBundle(String bundle)
Gets the default install resource bundle for the default localestatic Locale
getLocale(String stringformat)
Gets the locale object for the specified localized string format.static Locale
getLocaleObjFromAcceptLangHeader(String langStr)
Gets locale from accept-language header HTTP accept language header can have more than one language in the header, we honor the first language as localestatic String
getLocaleStringFromAcceptLangHeader(String langstr)
Returns locale from accept-language header HTTP accept language header can have more than one language in the header, we honor the first language as localestatic String
getNormalizedDateString(Date date)
Converts the Date object intoISO-8601
formatyyyy/MM/dd HH:mm
like2002/12/23 20:40
.protected static ResourceBundle
getResourceBundle(String bundle)
static ResourceBundle
getResourceBundle(String bundle, String stringformat)
Gets the resource bundle corresponding to the specified locale and the localized property file name.static String
getString(ResourceBundle rb, String resource)
Gets the localized string for the specified key.static String
getString(ResourceBundle rb, String resource, Object[] params)
Gets the localized string for the specified key formatted as per passed parameters.static String
getString(ResourceBundle rb, String resource, ResourceBundle defaultRb)
Gets the localized string for the specified key from the specified Resource or from the specified default resource.static String
getString(ResourceBundle rb, String resource, ResourceBundle defaultRb, Object[] params)
Gets the localized string for the specified key from the specified Resource or from the specified default resource formatted as per provided parameters.static String
getString(ResourceBundle rb, String resource, org.slf4j.Logger debug, ResourceBundle defaultRb)
Gets the localized string for the specified key from the specified Resource or from the specified default resourcestatic void
main(String[] args)
static Date
parseDateString(String dateString, Locale locale)
Gets Date object from date string with specified locale.static Date
parseDateString(String dateString, Locale locale, String dateSyntax)
Gets Date object from date string with specified locale.static Date
parseNormalizedDateString(String dateString)
Returns the Date object from the date string inISO-8601
format.static String
URLDecodeField(String strIn, String charset, org.slf4j.Logger debug)
static String
URLDecodeField(String strIn, org.slf4j.Logger debug)
static String
URLEncodeField(String input, String enc)
This method is replacement function forURLEncoder
Function URL encoder function converts input string intoURLEncoded
byte stream after converting Unicode string into bytes using native encoding.static String
URLEncodeField(String input, String enc, org.slf4j.Logger debug)
This method is replacement function forURLEncoder
Function URL encoder function converts input string intoURLencoded
byte stream after converting Unicode string into bytes using native encoding.
-
-
-
Field Detail
-
USER_PROPERTIES
protected static final String USER_PROPERTIES
- See Also:
- Constant Field Values
-
DATE_SYNTAX
protected static final String DATE_SYNTAX
- See Also:
- Constant Field Values
-
-
Method Detail
-
main
public static void main(String[] args)
-
getLocale
public static Locale getLocale(String stringformat)
Gets the locale object for the specified localized string format.- Parameters:
stringformat
- String representation of the locale. Examples:en_US, en_UK, ja_JP
.- Returns:
- the
java.util.locale
object.
-
getLocaleStringFromAcceptLangHeader
public static String getLocaleStringFromAcceptLangHeader(String langstr)
Returns locale from accept-language header HTTP accept language header can have more than one language in the header, we honor the first language as locale- Parameters:
langstr
- Value from Accept-Language header of HTTP- Returns:
- locale string in this format
en_US, fr
-
getLocaleObjFromAcceptLangHeader
public static Locale getLocaleObjFromAcceptLangHeader(String langStr)
Gets locale from accept-language header HTTP accept language header can have more than one language in the header, we honor the first language as locale- Parameters:
langStr
- Value from Accept-Language header of HTTP- Returns:
- locale string in this format
en_US, fr
.
-
getResourceBundle
public static ResourceBundle getResourceBundle(String bundle, String stringformat)
Gets the resource bundle corresponding to the specified locale and the localized property file name.- Parameters:
bundle
- Localized property file name.stringformat
- String representation of the locale.- Returns:
java.util.ResourceBundle
object.
-
getResourceBundle
protected static ResourceBundle getResourceBundle(String bundle)
-
getInstallResourceBundle
public static ResourceBundle getInstallResourceBundle(String bundle)
Gets the default install resource bundle for the default locale- Parameters:
bundle
- Localized property file name- Returns:
- the install resource bundle object
-
getDefaultLocale
public static Locale getDefaultLocale()
Gets the default locale- Returns:
- the default Locale object
-
formatMessage
public static String formatMessage(String formatStr, Object obj1)
Formats messages usingMessageFormat
Class.- Parameters:
formatStr
- string format template.obj1
- object to be added to the template.- Returns:
- formatted message.
-
formatMessage
public static String formatMessage(String formatStr, Object[] objs)
Formats to format messages usingMessageFormat
Class. given params to format them with- Parameters:
formatStr
- string format template.objs
- objects to be added to the template.- Returns:
- formatted message.
-
parseNormalizedDateString
public static Date parseNormalizedDateString(String dateString)
Returns the Date object from the date string inISO-8601
format. OpenAM stores date inISO-8601
formatyyyy/MM/yy hh:mm
- Parameters:
dateString
- in the format2002/12/31 23:59
.- Returns:
- Date object
-
parseDateString
public static Date parseDateString(String dateString, Locale locale, String dateSyntax)
Gets Date object from date string with specified locale.- Parameters:
dateString
- date stringlocale
- Locale objectdateSyntax
- syntax of the date string.- Returns:
- Date object returned if
dateString
matches thedateSyntax
. If the syntax or date string is empty, or the string does not match the syntax, null will be returned.
-
parseDateString
public static Date parseDateString(String dateString, Locale locale)
Gets Date object from date string with specified locale. Syntax of date string is defined in amUser_<locale> properties file.- Parameters:
dateString
- date stringlocale
- Locale object- Returns:
- Date object. null will be returned if error happens
-
getNormalizedDateString
public static String getNormalizedDateString(Date date)
Converts the Date object intoISO-8601
formatyyyy/MM/dd HH:mm
like2002/12/23 20:40
.- Parameters:
date
- to be normalized.- Returns:
- date in
ISO8601
format2002/12/31 11:59
.
-
getDateString
public static String getDateString(Date date, Locale locale)
Gets date string from date with specified locale.- Parameters:
date
- Date objectlocale
- Locale object- Returns:
- date string. null will be returned if error happens
-
convertDateString
public static String convertDateString(String srcDateString, Locale srcLocale, Locale dstLocale)
Converts date string from source locale to destination locale- Parameters:
srcDateString
- source date stringsrcLocale
- source Locale objectdstLocale
- destination Locale object- Returns:
- converted date string. null will be returned if error happens
-
getString
public static String getString(ResourceBundle rb, String resource, Object[] params)
Gets the localized string for the specified key formatted as per passed parameters.- Parameters:
rb
- resource bundle.resource
- the specified key.params
- formatting done as per these parameters.- Returns:
- the localized string representation formatted as per passed parameters.
-
getString
public static String getString(ResourceBundle rb, String resource, ResourceBundle defaultRb, Object[] params)
Gets the localized string for the specified key from the specified Resource or from the specified default resource formatted as per provided parameters.- Parameters:
rb
- resource bundle.resource
- the specified key.defaultRb
- Default resource bundle.params
- formatting done as per these parameters.- Returns:
- the localized string representation formatted as per passed parameters.
-
getString
public static String getString(ResourceBundle rb, String resource, org.slf4j.Logger debug, ResourceBundle defaultRb)
Gets the localized string for the specified key from the specified Resource or from the specified default resource- Parameters:
rb
- resource bundle.resource
- the specified key.debug
- the debug instance to which the debug messages need to be printed.defaultRb
- Default resource bundle.- Returns:
- the localized string representation
-
getString
public static String getString(ResourceBundle rb, String resource)
Gets the localized string for the specified key.- Parameters:
rb
- resource bundle.resource
- the specified key.- Returns:
- the localized string representation
-
getString
public static String getString(ResourceBundle rb, String resource, ResourceBundle defaultRb)
Gets the localized string for the specified key from the specified Resource or from the specified default resource.- Parameters:
rb
- resource bundle.resource
- the specified key.defaultRb
- Default resource bundle.- Returns:
- the localized string representation
-
URLEncodeField
public static String URLEncodeField(String input, String enc) throws UnsupportedEncodingException
This method is replacement function forURLEncoder
Function URL encoder function converts input string intoURLEncoded
byte stream after converting Unicode string into bytes using native encoding. TheURLEncoder
does not work for OpenAM if default encoding is notUTF-8
, hence this method was written.- Parameters:
input
- the input string.enc
- the encoding format.- Returns:
- the encoded string.
- Throws:
UnsupportedEncodingException
- If the encoding is not supported.
-
URLEncodeField
public static String URLEncodeField(String input, String enc, org.slf4j.Logger debug)
This method is replacement function forURLEncoder
Function URL encoder function converts input string intoURLencoded
byte stream after converting Unicode string into bytes using native encoding. TheURLEncoder
does not work for Sun Java System OpenAM if default encoding is notUTF-8
, hence this method was written.- Parameters:
input
- the input stringenc
- the encoding formatdebug
- the debug instance to which debug messages need to be printed- Returns:
- the encoded string
-
-