| MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Create 'Filter's | << | >> |
This section explains
how to customzie Filter creation
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 |
|---|---|
| ConsumerContext | jp.ne.dti.lares.foozy.pagemixer.mixer.ConsumerContext |
| Filter | jp.ne.dti.lares.foozy.pagemixer.mixer.Filter |
| FilterFactory | jp.ne.dti.lares.foozy.pagemixer.servlet.FilterFactory |
| FilterPipeline | jp.ne.dti.lares.foozy.pagemixer.mixer.FilterPipeline |
| PageServlet | jp.ne.dti.lares.foozy.pagemixer.servlet.PageServlet |
| Notation | Full name |
|---|---|
| CommonFilter | pagemixer.filter.CommonFilter |
Separating Filter creation from HTTP response renderring
allows you to:
Filter.FactoryPageMixer provides "FilterFactory"
for customization of Filter creation.
But in fact,
Filter which
FilterFactory default implementation
create directly is only FilterPipeline.
It pushes Filter created by
"Filter.Factory"s,
which are registered to itself,
into FilterPipeline.
Filter.Factory has the method
to accept creation request as shown below.
public Filter create(ConsumerContext context)
createYou can get runtime information
(e.g.: Servlet/web application initialization parameter)
via specified ConsumerContext
to create Filter.
ATTENTION:
For Filter creation cost reduction,
PageServlet invokes create method
only once per thread.
So, you must not use request or session wide information
to create Filter.
Implementation example is shown below.
public Filter create(ConsumerContext context){
return new CommonFilter();
}
Filter.FactoryIt is good idea to define Filter.Factory implementation classes
as inner class of each custom Filter classes
for maintenance.
Please see API document for detail to
implement Filter.Factory and/or
override FilterFactory.
FilterFactory accepts
Servet initialize parameter(s) shown below:
| name | description |
|---|---|
filter.factory.N |
name of Filter.Factory implement class.
"N" is 0 origin number.
you can specify multiple Filter.Factorys. |
To use your custom FilterFactory,
you should specify "servlet.filterFactory"
Servlet init-param in deployment descriptor
as shown below.
<init-param>
<param-name>
servlet.filterFactory
</param-name>
<param-value>
name of your custom FilterFactory
</param-value>
</init-param>
FilterFactory| MAP | PageMixer Documents > Tutorial > Mixing with Servlet > Create 'Filter's | << | >> |