Oracle® Globalization Development Kit Java API Reference
10g Release 1(10.1)

B10971-01

oracle.i18n.servlet
Class Localizer

java.lang.Object
  |
  +--oracle.i18n.servlet.Localizer

public class Localizer
extends Object

Localizer is an all-in-on object class that enables to access all necessary globalization information.

The Localizer instance derived from ServletHelper.getLocalizerInstance(HttpServletRequest) that is associated with the current user locale. The user may change the current locale on each page;therefore, the scope of Localizer is page.

By using Localizer, the user doesn't have to deal with the locale sensitive operation manually. Instead, all information can be obtained from one Localizer object. The following functionalities of classes are included:



Since:
10.1.0.2

Method Summary
 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 page character encoding.
 String encodeURL(String source)
          Encodes a URL string based on the current user character set using the page character set encoding.
 String formatCurrency(double nm)
          Translates a double value into a text representation of the currency amount.
 String formatCurrency(long nm)
          Translates a long value into a text representation of the currency amount.
 String formatCurrency(Number nm)
          Translates a Number object into a text representation of the currency amount.
 String formatDate(Date dt, int style)
          Translates a Date object into a text representation of the date.
 String formatDateTime(Date dt, int datestyle)
          Translates a Date object into a text representation of the date and time.
 String formatNumber(double nm)
          Translates a double value into a text representation of the number.
 String formatNumber(long nm)
          Translates a long value into a text representation of the number.
 String formatNumber(Number nm)
          Translates a Number object into a text representation of the number.
 String formatTime(Date dt)
          Translates a Date object into a text representation of the time.
 String getAlignment(LocaleSource.Alignment alignment)
          Returns the current text alignment Here is an example to specify the text alignment value; if LTR mode, the "Text Data" is aligned to right, otherwise left.
 String getCurrencyPattern()
          Returns the currency format pattern used.
 String getDatePattern(int style)
          Returns the date format pattern used in the specified style.
 String getDateTimePattern(int datestyle)
          Returns the date and time format pattern used in 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 TimeZone name.
 String getIANACharacterSet()
          Returns the IANA character set name used for the client.
 String getIANAPageCharacterSet()
          Returns the page character set encoding.
 String getISOCurrency()
          Returns the ISO 4217 currency code for the current locale's country
 Locale getLocale()
          Returns the Locale 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 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 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 given Oracle territory The supported languages are determined by the supported locale.
 String[] getSupportedOraTerritories()
          Returns supported Oracle territories.
 String[] getSupportedOraTerritories(String oraLanguage)
          Returns supported Oracle territories given Oracle language The supported territories are determined by the supported locale.
 String getTimePattern()
          Returns the time format pattern
 TimeZone getTimeZone()
          Returns the current TimeZone.
 LocaleSource.WritingDirection getWritingDirection()
          Returns the current text display writing direction.
 Number parseCurrency(String str)
          Translates a text representation of the currency amount into Number.
 Date parseDate(String str, int style)
          Translates a text representation of the date into a Date.
 Date parseDateTime(String str, int datestyle)
          Translates a Date object into a text representation of the date and time.
 Number parseNumber(String str)
          Translates a text representation of the number into a Number.
 Date parseTime(String str)
          Translates a text representation of the time into a Date.
 boolean synchronizeLocale(Connection con)
          Synchronizes the database session NLS parameters with this object.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Method Detail

getLocale

public Locale getLocale()
Returns the Locale representing the current locale.

The same value is returned by HttpServletRequest.getLocale method in JSP/Java Servlet application code.

Returns:
a Locale object

getOraLanguage

public String getOraLanguage()
Returns the Oracle language name
Returns:
a String representing the Oracle language name

getOraTerritory

public String getOraTerritory()
Returns the Oracle territory name
Returns:
a String representing the Oracle territory name

getOraCharacterSet

public String getOraCharacterSet()
Returns the Oracle character set name used for the client and decoding URLs.
Returns:
a String representing the Oracle character set name

getOraShortLanguage

public String getOraShortLanguage()
Returns the short form of Oracle language name.
Returns:
a String representing the short form of Oracle language name

getTimeZone

public TimeZone getTimeZone()
Returns the current TimeZone.

If the TimeZone is not set for the current user, returns the default TimeZone object for the user locale.

Returns:
a TimeZone object

getWritingDirection

public LocaleSource.WritingDirection getWritingDirection()
Returns the current text display writing direction.

