Home of: [Atelier "FUJIGURUMA"] >> [PageMixer hosted by SourceForge.net]

SEE "For Readers of English Version",
or Japanese version of this page

Combine filters

This section explains how to combine filters to treat them as one filter in PageMixer framework.


Class diagram

Class diagram in this section is shown below:

Class diagram
Class diagram (click for large figure)

Classes which you must define are colored, and other are already defined.

Object diagram

Object diagram in this section is shown below:

Object diagram
Object diagram (click for large figure)

Class names

In this tutorial, abbreviated class names are used. Complete names are shown below.

Classes of PageMixer framework

NotationFull 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

Tutorial specific classes

NotationFull 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.

Extend 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)

        push(new BasketEntryIterationFilter(providerKey,
        push(new BasketTotalTextInsetFilter(providerKey));

Extends FilterPipeline

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.

Connect and mix

Now, everything needed are ready to use. Execution code is as below (see BasketFilter for detail).

    // key to set/get DataProvider
    final Object providerkey =

    // key to set/get provided data
    final Object dataKey =

    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
catch(Exception e){
Connect and Mix

Sample HTML file as input is "basket.en.html" under "src/demo/servlet/war/WEB-INF/page/demosite" in distribution.

To next section "Combine efficiently"