public class Locale extends Object
Locale.java
is a utility that provides
functionality for applications and services to internationalize their
messages.Constructor and Description |
---|
Locale() |
Modifier and Type | Method and Description |
---|---|
static String |
convertDateString(String srcDateString,
Locale srcLocale,
Locale dstLocale)
Converts date string from source locale to destination locale
|
static String |
formatMessage(String formatStr,
Object obj1)
Formats messages using
MessageFormat Class. |
static String |
formatMessage(String formatStr,
Object[] objs)
Formats to format messages using
MessageFormat Class. |
static String |
getDateString(Date date,
Locale locale)
Gets date string from date with specified locale.
|
static Locale |
getDefaultLocale()
Gets the default locale
|
static ResourceBundle |
getInstallResourceBundle(String bundle)
Gets the default install resource bundle for the default locale
|
static 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
locale
|
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
|
static String |
getNormalizedDateString(Date date)
Converts the Date object into
ISO-8601 format
yyyy/MM/dd HH:mm like 2002/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,
Debug debug)
Gets the localized string for the specified key
|
static String |
getString(ResourceBundle rb,
String resource,
Debug debug,
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,
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 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 in
ISO-8601
format. |
static String |
URLDecodeField(String strIn,
Debug debug) |
static String |
URLDecodeField(String strIn,
String charset,
Debug debug) |
static String |
URLEncodeField(String input,
String enc)
This method is replacement function for
URLEncoder
Function URL encoder function converts input string into
URLEncoded byte stream after converting Unicode string
into bytes using native encoding. |
static String |
URLEncodeField(String input,
String enc,
Debug debug)
This method is replacement function for
URLEncoder Function
URL encoder function converts input string into URLencoded
byte stream after converting Unicode string into bytes using native
encoding. |
public static void main(String[] args)
public static Locale getLocale(String stringformat)
stringformat
- String representation of the locale. Examples:
en_US, en_UK, ja_JP
.java.util.locale
object.public static String getLocaleStringFromAcceptLangHeader(String langstr)
langstr
- Value from Accept-Language header of HTTPen_US, fr
public static Locale getLocaleObjFromAcceptLangHeader(String langStr)
langStr
- Value from Accept-Language header of HTTPen_US, fr
.public static ResourceBundle getResourceBundle(String bundle, String stringformat)
bundle
- Localized property file name.stringformat
- String representation of the locale.java.util.ResourceBundle
object.protected static ResourceBundle getResourceBundle(String bundle)
public static ResourceBundle getInstallResourceBundle(String bundle)
bundle
- Localized property file namepublic static Locale getDefaultLocale()
public static String formatMessage(String formatStr, Object obj1)
MessageFormat
Class.formatStr
- string format template.obj1
- object to be added to the template.public static String formatMessage(String formatStr, Object[] objs)
MessageFormat
Class.
given params to format them withformatStr
- string format template.objs
- objects to be added to the template.public static Date parseNormalizedDateString(String dateString)
ISO-8601
format. OpenAM stores date in ISO-8601
format
yyyy/MM/yy hh:mm
dateString
- in the format 2002/12/31 23:59
.public static Date parseDateString(String dateString, Locale locale, String dateSyntax)
dateString
- date stringlocale
- Locale objectdateSyntax
- syntax of the date string.dateString
matches the
dateSyntax
. If the syntax or date string is
empty, or the string does not match the syntax, null will be
returned.public static Date parseDateString(String dateString, Locale locale)
dateString
- date stringlocale
- Locale objectpublic static String getNormalizedDateString(Date date)
ISO-8601
format
yyyy/MM/dd HH:mm
like 2002/12/23 20:40
.date
- to be normalized.ISO8601
format
2002/12/31 11:59
.public static String getDateString(Date date, Locale locale)
date
- Date objectlocale
- Locale objectpublic static String convertDateString(String srcDateString, Locale srcLocale, Locale dstLocale)
srcDateString
- source date stringsrcLocale
- source Locale objectdstLocale
- destination Locale objectpublic static String getString(ResourceBundle rb, String resource, Object[] params)
rb
- resource bundle.resource
- the specified key.params
- formatting done as per these parameters.public static String getString(ResourceBundle rb, String resource, ResourceBundle defaultRb, Object[] params)
rb
- resource bundle.resource
- the specified key.defaultRb
- Default resource bundle.params
- formatting done as per these parameters.public static String getString(ResourceBundle rb, String resource, Debug debug)
rb
- resource bundle.resource
- the specified key.debug
- the debug instance to which the debug messages need to be
printed.public static String getString(ResourceBundle rb, String resource, Debug debug, ResourceBundle defaultRb)
rb
- resource bundle.resource
- the specified key.debug
- the debug instance to which the debug messages need to be
printed.defaultRb
- Default resource bundle.public static String getString(ResourceBundle rb, String resource)
rb
- resource bundle.resource
- the specified key.public static String getString(ResourceBundle rb, String resource, ResourceBundle defaultRb)
rb
- resource bundle.resource
- the specified key.defaultRb
- Default resource bundle.public static String URLEncodeField(String input, String enc) throws UnsupportedEncodingException
URLEncoder
Function URL encoder function converts input string into
URLEncoded
byte stream after converting Unicode string
into bytes using native encoding. The URLEncoder
does not
work for OpenAM if default encoding is not
UTF-8
, hence this method was written.input
- the input string.enc
- the encoding format.UnsupportedEncodingException
- If the encoding is not supported.public static String URLEncodeField(String input, String enc, Debug debug)
URLEncoder
Function
URL encoder function converts input string into URLencoded
byte stream after converting Unicode string into bytes using native
encoding. The URLEncoder
does not work for Sun Java System
OpenAM if default encoding is not UTF-8
, hence this
method was written.input
- the input stringenc
- the encoding formatdebug
- the debug instance to which debug messages need to
be printedCopyright © 2010-2018, ForgeRock All Rights Reserved.