The return value LocaleSource.WritingDirection is used as follows:

 <%
   Localizer localizer = ServletHelper.getLocalizerInstance(request);
 %>
 <table dir="<%=localizer.getWritingDirection()%>"
 ... >
 ...
 </table>


Returns:
LocaleSource.WritingDirection object

getAlignment

public String getAlignment(LocaleSource.Alignment alignment)
Returns the current text alignment

Here is an example to specify the text alignment value; if LTR mode, the "Text Data" is aligned to right, otherwise left.

 <%
   Localizer localizer = ServletHelper.getLocalizerInstance(request);
 %>
 <table ... >
 <tr>
 <td align="<%=localizer.getAlignment(LocaleSource.Alignment.END)%>">
 Text Data</td></tr>
 ...
 </table>


Parameters:
alignment - LocaleSource.Alignment.START or LocaleSource.Alignment.END
Returns:
String object either "left" or "right"

getISOCurrency

public String getISOCurrency()
Returns the ISO 4217 currency code for the current locale's country
Returns:
ISO4217 currency code

getIANACharacterSet

public String getIANACharacterSet()
Returns the IANA character set name used for the client.
Returns:
IANA character set name

formatDate

public String formatDate(Date dt,
                         int style)
Translates a Date object into a text representation of the date. The required text format is specified by method arguments.
Parameters:
dt - java.util.Date object to format
style - Format of text data; either OraDateFormat.LONG, OraDateFormat.SHORT, or OraDateFormat.DEFAULT.
Returns:
String representing the date.

parseDate

public Date parseDate(String str,
                      int style)
               throws ParseException
Translates a text representation of the date into a Date.
Parameters:
str - String be parsed.
style - Format of text data, either OraDateFormat.LONG, OraDateFormat.SHORT, or OraDateFormat.DEFAULT.
Returns:
Date parsed from the string.
Throws:
ParseException - if the specified string cannot be parsed.

getDatePattern

public String getDatePattern(int style)
Returns the date format pattern used in the specified style.
Parameters:
style - Format of text data, either OraDateFormat.LONG, OraDateFormat.SHORT, or OraDateFormat.DEFAULT.
Returns:
the format pattern

formatTime

public String formatTime(Date dt)
Translates a Date object into a text representation of the time.
Parameters:
dt - java.util.Date object to format
Returns:
String representing the time.

parseTime

public Date parseTime(String str)
               throws ParseException
Translates a text representation of the time into a Date.
Parameters:
str - String be parsed.
Returns:
Date parsed from the string.
Throws:
ParseException - if the specified string cannot be parsed.

getTimePattern

public String getTimePattern()
Returns the time format pattern
Returns:
the format pattern

formatDateTime

public String formatDateTime(Date dt,
                             int datestyle)
Translates a Date object into a text representation of the date and time. The required text format is specified by method arguments.
Parameters:
dt - java.util.Date object to format
datestyle - Format of text data for the date, either OraDateFormat.LONG, OraDateFormat.SHORT, or OraDateFormat.DEFAULT. Time element doesn't have style.
Returns:
String representing the date and time.

parseDateTime

public Date parseDateTime(String str,
                          int datestyle)
                   throws ParseException
Translates a Date object into a text representation of the date and time. The required text format is specified by method arguments.
Parameters:
str - String be parsed.
datestyle - Format of text data for the date, either] OraDateFormat.LONG, OraDateFormat.SHORT or, OraDateFormat.DEFAULT. Time element doesn't have style.
Returns:
Date parsed from the string.
Throws:
ParseException - if the specified string cannot be parsed.

getDateTimePattern

public String getDateTimePattern(int datestyle)
Returns the date and time format pattern used in the specified style.

You cannot specify the style of time

Parameters:
datestyle - Format of text data either OraDateFormat.LONG, OraDateFormat.SHORT, or OraDateFormat.DEFAULT
Returns:
the format pattern

formatNumber

public String formatNumber(Number nm)
Translates a Number object into a text representation of the number.
Parameters:
nm - Number object to format
Returns:
String representing the number.

parseNumber

public Number parseNumber(String str)
                   throws ParseException
Translates a text representation of the number into a Number.
Parameters:
str - String be parsed.
Returns:
Number parsed from the string.
Throws:
ParseException - if the specified string cannot be parsed.

getNumberPattern

public String getNumberPattern()
Returns the number format pattern used.
Returns:
the format pattern

formatNumber

