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

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

'NOP' filter

This section explains how to parse and render HTML page 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)

Sequence diagram

Processing flow of parsing and renderring of HTML page is shown as below:

  1. create your specific Filter
  2. create Renderer instance
  3. get(or create) Producer instance
  4. create ConsumerContext instance
  5. connect your Filter to Renderer
  6. invoke Producer#produce with Filter and ConsumerContext

And sequence diagram after Producer#produce invocation is shown below.

Sequence diagram
Sequence 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
Filter jp.ne.dti.lares.foozy.pagemixer.mixer.Filter
HashMapConsumerContext jp.ne.dti.lares.foozy.pagemixer.mixer.HashMapConsumerContext
LoosePageState jp.ne.dti.lares.foozy.pagemixer.parser.LoosePageState
PageParser jp.ne.dti.lares.foozy.pagemixer.mixer.PageParser
PageState jp.ne.dti.lares.foozy.pagemixer.parser.PageState
Producer jp.ne.dti.lares.foozy.pagemixer.mixer.Producer
Renderer jp.ne.dti.lares.foozy.pagemixer.mixer.Renderer
Token jp.ne.dti.lares.foozy.pagemixer.Token

Tutorial specific classes

NotationFull name
Bootstrap pagemixer.filter.Bootstrap
Bootstrap.Default pagemixer.filter.Bootstrap.Default
NopFilter pagemixer.filter.NopFilter

Define 'NOP' filter

At first, define filter which does nothing(NOP:No OPeration) but passes token sequence to connected consumer.

public class NopFilter
    extends Filter
    public NopFilter(){ super(); }

    public void consume(ConsumerContext context, Token token){
        getConsumer().consume(context, token);

    public void flush(ConsumerContext context){
NopFilter class

Both "consume" and "flush" methods only invoke same signature method of Consumer to which it is connected.

NOTE: In fact, that kind filter is already defined as "DefaultFilter", and you should use it if you need 'NOP' filter.

Create Renderer

In PageMixer framework, HTML page is treated as Token sequence. But string(or byte-stream) representation must be needed to show HTML page as result of processing.

"Renderer" class renders token sequence on java.io.Writer specified at construction. For example, Renderer writing on standard-out is created by:

Renderer renderer =
new Renderer(new OutputStreamWriter(System.out));

Renderer writing on standard-out

Create Producer

Once again, In PageMixer framework, HTML page is treated as "Token" sequence. So you must get "Producer", the provider of token sequence.

There is very easy way to create Producer which provides token sequence representing specified HTML page. It is to use "PageParser" and "LoosePageState".

LoosePageState pageState = new LoosePageState();
PageParser parser = new PageParser(pageState);
Producer producer = parser.parse(filename);

Producer creation

Variable "filename" contains filename of HTML page.

ATTENTION: "LoosePageState" is sample implementation of "PageState" interface, its name "Loose" comes from "Syntactically Loose".

This implementation allows invalid tag structure, 'table' under 'h1' for example, so you should not expect it to tell HTML source invalidity.

Create ConsumerContext

"ConsumerContext" is created for dynamic values and inter-filter communication.

For stand-alone environment, there is "HashMapConsumerContext" class which implements ConsumerContext interface with java.util.HashMap, and you can create it as below:

HashMapConsumerContext context = 
new HashMapConsumerContext();

ConsumerContext creation

To know how to create this(or what class you should use) is important even though nothing needs this "context" in this section.

Connect and mix

Now, everything needed are ready to use. To parse and render HTML page, you should do only below steps.

  1. create NopFilter
  2. connect NopFilter to Renderer
  3. invoke Producer#produce with NopFilter and ConsumerContext

NopFilter filter = new NopFilter(); // --- (1)
filter.connectTo(renderer); // --- (2)

producer.produce(context, filter); // --- (3)

Connect and (Nop)Mix

In fact, utility class "Bootstrap", or its derived classes, assists each steps described from "Create Renderer" to "Connect and Mix"(this sub section).

You can get rendered HTML page from standard-out by as below.

  1. Create instance of "Bootstrap.Default" with filename of HTML page to parse
  2. invoke "execute(Filter)" with your specific Filter

Execution code is as below (see pagemixer.filter.NopFilter for detail).

    Bootstrap bootstrap =
    new Bootstrap.Default(filename);

    bootstrap.execute(new NopFilter());
catch(Exception e){
Bootstrap with Bootstrap class

To next section "Trim token"