Class LocaleSource
- java.lang.Object
-
- oracle.i18n.servlet.localesource.LocaleSource
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ApplicationDefault,DBLocaleSource,HttpAcceptLanguage,UserInput
public abstract class LocaleSource extends Object implements Serializable
TheLocaleSourceclass is the abstract base class for locale source objects. A locale source represents an entity that can provide certain locale specific preferences like a locale name, encoding name, etc. There can be many types of sources of pertinent locale preferences, for instance a database table can contain locale specific parameters and can be a locale source. A user action can result in generation of an HTML POST request with query parameters that can be a basis of locale source. Even the HTTP protocol's headers can be yet another source of these locale parameters.The user locale is determined according to the list of
LocaleSourceclass declarations in the GDK application configuration file. The GDK examines eachLocaleSourceclass declaration, in the list using the declared order of the list. The first availableLocaleSourceis used for the user locale.The GDK provides the following pre-defined
LocaleSourceimplementations:-
HttpAcceptLanguage- the locale preference set by the web client in the HTTP header. -
UserInput- the locale preference in the parameters ofGETandPOSTmethods. -
DBLocaleSource- the locale preference stored in the Oracle database. -
ApplicationDefault- the default locale for the application.
Note
ApplicationDefaultlocale source is implicitly registered in the end of the locale source. If no other locale source is available, theApplicationDefaultlocale source is used.Using the GDK configuration, the language of an application (User Interface) can be configured in many ways. The GDK configuration example below, illustrates configuration for a scenario where the language of an initial application page will be determined based on the language setting of the browser. Additionally, the user will be able to override this language by choosing from the available list of locales displayed in a Locale Selection drop-down. For example, if the browser language setting is Chinese, then pointing your browser to this application will display the User Interface in the Chinese language. Furthermore, the user can select Swiss (German) locale from the Locale Selection dropdown to change the application user interface to display German. The configuration below (from a gdkapp.xml) is used by the GDK to first try to use the Accept-Language HTTP header as the source of the locale, unless it is overridden by user input, which in the application's case is the selection of the locale from a Locale Selection dropdown. When the user picks the locale from the dropdown, the JSP posts a locale parameter value containing the selected locale. The GDK then sends a response, with the contents in the selected language.
<locale-determine-rule> <locale-source> oracle.i18n.servlet.localesource.UserInput </locale-source> <locale-source> oracle.i18n.servlet.localesource.HttpAcceptLanguage </locale-source> </locale-determine-rule>To create a custom locale source object, extend this class. The custom object for instance, may access the Oracle database to fetch and update the user locale preference, or it may access the LDAP server to get and set the language preference elements. Three methods must be implemented in the custom locale source:
-
public static LocaleSource getInstance(HttpServletRequest)- used to instantiate the object. It returns the object if it succeeds, otherwisenull. -
public boolean- used to load the locale and its attributes from the locale source.load() -
public boolean- used to store the locale and its attributes into the locale source. If the locale source is read-only, this method should do nothing but returnstore()true.
-
public static boolean isAccessible(HttpServletRequest)- used to check if the locale source is accessible before using the cached object. It returnstrueif the locale source is accessible, otherwisefalse. If this method is not implemented, the GDK assumes that the locale source is always accessible.
-
cache flag- indicates whether the locale source can be cached. If the access cost to the locale source is not trivial, such as LDAP server, this flag should betrue, otherwisefalse. -
read-only flag- indicates whether the locale source is read-only. If the locale source cannot be updated, such as theAccept-Languageitem in the HTTP header, this flag istrue, otherwisefalse.
For example, the locale source accessing the LDAP server should be cached so that the GDK keeps the locale information while the user is valid. Once the user logs out, the locale information is no longer valid.
- Since:
- 10.1.0.2
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLocaleSource.AlignmentTheLocaleSource.Alignmentclass represents the alignment of text elements.static classLocaleSource.ParameterTheLocaleSource.Parameterclass represents locale and attribute variable names.static classLocaleSource.WritingDirectionTheLocaleSource.WritingDirectionclass represents the writing direction of the locale.
-
Constructor Summary
Constructors Modifier Constructor Description protectedLocaleSource(boolean isCached, boolean isReadOnly)Constructs aLocaleSourceobject.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Determines if a specific object is equal to this object.protected ObjectgetAttribute(String key)Returns the attribute object.StringgetCharacterSet()Returns the character set name in this object.OraCollatorgetCollator()Returns the Oracle collator object.OraNumberFormatgetCurrencyFormat()Returns the Oracle currency format in this object.OraDateFormatgetDateFormat(int style)Returns the Oracle date format of the specified style in this object.OraDateFormatgetDateTimeFormat(int style)Returns the Oracle date and time format of the specified style in this object.StringgetISOCurrency()Returns the ISO 4217 currency ID in this object.LocalegetLocale()Returns theLocaleobject in this object.ClassgetLocaleSourceClass()Returns the locale source class.OraNumberFormatgetNumberFormat()Returns the Oracle number format in this object.OraDateFormatgetTimeFormat()Returns the Oracle time format in this object.TimeZonegetTimeZone()Returns the time zone in this object.LocaleSource.WritingDirectiongetWritingDirection()Returns the writing direction in this object.inthashCode()Returns the hash value of this object.booleanisCached()Checks if theLocaleSourceobject is cached.booleanisReadOnly()Checks if theLocaleSourceobject is read-only.abstract booleanload()Loads the locale and all attributes from the actual locale source into this object.protected voidsetAttribute(String key, Object object)Registers an attribute object in the locale source.voidsetCharacterSet(String charset)Registers the Oracle character set name to store in the actualLocaleSourceclass.voidsetCollator(OraCollator ocol)Registers the Oracle collator to store in the actualLocaleSourceclass.voidsetCurrencyFormat(OraNumberFormat nfmt)Registers the Oracle currency format object to store in the actualLocaleSourceclass.voidsetDateFormat(int style, OraDateFormat dtfmt)Registers the Oracle date format object to store in the actualLocaleSourceclass.voidsetDateTimeFormat(int dtstyle, OraDateFormat dtfmt)Registers the Oracle date time format object to store in the actualLocaleSourceclass.voidsetISOCurrency(String currency)Registers the ISO currency to store in the actualLocaleSourceclass.voidsetLocale(Locale locale)Registers theLocaleobject with this object.voidsetLocale(Locale locale, ApplicationContext appctx)Registers the locale object in this object.voidsetLocaleSourceClass(Class loccls)Registers the locale source class object.voidsetNumberFormat(OraNumberFormat nfmt)Registers the Oracle number format object to store in the actualLocaleSourceclass.voidsetTimeFormat(OraDateFormat tmfmt)Registers the Oracle time format object to store in the actualLocaleSourceclass.voidsetTimeZone(TimeZone tz)Registers theTimeZoneID to store in the actualLocaleSourceclass.voidsetWritingDirection(LocaleSource.WritingDirection wdir)Registers the writing direction to store in the actualLocaleSourceclass.abstract booleanstore()Stores the locale and all attributes of the object in the actualLocaleSourceclass.
-
-
-
Method Detail
-
isCached
public final boolean isCached()
Checks if theLocaleSourceobject is cached.- Returns:
trueif this object is cached;falseotherwise.
-
isReadOnly
public final boolean isReadOnly()
Checks if theLocaleSourceobject is read-only.If this is
true, creation and update operations on this object are omitted.- Returns:
trueif this object is read-only;falseotherwise.
-
store
public abstract boolean store()
Stores the locale and all attributes of the object in the actualLocaleSourceclass.This method must be implemented by the concrete classes.
- Returns:
trueif the storing operation is successful;falseotherwise
-
load
public abstract boolean load()
Loads the locale and all attributes from the actual locale source into this object.This method must be implemented by the concrete classes.
- Returns:
trueif the loading operation is successful;falseotherwise
-
setLocale
public final void setLocale(Locale locale)
Registers theLocaleobject with this object.- Parameters:
locale- theLocaleobject
-
setLocale
public final void setLocale(Locale locale, ApplicationContext appctx)
Registers the locale object in this object.- Parameters:
locale- theLocaleobjectappctx- theApplicationContextobject
-
setISOCurrency
public final void setISOCurrency(String currency)
Registers the ISO currency to store in the actualLocaleSourceclass.- Parameters:
currency- the ISO currency ID defined in ISO 4217
-
setCharacterSet
public final void setCharacterSet(String charset)
Registers the Oracle character set name to store in the actualLocaleSourceclass.- Parameters:
charset- the Oracle character set name
-
setLocaleSourceClass
public final void setLocaleSourceClass(Class loccls)
Registers the locale source class object.- Parameters:
loccls- aClassobject
-
setTimeZone
public final void setTimeZone(TimeZone tz)
Registers theTimeZoneID to store in the actualLocaleSourceclass. For example:America/Los_Angeles- Parameters:
tz- aTimeZoneobject to register
-
setDateTimeFormat
public final void setDateTimeFormat(int dtstyle, OraDateFormat dtfmt)Registers the Oracle date time format object to store in the actualLocaleSourceclass.- Parameters:
dtstyle- the date format style defined in theOraDateFormatclassdtfmt- anOraDateFormatobject
-
setDateFormat
public final void setDateFormat(int style, OraDateFormat dtfmt)Registers the Oracle date format object to store in the actualLocaleSourceclass.- Parameters:
style- the date format style defined in theOraDateFormatclassdtfmt- anOraDateFormatobject
-
setTimeFormat
public final void setTimeFormat(OraDateFormat tmfmt)
Registers the Oracle time format object to store in the actualLocaleSourceclass.- Parameters:
tmfmt- anOraDateFormatobject
-
setWritingDirection
public final void setWritingDirection(LocaleSource.WritingDirection wdir)
Registers the writing direction to store in the actualLocaleSourceclass.- Parameters:
wdir- a writing direction of text on display
-
setCurrencyFormat
public final void setCurrencyFormat(OraNumberFormat nfmt)
Registers the Oracle currency format object to store in the actualLocaleSourceclass.- Parameters:
nfmt- anOraNumberFormatobject to register
-
setNumberFormat
public final void setNumberFormat(OraNumberFormat nfmt)
Registers the Oracle number format object to store in the actualLocaleSourceclass.- Parameters:
nfmt- anOraNumberFormatobject to register
-
setCollator
public final void setCollator(OraCollator ocol)
Registers the Oracle collator to store in the actualLocaleSourceclass.- Parameters:
ocol- anOraCollatorobject to register
-
setAttribute
protected final void setAttribute(String key, Object object)
Registers an attribute object in the locale source.Used in the concrete classes to set custom attributes.
Note the attribute object must beSerializable.- Parameters:
key- aStringkey of objectobject- an object
-
getLocale
public final Locale getLocale()
Returns theLocaleobject in this object.- Returns:
Localeobject
-
getISOCurrency
public final String getISOCurrency()
Returns the ISO 4217 currency ID in this object.- Returns:
- the ISO 4217 currency ID
-
getCharacterSet
public final String getCharacterSet()
Returns the character set name in this object.- Returns:
- the character set name
-
getLocaleSourceClass
public final Class getLocaleSourceClass()
Returns the locale source class.- Returns:
- the locale source class
-
getTimeZone
public final TimeZone getTimeZone()
Returns the time zone in this object.- Returns:
- a
TimeZoneobject
-
getDateTimeFormat
public final OraDateFormat getDateTimeFormat(int style)
Returns the Oracle date and time format of the specified style in this object.- Parameters:
style- theDateformat style- Returns:
- an
OraDateFormatobject
-
getDateFormat
public final OraDateFormat getDateFormat(int style)
Returns the Oracle date format of the specified style in this object.- Parameters:
style- theDateformat style- Returns:
- an
OraDateFormatobject
-
getTimeFormat
public final OraDateFormat getTimeFormat()
Returns the Oracle time format in this object.- Returns:
- the Oracle time format
-
getWritingDirection
public final LocaleSource.WritingDirection getWritingDirection()
Returns the writing direction in this object.- Returns:
- a
WritingDirectionobject
-
getCurrencyFormat
public final OraNumberFormat getCurrencyFormat()
Returns the Oracle currency format in this object.- Returns:
- an
OraNumberFormatobject
-
getNumberFormat
public final OraNumberFormat getNumberFormat()
Returns the Oracle number format in this object.- Returns:
- an
OraNumberFormatobject
-
getCollator
public final OraCollator getCollator()
Returns the Oracle collator object.- Returns:
- an
OraCollatorobject
-
getAttribute
protected final Object getAttribute(String key)
Returns the attribute object.Used in the concrete classes to retrieve custom attributes. Note the attribute object must be
Serializable.- Parameters:
key- aStringkey of object- Returns:
- an
Objectassociated with thekey
-
equals
public boolean equals(Object o)
Determines if a specific object is equal to this object.
-
-