|
Oracle® Database Globalization Development Kit Java API Reference 10g Release 2 (10.2) Part No. B14224-02 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.i18n.servlet.ServletHelper
The ServletHelper
class is a delegate class that provides a
bridge between Java servlets and globalization objects. All operations that
involve Java servlets are performed using this class.
In order to enable a J2EE based Web application to use the GDK framework, it is necessary to configure a GDK filter and a listener in the application deployment descriptor file web.xml. This allows the GDK framework to be hooked into the Web application. See the sample web.xml descriptor file below.
First the GDK filter is configured in the deployment descriptor file,
whose purpose is to instantiate the GDK wrappers for HTTP requests and
responses. The GDKFilter filter specifies the
oracle.i18n.servlet.filter.ServletFilter Javaclass for use as
the GDK filter. Additionally, the GDK default listener is configured
that instantiates the GDK ApplicationContext
object,
that controls application scope operations for the framework. In
this case the Java class oracle.i18n.servlet.listener.ContextListener
is configured as the listener.
<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>web.xml file for enabling GDK in the application</description>
<!-- Enable the application to use the GDK Application Framework.-->
<filter>
<filter-name>GDKFilter</filter-name>
<filter-class>oracle.i18n.servlet.filter.ServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>GDKFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<listener>
<listener-class>oracle.i18n.servlet.listener.ContextListener</listener-class>
</listener>
....
<session-config>
<session-timeout>35</session-timeout>
</session-config>
....
</web-app>
Once the GDK framework has been enabled for your application, you need to configure its behavior via the use of the gdkapp.xml framework configuration file. The complete steps on how to enable the GDK framework within your application and its configuration is documented in the Oracle Database Globalization Support Guide.
The GDK application framework is driven by the application configuration
file, which by default is gdkapp.xml and resides in the same
directory as the web.xml file. See below for a sample listing
of the gdkapp.xml file, which shows configuration of the most
applicable elements for J2EE applications. The
<application-locales>
section is used to declare all the
locales that the application supports, so they don't have to be hard
coded somewhere, plus can be accessed from the application in a generic
manner via the GDK API. The <locale-determine-rule>
section is used to define locale sources in priority order, as to the
sources that supply locale preferences. See the
LocaleSource
class for more
information. Finally, the message resource bundles allow a GDK
application access to localized static content that may be displayed
in a web page. They are declared using the
<message-bundles>
section. In this case the message
bundle named Messages, is declared as the default application
resource bundle. The
Localizer
class exposes methods to
retrieve localized messages from the declared resource bundles.
The GDK configuration file – gdkapp.xml
<?xml version="1.0" encoding="UTF-8"?>
<gdkapp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="gdkapp.xsd">
<!-- All pages are generated using the UTF-8 encoding -->
<page-charset default="yes">UTF-8</page-charset>
<!-- The application locale list for the Web application, i.e. -->
<!-- all the locales that are supported by the application. -->
<application-locales>
<locale>de-CH</locale>
<locale default="yes">en-US</locale>
<locale>zh-CN</locale>
</application-locales>
<locale-determine-rule>
<locale-source>
oracle.i18n.servlet.localesource.UserInput
</locale-source>
<locale-source>
oracle.i18n.servlet.localesource.HttpAcceptLanguage
</locale-source>
</locale-determine-rule>
<!-- Declare a default application resource bundle that -->
<!-- supplies all the messages to the application. -->
<message-bundles>
<resource-bundle name="default">
com.oracle.demo.Messages
</resource-bundle>
</message-bundles>
</gdkapp>
Method Summary | |
static oracle.i18n.servlet.ApplicationContext |
getApplicationContextInstance(HttpServletRequest request)
Returns an ApplicationContext object associated with the
Web application. |
static oracle.i18n.servlet.localesource.LocaleSource |
getLocaleSourceInstance(HttpServletRequest request)
Returns a LocaleSource object associated with the HTTP
request object. |
static oracle.i18n.servlet.Localizer |
getLocalizerInstance(HttpServletRequest request)
Returns a Localizer object derived from the HTTP request
object. |
static void |
refreshLocales(HttpServletRequest request)
Refreshes the locale objects associated with the request. |
static String |
rewriteURL(String baseURL,
HttpServletRequest request)
Rewrites a URL based on the rules specified in the GDK application configuration file. |
static String |
rewriteURL(String baseURL,
String name,
HttpServletRequest request)
Rewrites a URL based on the rules specified in the GDK application configuration file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static oracle.i18n.servlet.ApplicationContext getApplicationContextInstance(HttpServletRequest request)
ApplicationContext
object associated with the
Web application.
request
- an HTTP request object
ApplicationContext
object
IllegalArgumentException
- if ApplicationContext
cannot be instantiatedpublic static oracle.i18n.servlet.localesource.LocaleSource getLocaleSourceInstance(HttpServletRequest request)
LocaleSource
object associated with the HTTP
request object. This associated locale source is determined by
the ServletRequestWrapper as part of the GDK framework functionality.
request
- an HTTP request object
LocaleSource
objectpublic static oracle.i18n.servlet.Localizer getLocalizerInstance(HttpServletRequest request)
Localizer
object derived from the HTTP request
object. The Localizer's properties are based on the locale source
object associated with the request.
request
- an HTTP request object
Localizer
objectpublic static String rewriteURL(String baseURL, HttpServletRequest request)
baseURL
- a URL stringrequest
- an HTTP request object
rewriteURL(String, String, HttpServletRequest)
public static String rewriteURL(String baseURL, String name, HttpServletRequest request)
For example, if localized contents are supplied in
/images/es/welcome.jpg
for Spanish and
/images/ja/welcome.jpg
for Japanese locales, the
baseURL
would be /images/welcome.jpg
, and the
rule defined in the regular expression should be
"(.)/([^\/]+)$"
in order that the URL be
replaced with the string "$1/$A/$2"
.
baseURL
- a URL stringname
- the name of the rewrite URL rulerequest
- an HTTP request object
IllegalArgumentException
- if invalid regular expression is
specifiedpublic static void refreshLocales(HttpServletRequest request)
By calling this method, you can explicitly refresh the locale objects
associated with the request. With the servlet authentication, usually
it performs the FORWARD
operation to jump to the success
page or the failure page based on the results of authentication.
However, because the FORWARD
operation
does not involve the servlet filter, GDK cannot
refresh the locale information after the authentication. Instead, the
page after the success page will take the effect. This method resolves
this issue and provides the flexibility of taking advantage of GDK
locale determination feature.
For struts framework, the session attribute Action.LOCALE_KEY
is updated.
request
- an HTTP request object
|
Oracle® Database Globalization Development Kit Java API Reference 10g Release 2 (10.2) Part No. B14224-02 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |