public class Localizer extends Object
Localizer class is an all-in-one class that provides
access to all necessary globalization services.
The Localizer instance is derived from the ServletHelper.getLocalizerInstance(HttpServletRequest) method that is
associated with the current user locale. You may change the current locale on
each page, therefore, the scope of Localizer
is page scope.
By using the Localizer class, you do not have to manually deal
with the locale-sensitive operations. Instead, all information can be
obtained from one Localizer object. The following
functionalities of classes are included as part of Localizer's services:
oracle.i18n.text.OraDateFormat
oracle.i18n.text.OraNumberFormat
oracle.i18n.text.OraCollator
oracle.i18n.util.OraLocaleInfo
oracle.i18n.util.LocaleMapper
Note: Strings returned by many Localizer methods, such as
formatted dates and locale-specific currency symbols, depend on locale data
that may be provided by users through URLs or form input. For example, the
locale source class UserInput
provides various datetime format patterns and the ISO currency abbreviation
retrieved from a page URL. A datetime format pattern may include
double-quoted literal strings with arbitrary contents. To prevent cross-site
script injection attacks, strings returned by Localizer methods
must be properly escaped before being displayed as part of an HTML page, for
example by applying the
CharEntityReference.escape(String) method.
| Modifier and Type | Method and Description |
|---|---|
int |
compareString(String source,
String target)
Compares two strings using the current linguistic sort/collator object.
|
int |
compareStringWithDefaultCollator(String source,
String target)
Compares two strings using the default linguistic sort/collator object.
|
String |
decodeURL(String source)
Decodes a URL string based on the current user character set using
the character encoding of the page.
|
String |
encodeURL(String source)
Encodes a URL string based on the current user character set using
the character encoding of the page.
|
String |
formatCurrency(double nm)
Formats a
double value into a currency string. |
String |
formatCurrency(long nm)
Formats a
long value into a currency string. |
String |
formatCurrency(Number nm)
Formats a
Number object into a currency string. |
String |
formatDate(Date dt,
int style)
Formats a
Date object into a text string representation of the
date. |
String |
formatDateTime(Date dt,
int datestyle)
Formats a
Date object into a text representation of the
date and time. |
String |
formatNumber(double nm)
Formats a
double value into a text representation of the
number. |
String |
formatNumber(long nm)
Formats a
long value into a text representation of the
number. |
String |
formatNumber(Number nm)
Formats a
Number object into a text representation of the
number. |
String |
formatTime(Date dt)
Formats a
Date object into its text representation of the
time. |
String |
getAlignment(LocaleSource.Alignment alignment)
Returns the current text alignment.
|
String |
getCurrencyPattern()
Returns the currency format pattern used.
|
String |
getDatePattern(int style)
Returns the date format pattern used for the specified style.
|
String |
getDateTimePattern(int datestyle)
Returns the date and time format pattern used for the specified style.
|
String |
getDisplayCharacterSet(String charset)
Returns a translated character set name.
|
String |
getDisplayCountry(Locale locale)
Returns a translated country/territory name.
|
String |
getDisplayCountry(String country)
Returns a translated country/territory name.
|
String |
getDisplayCurrency(String currencySymbol)
Returns a translated currency name.
|
String |
getDisplayLanguage(Locale locale)
Returns a translated language name.
|
String |
getDisplayLanguage(String language)
Returns a translated language name.
|
String |
getDisplayLinguisticSort(String linguisticSort)
Returns a translated linguistic sorting name.
|
String |
getDisplayLocale(Locale locale)
Returns a translated locale name.
|
String |
getDisplayLocale(String oraLanguage,
String oraTerritory)
Returns a translated locale name.
|
String |
getDisplayTerritory(String territory)
Returns a translated country/territory name.
|
String |
getDisplayTimeZone(TimeZone tz)
Returns a translated time zone name.
|
String |
getIANACharacterSet()
Returns the IANA character set name used for the client.
|
String |
getIANAPageCharacterSet()
Returns the character set encoding of the page.
|
String |
getISOCurrency()
Returns the ISO 4217 currency code for the country of the current locale.
|
Locale |
getLocale()
Returns the
Locale object representing the current locale. |
Class[] |
getLocaleSources()
Returns locale sources examined in this order to determine the current
locale.
|
String[] |
getLocalIANACharacterSets()
Returns an array of local character sets for the current language.
|
String[] |
getLocalLinguisticSorts()
Returns an array of local Oracle linguistic sort names for the current
language.
|
String[] |
getLocalOraLanguages()
Returns an array of local languages for the current territory.
|
String[] |
getLocalOraTerritories()
Returns an array of local territories for the current language.
|
TimeZone[] |
getLocalTimeZones()
Returns an array of local
TimeZone objects for the current
territory. |
String |
getMessage(String key)
Returns a localized message associated with the key for the current
locale.
|
String |
getMessage(String key,
Class base)
Returns a localized message associated with the key for the current
locale.
|
String |
getMessage(String key,
String baseKeyName)
Returns a localized message associated with the key for the current
locale.
|
String |
getNumberPattern()
Returns the number format pattern used.
|
String |
getOraCharacterSet()
Returns the Oracle character set name used for the client
and decoding URLs.
|
String |
getOraLanguage()
Returns the Oracle language name.
|
String |
getOraShortLanguage()
Returns the short form of the Oracle language name.
|
String |
getOraTerritory()
Returns the Oracle territory name.
|
String |
getParameterName(LocaleSource.Parameter parameter)
Returns a
String representing the parameter name used to
specify locale attributes. |
String[] |
getSupportedIANACharacterSets()
Returns supported IANA character sets.
|
Locale[] |
getSupportedLocales()
Returns locales supported in the application.
|
String[] |
getSupportedOraLanguages()
Returns supported Oracle languages.
|
String[] |
getSupportedOraLanguages(String oraTerritory)
Returns supported Oracle languages for the given Oracle territory.
|
String[] |
getSupportedOraTerritories()
Returns supported Oracle territories.
|
String[] |
getSupportedOraTerritories(String oraLanguage)
Returns supported Oracle territories for the given Oracle language.
|
String |
getTimePattern()
Returns the time format pattern.
|
TimeZone |
getTimeZone()
Returns the current
TimeZone object. |
LocaleSource.WritingDirection |
getWritingDirection()
Returns the current text display writing direction.
|
Number |
parseCurrency(String str)
Parses a text representation of the currency amount into
Number object. |
Date |
parseDate(String str,
int style)
Parses a text representation of the date into a
Date
object. |
Date |
parseDateTime(String str,
int datestyle)
Parses a text representation of the date and time into a
Date
object. |
Number |
parseNumber(String str)
Parses a text representation of the number into a
Number
object. |
Date |
parseTime(String str)
Parses a text representation of the time into a
Date
object. |
boolean |
synchronizeLocale(Connection con)
Synchronizes the NLS parameters of the database session with this object.
|
public Locale getLocale()
Locale object representing the current locale.
The same value is returned by the HttpServletRequest.getLocale
method in JSP/Java Servlet application code.
Locale objectpublic String getOraLanguage()
String representing the Oracle language namepublic String getOraTerritory()
String representing the Oracle territory namepublic String getOraCharacterSet()
String representing the Oracle character set namepublic String getOraShortLanguage()
String representing the short form of the Oracle
language namepublic TimeZone getTimeZone()
TimeZone object.
If the TimeZone object is not set for the current user,
returns the default TimeZone object for the user locale.
TimeZone objectpublic LocaleSource.WritingDirection getWritingDirection()
The returned LocaleSource.WritingDirection value
is used as follows:
<% Localizer localizer = ServletHelper.getLocalizerInstance(request); %> <table dir="<%=localizer.getWritingDirection()%>" ... > ... </table>
LocaleSource.WritingDirection objectpublic String getAlignment(LocaleSource.Alignment alignment)
For example, if LTR mode, the
"Text Data" is aligned to the right,
otherwise the left.
<% Localizer localizer = ServletHelper.getLocalizerInstance(request); %> <table ... > <tr> <td align="<%=localizer.getAlignment(LocaleSource.Alignment.END)%>"> Text Data</td></tr> ... </table>
alignment - LocaleSource.Alignment.START or LocaleSource.Alignment.ENDString object either "left" or
"right"public String getISOCurrency()
public String getIANACharacterSet()
public String formatDate(Date dt, int style)
Date object into a text string representation of the
date. The required text format is specified by method arguments.dt - java.util.Date object to formatstyle - format of text data; either
OraDateFormat.LONG,
OraDateFormat.SHORT, or
OraDateFormat.DEFAULTString representing the datepublic Date parseDate(String str, int style) throws ParseException
Date
object.str - String be parsedstyle - format of text data, either
OraDateFormat.LONG,
OraDateFormat.SHORT, or
OraDateFormat.DEFAULTDate parsed from the stringParseException - if the specified string cannot be parsedpublic String getDatePattern(int style)
style - a pattern style, either
OraDateFormat.LONG,
OraDateFormat.SHORT, or
OraDateFormat.DEFAULTpublic String formatTime(Date dt)
Date object into its text representation of the
time.dt - java.util.Date object to formatString representing the timepublic Date parseTime(String str) throws ParseException
Date
object.str - String to be parsedDate parsed from the stringParseException - if the specified string cannot be parsedpublic String getTimePattern()
public String formatDateTime(Date dt, int datestyle)
Date object into a text representation of the
date and time. The required text format is specified by the style argument.dt - java.util.Date object to formatdatestyle - format of text data for the date, either
OraDateFormat.LONG,
OraDateFormat.SHORT, or
OraDateFormat.DEFAULT. The time element does not have
a style.String representing the date and timepublic Date parseDateTime(String str, int datestyle) throws ParseException
Date
object. The passed in style of the date/time string is used for the
proper parsing of the string.str - String to be parseddatestyle - format of text data for the date, either
OraDateFormat.LONG,
OraDateFormat.SHORT,
or OraDateFormat.DEFAULT. The time element does not
have a style.Date parsed from the stringParseException - if the specified string cannot be parsedpublic String getDateTimePattern(int datestyle)
You cannot specify the style of time.
datestyle - format of text data, either
OraDateFormat.LONG,
OraDateFormat.SHORT, or
OraDateFormat.DEFAULTpublic String formatNumber(Number nm)
Number object into a text representation of the
number.nm - Number object to formatString representing the numberpublic Number parseNumber(String str) throws ParseException
Number
object.str - String be parsedNumber parsed from the stringParseException - if the specified string cannot be parsedpublic String getNumberPattern()
public String formatNumber(double nm)
double value into a text representation of the
number.nm - double value to formatString representing the numberpublic String formatNumber(long nm)
long value into a text representation of the
number.nm - long value to formatString representing the numberpublic String formatCurrency(Number nm)
Number object into a currency string.nm - Number object to formatString representing the currency amountpublic Number parseCurrency(String str) throws ParseException
Number object.str - String be parsedNumber parsed from the stringParseException - if the specified string cannot be parsedpublic String getCurrencyPattern()
public String formatCurrency(double nm)
double value into a currency string.nm - double value to formatString representing the currency amountpublic String formatCurrency(long nm)
long value into a currency string.nm - long value to formatString representing the currency amountpublic int compareString(String source, String target)
source - the source string to be comparedtarget - the target string to be comparedOraCollator.EQUAL if source collation values equal
the target values, or OraCollator.LESS if source collation values are
smaller than target values, or OraCollator.GREATER if source collation values are
larger than target valuespublic int compareStringWithDefaultCollator(String source, String target)
This method is provided for the compatible operations.
source - the source string to be comparedtarget - the target string to be comparedOraCollator.EQUAL if source collation values equal
the target values, orOraCollator.LESS if source collation values are
smaller than target values, or OraCollator.GREATER if source collation values are
larger than target valuespublic String getMessage(String key, Class base)
key - a key stringbase - a base class name of the message resource bundlepublic String getMessage(String key, String baseKeyName)
key - a key stringbaseKeyName - a base key class name of the message resource bundlepublic String getMessage(String key)
key - a key stringpublic String[] getLocalOraLanguages()
public String[] getLocalOraTerritories()
public String[] getLocalIANACharacterSets()
public TimeZone[] getLocalTimeZones()
TimeZone objects for the current
territory.TimeZone objectspublic String[] getLocalLinguisticSorts()
String containing Oracle linguistic sort
namespublic String getDisplayLocale(Locale locale)
locale - a locale to be translatedpublic String getDisplayLocale(String oraLanguage, String oraTerritory)
oraLanguage - an Oracle language nameoraTerritory - an Oracle territory namepublic String getDisplayLanguage(Locale locale)
locale - a locale that includes the language to be translatedpublic String getDisplayLanguage(String language)
language - a language namepublic String getDisplayCountry(Locale locale)
locale - a locale that includes the country to be translatedpublic String getDisplayCountry(String country)
country - a country name to be translatedpublic String getDisplayTerritory(String territory)
territory - a country name to be translatedpublic String getDisplayTimeZone(TimeZone tz)
If the translation is not found, the return value is composed using
getRawOffset() value in the form of (SHH:MM) where
S for a sign of the value, HH represents the
hours of the offset, and MM represents the minutes of the
offset.
tz - a time zone to be translatedpublic String getDisplayLinguisticSort(String linguisticSort)
linguisticSort - an Oracle linguistic sorting name to be translatedpublic String getDisplayCharacterSet(String charset)
charset - a character set name to be translatedpublic String getDisplayCurrency(String currencySymbol)
currencySymbol - a character set symbol ISO 4217public String encodeURL(String source)
source - a source string to encodepublic String decodeURL(String source)
source - a source string to decodepublic boolean synchronizeLocale(Connection con) throws SQLException
This executes ALTER SESSION SQL commands to set NLS session
parameters to synchronize the locale and attributes in this object. The
following session parameters are updated:
NLS_LANGUAGE
NLS_TERRITORY
NLS_DATE_LANGUAGE
NLS_DATE_FORMAT
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_COMP
NLS_SORT
con - the connection object for the database. Make sure the connection
is established, othewise you will get an SQLException
error.true if the SQL execution is successfull, otherwise
falseSQLExceptionpublic String getParameterName(LocaleSource.Parameter parameter)
String representing the parameter name used to
specify locale attributes. For example, if you want to get the locale
value, use the LocaleSource.LOCALE object as an input:
ApplicationContext appctx = ServletHelper.getApplicationContextInstance( request); String locale = request.getParameter( appctx.getParameterName(LocaleSource.LOCALE));
parameter - a parameter typepublic Locale[] getSupportedLocales()
The supported locale can be specified in the application configuration file.
Locale objects
representing supported locales in the applicationpublic String getIANAPageCharacterSet()
public Class[] getLocaleSources()
LocaleSource classespublic String[] getSupportedOraLanguages(String oraTerritory)
The supported languages are determined by the supported locale. Sorting order is in the English language.
oraTerritory - Oracle territory nameString representing the supported
languages in the applicationpublic String[] getSupportedOraLanguages()
The supported languages are determined by the supported locale. Sorting order is in the English language.
String representing the supported
languages in the applicationpublic String[] getSupportedOraTerritories(String oraLanguage)
The supported territories are determined by the supported locale. Sorting order is in the English language.
oraLanguage - Oracle langauge nameString representing the supported
territories in the applicationpublic String[] getSupportedOraTerritories()
The supported territories are determined by the supported locale. Sorting order is in the English language.
String representing the supported
territories in the applicationpublic String[] getSupportedIANACharacterSets()