public final class Localizer extends Object implements Serializable
Many methods in the iFS API require internationalization information, such as the appropriate locale, date format, time format, or number format. This data is encapsulated in a Localizer instance, which is made available to such methods.
Each LibrarySession has a Localizer based on arguments supplied to
LibraryService.connect
.
A Localizer also encapsulates the iFS resource bundle.
The getResourceString
methods of LibrarySession and
LibraryObject use this resource bundle to generate localized messages.
An application can override some or all of these messages, or introduce
its own messages, by invoking setExtendedResourceBundles
on the Localizer returned by LibrarySession.getLocalizer
.
Modifier and Type | Field and Description |
---|---|
static String |
ADDEDEXTENDEDRESOURCEBUNDLENAME
Internal property name for adding an extended resource property bundle names.
|
static String |
CHARENCODING
Internal property name for the character encoding.
|
static String |
DATEFORMATTER
Internal property name for the date formatter.
|
static String |
EXTENDEDRESOURCEBUNDLENAMES
Internal property name for the extended resource property bundle names.
|
static String |
LANGUAGE
Internal property name for the context language.
|
static String |
LOCALE
Internal property name for the locale.
|
protected Calendar |
m_Calendar
The Calendar of this Localizer.
|
protected String |
m_CharEncoding
The Iana character encoding of this Localizer.
|
protected DateFormat |
m_DateFormatter
The date formatter of this Localizer.
|
protected boolean |
m_DefaultExtendedResourceBundleNamesAdded
Have the default names of the extended resource bundles been added
to this Localizer?
|
protected Vector |
m_ExtendedResourceBundleNames
The names of the extended resource bundles of this Localizer.
|
protected Vector |
m_ExtendedResourceBundles
The extended resource bundles of this Localizer.
|
protected String |
m_Language
The Oracle language name for context search.
|
protected Locale |
m_Locale
The locale of this Localizer.
|
protected NumberFormat |
m_NumberFormatter
The number formatter of this Localizer.
|
protected ResourceBundle |
m_ResourceBundle
The resource bundle of this Localizer.
|
protected LibrarySession |
m_Session
The LibrarySession to which this Localizer is bound.
|
protected DateFormat |
m_TimeFormatter
The time formatter of this Localizer.
|
protected TimeZone |
m_TimeZone
The time zone of this Localizer.
|
static String |
NUMBERFORMATTER
Internal property name for the number formatter.
|
static String |
REMOVEALLEXTENDEDRESOURCEBUNDLENAMES
Internal property name for removing all extended resource property bundle names.
|
static String |
REMOVEDEXTENDEDRESOURCEBUNDLENAME
Internal property name for removing an extended resource property bundle names.
|
protected static Locale |
s_NoLanguageLocale
A static Locale (no lang or country) for forced english
translations.
|
protected static Localizer |
s_UsEnglishLocalizer
A static US English Localizer.
|
static String |
TIMEFORMATTER
Internal property name for the time formatter.
|
static String |
TIMEZONE
Internal property name for the timezone.
|
Constructor and Description |
---|
Localizer()
Constructs a Localizer.
|
Localizer(Locale locale)
Constructs a Localizer for the specified locale.
|
Localizer(Locale locale,
LibrarySession session)
Constructs a Localizer for the specified locale.
|
Modifier and Type | Method and Description |
---|---|
void |
addExtendedResourceBundle(String bundleName)
Adds a resource bundle to the vector if it is not there already.
|
static Locale |
constructLocale(String localeString)
Construct a Locale from a String representation.
|
Calendar |
getCalendar()
Gets the Calendar of this Localizer.
|
String |
getCharEncoding()
Gets the Iana character set of this Localizer.
|
DateFormat |
getDateFormatter()
Gets the date formatter of this Localizer.
|
static Localizer |
getDefault()
Gets the default US English Localizer.
|
protected Locale |
getDefaultLocale()
Gets the default locale, first looks in the properties file, second
looks at the JavaVM.
|
String[] |
getExtendedResourceBundles()
Gets the extended resource bundles for this Localizer.
|
String |
getLanguage()
Returns the language for this LibrarySession
in English.
|
Locale |
getLocale()
Gets the locale of this Localizer.
|
NumberFormat |
getNumberFormatter()
Gets the number formatter of this Localizer.
|
String |
getResourceString(String key)
Gets the resource string for the specified key.
|
String |
getResourceString(String key,
Object[] params)
Gets the resource string for the specified key, and substitutes the
specified parameters into that resource string.
|
DateFormat |
getTimeFormatter()
Gets the time formatter of this Localizer.
|
TimeZone |
getTimeZone()
Gets the time zone of this Localizer.
|
void |
removeAllExtendedResourceBundles()
Removes all extended resource bundles.
|
void |
removeExtendedResourceBundle(String bundleName)
Removes a resource bundle from the vector.
|
static void |
resetDefaultLocalizerExtendedResourceBundles(LibrarySession session)
Initialize the default Localizer's set of Extended resource bundles
|
void |
setCharEncoding(String charEncoding)
Sets the Iana character set of this Localizer.
|
void |
setDateFormatter(DateFormat dateFormatter)
Sets the date formatter of this Localizer.
|
void |
setDefaultExtendedResourceBundles()
Sets the default set of extended resource bundle names to be
used.
|
void |
setExtendedResourceBundles(String[] baseNames)
Sets the extended resource bundles for this Localizer.
|
void |
setLanguage(String language)
Sets the language to be used by context search.
|
void |
setLocale(Locale locale)
Sets the locale of this Localizer.
|
void |
setNumberFormatter(NumberFormat numberFormatter)
Sets the number formatter of this Localizer.
|
void |
setTimeFormatter(DateFormat timeFormatter)
Sets the time formatter of this Localizer.
|
void |
setTimeZone(TimeZone timeZone)
Sets the time zone of this Localizer.
|
protected void |
updateTimeZone(TimeZone timeZone) |
public static final String LOCALE
public static final String CHARENCODING
public static final String LANGUAGE
public static final String NUMBERFORMATTER
public static final String DATEFORMATTER
public static final String TIMEFORMATTER
public static final String TIMEZONE
public static final String EXTENDEDRESOURCEBUNDLENAMES
public static final String ADDEDEXTENDEDRESOURCEBUNDLENAME
public static final String REMOVEDEXTENDEDRESOURCEBUNDLENAME
public static final String REMOVEALLEXTENDEDRESOURCEBUNDLENAMES
protected transient LibrarySession m_Session
protected Locale m_Locale
protected String m_CharEncoding
protected String m_Language
protected NumberFormat m_NumberFormatter
protected DateFormat m_DateFormatter
protected DateFormat m_TimeFormatter
protected Calendar m_Calendar
protected TimeZone m_TimeZone
protected transient ResourceBundle m_ResourceBundle
protected transient Vector m_ExtendedResourceBundles
protected transient Vector m_ExtendedResourceBundleNames
protected boolean m_DefaultExtendedResourceBundleNamesAdded
protected static Localizer s_UsEnglishLocalizer
protected static Locale s_NoLanguageLocale
public Localizer() throws IfsException
The Localizer's locale is the default locale of the Java VM. The Localizer has default number, date, and time formatters for that locale, and uses 8859_1 (ISO Latin1) character encoding.
IfsException
- (IFS-12000) if the operation failspublic Localizer(Locale locale) throws IfsException
The Localizer has default number, date, time formatters; and default Timezone and character encoding settings.
locale
- the locale of the Localizer. If null, the
default locale of the Java VM is used.IfsException
- (IFS-12000) if the operation failspublic Localizer(Locale locale, LibrarySession session) throws IfsException
The Localizer has default number, date, time formatters; and default Timezone and character encoding settings.
locale
- the locale of the Localizer. If null, the
default locale of the Java VM is used.session
- the LibrarySession to which the Localizer is
bound; any changes to this Localizer will
trigger identical changes in the Localizer of
the corresponding S_LibrarySessionIfsException
- (IFS-12000) if the operation failspublic void setDefaultExtendedResourceBundles() throws IfsException
IfsException
- if the operation failspublic static void resetDefaultLocalizerExtendedResourceBundles(LibrarySession session) throws IfsException
session
- the session contextIfsException
- if the operation failspublic Locale getLocale() throws IfsException
IfsException
- if the operation failspublic static Locale constructLocale(String localeString)
The string should be one of:
localeString
- the string representation of the Localepublic void setLocale(Locale locale) throws IfsException
The number formatter, date formatter, and time formatter are set to default formatters for the specified locale.
locale
- the localeIfsException
- if the operation failspublic static Localizer getDefault()
This default is used by IfsException.getMessage
.
public void setCharEncoding(String charEncoding) throws IfsException
charEncoding
- the Iana character set.IfsException
- if the operation failspublic String getCharEncoding() throws IfsException
IfsException
- if the operation failsprotected Locale getDefaultLocale() throws IfsException
IfsException
- if the operation failspublic void setLanguage(String language) throws IfsException
language
- the Oracle language name.IfsException
public String getLanguage() throws IfsException
IfsException
public void setNumberFormatter(NumberFormat numberFormatter) throws IfsException
numberFormatter
- the number formatter. If null, a default
number formatter for the locale of this
Localizer is used.IfsException
- (IFS-12002) if the operation failspublic NumberFormat getNumberFormatter() throws IfsException
IfsException
- if the operation failspublic void setDateFormatter(DateFormat dateFormatter) throws IfsException
dateFormatter
- the date formatter. If null, a default
date formatter for the locale of this
Localizer is used.IfsException
- (IFS-12003) if the operation failspublic DateFormat getDateFormatter() throws IfsException
IfsException
- if the operation failspublic void setTimeFormatter(DateFormat timeFormatter) throws IfsException
timeFormatter
- the time formatter. If null, a default
time formatter for the locale of this
Localizer is used.IfsException
- (IFS-12004) if the operation failspublic DateFormat getTimeFormatter() throws IfsException
IfsException
- if the operation failspublic void setTimeZone(TimeZone timeZone) throws IfsException
timeZone
- the time zone. If null, a default
time zone for the locale of this
Localizer is used.IfsException
- (IFS-12005) if the operation failsprotected void updateTimeZone(TimeZone timeZone)
public TimeZone getTimeZone() throws IfsException
IfsException
- if the operation failspublic Calendar getCalendar() throws IfsException
IfsException
- if the operation failspublic void setExtendedResourceBundles(String[] baseNames) throws IfsException
baseNames
- an array of resource bundle names. Each
resource bundle name must be a valid argument to
ResourceBundle.getBundle(String)
.IfsException
- if the operation failspublic String[] getExtendedResourceBundles() throws IfsException
When a Localizer is constructed, its extended resource bundles default
to those of the default Localizer (Localizer.getDefault()
).
ResourceBundle.getBundle(String)
.IfsException
- if the operation failspublic void addExtendedResourceBundle(String bundleName) throws IfsException
bundleName
- the name of the resource bundle.IfsException
- if the operation failspublic void removeExtendedResourceBundle(String bundleName) throws IfsException
bundleName
- the name of the resource bundle.IfsException
- if the operation failspublic void removeAllExtendedResourceBundles() throws IfsException
IfsException
- if the operation failspublic String getResourceString(String key) throws IfsException
The method looks-up the key in each extended resource bundle, in the
order specified by the array in setExtendedResourceBundles
,
until it finds a bundle containing the key. If no extended resource
bundle contains the key, the default resource bundle (LibraryResources)
is used.
key
- the resource bundle keyIfsException
- IFS-12001 if the operation failspublic String getResourceString(String key, Object[] params) throws IfsException
The method looks-up the key using getResourceString(key)
.
Next, java.text.MessageFormat
is used to substitute the
parameters specified by params
into the key's value. If
a string element of params
is delimited by brackets, i.e.
"{param}
", then that element is replaced with the
value returned by getResourceString("param")
before
being passed to MessageFormat
.
key
- the resource bundle keyparams
- an array of Objects to be substituted into
the resource bundle message using using
java.text.MessageFormat
IfsException
- IFS-12006 if the operation failsCopyright © 2023. All rights reserved.