MAP | PageMixer Documents > Tutorial > Mixing with PageMixer > Combine filters | << | >> |
This section explains how to combine filters to treat them as one filter in PageMixer framework.
Class diagram in this section is shown below:
Classes which you must define are colored, and other are already defined.
Object diagram in this section is shown below:
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 |
DataProvider | jp.ne.dti.lares.foozy.pagemixer.mixer.DataProvider |
Filter | jp.ne.dti.lares.foozy.pagemixer.mixer.Filter |
FilterPipeline | jp.ne.dti.lares.foozy.pagemixer.mixer.FilterPipeline |
Renderer | jp.ne.dti.lares.foozy.pagemixer.mixer.Renderer |
Notation | Full name |
---|---|
BasketFilter | pagemixer.filter.BasketFilter |
BasketEntryIterationFilter | pagemixer.filter.BasketEntryIterationFilter |
BasketTotalTextInsetFilter | pagemixer.filter.BasketTotalTextInsetFilter |
Bootstrap | pagemixer.filter.Bootstrap |
For example, it assumed that there are some classes of filter for "Shopping basket" part of HTML page.
If these filters are treated each other separatelly, you must construct these in step by step.
It seems to be good idea
to define the utility method
which returns filters already connected to each other,
but you can not connect "last filter" to Renderer
if it returns "first filter" object only.
Keeping filters as "fine grain" means that required function consists of many filters. And so, easyness of handling filter collection is needed.
FilterPipeline
For filter combination to treat them as one filter,
PageMixer framework provides
"FilterPipeline
" class.
It connects the filters pushed to it internally,
and provides the token sequence, which it is given, to them.
Because it is also derived class of Filter
,
it provides the token sequence, which is processed by pushed filters,
to the filter to which it is connected.
And you can treat FilterPipeline
as a Filter
.
The filter to combine filters for "Shopping basket" part of HTML page is defined as below.
public class BasketFilter extends FilterPipeline { public BasketFilter(Object providerKey, Object dataKey) { super(); push(new BasketEntryIterationFilter(providerKey, dataKey)); push(new BasketTotalTextInsetFilter(providerKey)); } }
BasketEntryIterationFilter
is explained
in "Iterate sub-sequence" section.
"BasketTotalTextInsetFilter
" is filter
which insets total price of all items provided
by DataProvider
.
It is so simple and easy
to understand with knowledge of earlier sections
that this section omits explanation of it.
Please see source files directly for detail.
Now, everything needed are ready to use. Execution code is as below (see BasketFilter for detail).
try{ // key to set/get DataProvider final Object providerkey = "Shop.Basket.BasketEntryProvider"; // key to set/get provided data final Object dataKey = "Shop.Basket.BasketEntry"; Bootstrap bootstrap = new Bootstrap.Default(filename) { protected void prepare(ConsumerContext context) { List entryList = BasketEntry.getEntryList(); ListDataProvider provider = new ListDataProvider(entryList); // put DataProvider into context context.setValue(providerKey, provider); } }; BasketFilter filter = new BasketFilter(providerKey, dataKey); // apply the filter bootstrap.execute(filter); } catch(Exception e){ e.printStackTrace(System.err); }
Sample HTML file as input is "basket.en.html
"
under "src/demo/servlet/war/WEB-INF/page/demosite
"
in distribution.
MAP | PageMixer Documents > Tutorial > Mixing with PageMixer > Combine filters | << | >> |