| MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Determine page information | << | >> |
This section explains
how to customize determining page information
(resource location, content type, ....)
with PageServlet.
Class diagram in this section is shown below:
Classes which you must define are colored, and other are already defined.
In this tutorial, abbreviated class names are used. Complete names are shown below.
| Notation | Full name |
|---|---|
| DefaultPage | jp.ne.dti.lares.foozy.pagemixer.page.DefaultPage |
| DefaultPageFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.DefaultPageFactory |
| I18NDefaultPage | jp.ne.dti.lares.foozy.pagemixer.page.I18NDefaultPage |
| I18NDefaultPageFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.I18NDefaultPageFactory |
| LocalePage | jp.ne.dti.lares.foozy.pagemixer.page.LocalePage |
| LocalePageFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.LocalePageFactory |
| MonoPage | jp.ne.dti.lares.foozy.pagemixer.page.MonoPage |
| MonoPageFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.MonoPageFactory |
| Page | jp.ne.dti.lares.foozy.pagemixer.page.Page |
| PageFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.PageFactory |
| PageServlet | jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet |
No tutorial specific class is explained in this section.
Please see "Render locale sensitively" section for detail about 'page' information management.
PageFactory implementationPageMixer provides
"PageFactory" for
customization of determining 'page' information.
In addition to it,
PageMixer almost provides
concrete classes derived from PageFactory,
which use one of MonoPage,
LocalePage or DefaultPage
(also I18NDefaultPage described below, in fact).
You will find classes corresponded to them out easily,
because they PageFactory classes
contains the name of corresponded Page implementation
in their own name.
Please see API document and source code of them
about detail to define custom concrete PageFactory,
even though you may satisfy your needs by pre-defined classes
in almost all cases.
I18NDefaultPage for real locale sensitivityIn fact,
I think that
I can map DefaultPage
for multiple locales
by configuration shown below,
at first.
<servlet-mapping>
<servlet-name>en.DefaultPage</servlet-name>
<url-pattern>*.en.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ja.DefaultPage</servlet-name>
<url-pattern>*.ja.html</url-pattern>
</servlet-mapping>
In above example,
"ja.DefaultPage" is Servlet using DefaultPage
which is configured with "text/html; charset=Windows-31J" content type and
"Windows-31J" encoding
("en.DefaultPage" is as same).
I expected ja.DefaultPage to be invoked
for "*.ja.html" request,
and en.DefaultPage to be invoked
for "*.en.html" request.
But Servlet specification(version 2.3) says that:
the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last "." character.chapter SRV 11.1 "Mapping Requests to Servlets"
So, PageMixer provides
"I18NDefaultPage" for
multi-locale DefaultPage.
Configuration example is shown below (and this only focuses on mapping between URI suffix and content type).
<servlet>
<servlet-name>DefaultPage</servlet-name>
<servlet-class>
jp.ne.dti.lares.foozy.pagemixer.servlet.I18NDefaultPageServlet
</servlet-class>
<!-- default configuration -->
<init-param>
<param-name>page.contentType</param-name>
<param-value>text/html; charset=iso-8859-1</param-value>
</init-param>
<!-- configuration for "*.ja.html" suffix -->
<init-param>
<param-name>page.suffix.0</param-name>
<param-value>.ja.html</param-value>
</init-param>
<init-param>
<param-name>page.contentType.0</param-name>
<param-value>text/html; charset=Windows-31J</param-value>
</init-param>
<!-- configuration for "*.en.html" suffix -->
<init-param>
<param-name>page.suffix.1</param-name>
<param-value>.en.html</param-value>
</init-param>
<init-param>
<param-name>page.contentType.1</param-name>
<param-value>text/html; charset=iso-8859-1</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DefaultPage</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
I18NDefaultPage configurationThis configuration makes I18NDefaultPage
to recognize "*.ja.html" requests as one requiring
"text/html; charset=Windows-31J",
"*.en.html" and the other as one requiring
"text/html; charset=iso-8859-1".
Is this complex, is not it? Yes, I think so too. But I also think that this configuration style balances well between simpleness and customizability.
PageFactory itself does not require any parameters,
but derived classes require/accept some parameters.
MonoPageFactoryMonoPageFactory accepts(or requires) below parameters,
and all of these are used to construct MonoPage.
| name | description |
|---|---|
page.location |
location of resource.(optional) |
page.contentType |
content type of HTTP response. |
page.encoding |
encoding of resource.(optional) |
LocalePageFactoryLocalePageFactory accepts(or requires) below parameters,
and all of these are used to construct LocalePage.
| name | description |
|---|---|
page.location |
base name of ResourceBundle
to read locale sensitive information in. |
DefaultPageFactoryDefaultPageFactory accepts(or requires) below parameters,
and all of these are used to construct DefaultPage.
| name | description |
|---|---|
page.contentType |
content type of HTTP response |
page.encoding |
encoding of resources.(optional) |
I18NDefaultPageFactoryI18NDefaultPageFactory also accepts(or requires)
below parameters other than ones for DefaultPageFactory,
and all of these are used to construct I18NDefaultPage.
| name | description |
|---|---|
page.suffix.N |
suffix of this I18N mapping entry. "N" is 0 origin number. |
page.contentType.N |
content type of HTTP response for corresponded suffix. |
page.encoding.N |
encoding of resources for corresponded suffix(optional). |
You should not (and can not)
specify name of concrete PageFactory class
which you choose,
when you use (1)one of pre-defined classes
(MonoPageServlet,
LocalePageServlet,
DefaultPageServlet or
I18NDefaultPageServlet)
or classes derived from them, or
(2)class which specifies non-null concrete PageFactory object
at invocation of base class constuctor.
Otherwise,
because PageFactory configuration can not decide
"default implementation",
you should specify "servlet.pageFactory"
Servlet init-param in deployment descriptor
as shown below.
<init-param>
<param-name>
servlet.pageFactory
</param-name>
<param-value>
jp.ne.dti.lares.foozy.pagemixer.servlet.MonoPageFactory
</param-value>
</init-param>
PageFactory| MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Determine page information | << | >> |