public String formatNumber(double nm)
Translates a double value into a text representation of the number.
Parameters:
nm - double value to format
Returns:
String representing the number.

formatNumber

public String formatNumber(long nm)
Translates a long value into a text representation of the number.
Parameters:
nm - long value to format
Returns:
String representing the number.

formatCurrency

public String formatCurrency(Number nm)
Translates a Number object into a text representation of the currency amount.
Parameters:
nm - Number object to format
Returns:
String representing the currency amount.

parseCurrency

public Number parseCurrency(String str)
                     throws ParseException
Translates a text representation of the currency amount into Number.
Parameters:
str - String be parsed.
Returns:
Number parsed from the string.
Throws:
ParseException - if the specified string cannot be parsed.

getCurrencyPattern

public String getCurrencyPattern()
Returns the currency format pattern used.
Returns:
the format pattern

formatCurrency

public String formatCurrency(double nm)
Translates a double value into a text representation of the currency amount.
Parameters:
nm - double value to format.
Returns:
String representing the currency amount.

formatCurrency

public String formatCurrency(long nm)
Translates a long value into a text representation of the currency amount.
Parameters:
nm - long value to format.
Returns:
String representing the currency amount.

compareString

public int compareString(String source,
String target)
Compares two strings using the current linguistic sort/collator object.
Parameters:
source - the source string to be compared
target - the target string to be compared
Returns:
OraCollator.EQUAL if equals,
OraCollator.LESS if source collation values are smaller than target's, or
OraCollator.GREATER if source collation values are larger than target's.

compareStringWithDefaultCollator

public int compareStringWithDefaultCollator(String source,
String target)
Compares two strings using the default linguistic sort/collator object.

This method is provided for the compatible operations.

Parameters:
source - the source string to be compared
target - the target string to be compared
Returns:
OraCollator.EQUAL if equals,
OraCollator.LESS if source collation values are smaller than target's, or
OraCollator.GREATER if source collation values are larger than target's.

getMessage

public String getMessage(String key,
Class base)
Returns a localized message associated with the key for the current locale
Parameters:
key - a key string
base - a base class name of the message resource bundle
Returns:
a localized message

getMessage

public String getMessage(String key,
String baseKeyName)
Returns a localized message associated with the key for the current locale
Parameters:
key - a key string
baseKeyName - a base key class name of the message resource bundle
Returns:
a localized message

getMessage

public String getMessage(String key)
Returns a localized message associated with the key for the current locale.
Parameters:
key - a key string
Returns:
a localized message

getLocalOraLanguages

public String[] getLocalOraLanguages()
Returns an array of local languages for the current territory.
Returns:
an array of Oracle languages

getLocalOraTerritories

public String[] getLocalOraTerritories()
Returns an array of local territories for the current language.
Returns:
an array of Oracle territories

getLocalIANACharacterSets

public String[] getLocalIANACharacterSets()
Returns an array of local character sets for the current language.
Returns:
an array of IANA territories

getLocalTimeZones

public TimeZone[] getLocalTimeZones()
Returns an array of local TimeZone for the current territory.
Returns:
an array of Java TimeZone

getLocalLinguisticSorts

public String[] getLocalLinguisticSorts()
Returns an array of local Oracle Linguistic sort names for the current language.
Returns:
an array of String containing Oracle linguistic sort names.

getDisplayLocale

public String getDisplayLocale(Locale locale)
Returns a translated locale name.
Parameters:
locale - a locale to be translated.
Returns:
a translated string.

getDisplayLocale

public String getDisplayLocale(String oraLanguage,
String oraTerritory)
Returns a translated locale name
Parameters:
oraLanguage - an Oracle language name
oraTerritory - an Oracle territory name
Returns:
a translated locale name

getDisplayLanguage

public String getDisplayLanguage(Locale locale)
Returns a translated language name
Parameters:
locale - a locale that includes the language to be translated
Returns:
a translated langauge name

getDisplayLanguage

public String getDisplayLanguage(String language)
Returns a translated language name
Parameters:
language - a language name
Returns:
a translated langauge name

getDisplayCountry

public String getDisplayCountry(Locale locale)
Returns a translated country/territory name
Parameters:
locale - a locale that includes the country to be translated
Returns:
a translated country name

getDisplayCountry

public String getDisplayCountry(String country)
Returns a translated country/territory name
Parameters:
country - a country name to be translated
Returns:
a translated country name

getDisplayTerritory

public String getDisplayTerritory(String territory)
Returns a translated country/territory name
Parameters:
territory - a country name to be translated
Returns:
a translated country name

getDisplayTimeZone

public String getDisplayTimeZone(TimeZone tz)
Returns a translated TimeZone name.

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 MI represents the minutes of the offiset.

Parameters:
tz - a TimeZone to be translated.
Returns:
a translated timezone name

getDisplayLinguisticSort

public String getDisplayLinguisticSort(String linguisticSort)
Returns a translated Linguistic sorting name
Parameters:
linguisticSort - an Oracle linguistic sorting name to be translated
Returns:
a translated linguistic sorting name

getDisplayCharacterSet

public String getDisplayCharacterSet(String charset)
Returns a translated character set name
Parameters:
charset - a character set name to be translated
Returns:
a translated character set name

getDisplayCurrency

public String getDisplayCurrency(String currencySymbol)
Returns a translated currency name
Parameters:
currencySymbol - a character set symbol ISO 4217
Returns:
a translated currency name

encodeURL

public String encodeURL(String source)
Encodes a URL string based on the current user character set using the page character set encoding.
Parameters:
source - a source string to encode
Returns:
a encoded string

decodeURL

public String decodeURL(String source)
Decodes a URL string based on the current user character set using the page character encoding.
Parameters:
source - a source string to decode
Returns:
a decoded string

synchronizeLocale

public boolean synchronizeLocale(Connection con)
                          throws SQLException
Synchronizes the database session NLS parameters with this object.

This executes ALTER SESSIONSQL commands to set NLS session parameters to synchronize the locale and attributes in this object. The following session parameters will be updated:

Note: Other threads may override NLS session parameters with different values while your thread is active. For this reason, this method is not suitable for a multilingual application that handles multiple locales in a single instance. Instead, develop applications that are as independent from NLS session parameters as possible.

Parameters:
con - the connection object for the database. Make sure connection is established, othewise you will get an SQLException.
Returns:
true if the SQL execution is successfull, otherwise false.
Throws:
SQLException

getParameterName

public String getParameterName(LocaleSource.Parameter parameter)
Returns a String representing the parameter name used to specify locale attributes. For example, if you want to get the locale value, use LocaleSource.LOCALE as an input:
 ApplicationContext appctx = ServletHelper.getApplicationContextInstance(
   request);
 String plocale = request.getParameter(
   appctx.getParameterName(LocaleSource.LOCALE));
Parameters:
parameter - a parameter type.
Returns:
a parameter name used in the application.

getSupportedLocales

public Locale[] getSupportedLocales()
Returns locales supported in the application.

The supported locale can be specified in the application configration file.

Returns:
an array of Locale representing supported locales in the application.

getIANAPageCharacterSet

public String getIANAPageCharacterSet()
Returns the page character set encoding.

If this object is obtained by ServletHelper.getLocalizerInstance,

Returns:
a IANA character set name

getLocaleSources

public Class[] getLocaleSources()
Returns locale sources examined in this order to determine the current locale.
Returns:
an array of LocaleSource classes

getSupportedOraLanguages

public String[] getSupportedOraLanguages(String oraTerritory)
Returns supported Oracle languages given Oracle territory

The supported languages are determined by the supported locale. Sorting order is in English.

Parameters:
oraTerritory - Oracle territory name
Returns:
an array of String representing the supported languages in the application.

getSupportedOraLanguages

public String[] getSupportedOraLanguages()
Returns supported Oracle languages.

The supported languages are determined by the supported locale. Sorting order is in English.

Returns:
an array of String representing the supported languages in the application.

getSupportedOraTerritories

public String[] getSupportedOraTerritories(String oraLanguage)
Returns supported Oracle territories given Oracle language

The supported territories are determined by the supported locale. Sorting order is in English.

Parameters:
oraLanguage - Oracle langauge name
Returns:
an array of String representing the supported territories in the application.

getSupportedOraTerritories

public String[] getSupportedOraTerritories()
Returns supported Oracle territories.

The supported territories are determined by the supported locale. Sorting order is in English.

Returns:
an array of String representing the supported territories in the application.

getSupportedIANACharacterSets

public String[] getSupportedIANACharacterSets()
Returns supported IANA character sets
Returns:
an array of supported IANA character sets in the application.

Oracle® Globalization Development Kit Java API Reference
10g Release 1(10.1)

B10971-01

Copyright © 2003 Oracle Corporation. All Rights Reserved.