PageMixer API - 3.1

jp.ne.dti.lares.foozy.pagemixer.mixer
Interface SequenceWatcher

All Known Implementing Classes:
SequenceWatcher.NameBased

public interface SequenceWatcher

Abstraction of token sequence watching.

This interface separates "judgement whether you have interest in current token sequence" from "processing which you want do on them".

"Token sequence" means the part of token stream consisting of one or more tokens (e.g.: tokens between StartTagToken representing "<div>" to EndTagToken representing "</div>").

Even though primitive inner classes are defined, you can create your specific watcher like as below:

See Also:
SequenceEditFilter, TokenWatcher, TokenEditFilter

Inner Class Summary
static class SequenceWatcher.Attr
          Find sequences by attribute of token.
static class SequenceWatcher.Name
          Find sequences by name of token.
static class SequenceWatcher.NameAttr
          Find sequences by name and attribute of token.
static class SequenceWatcher.NameBased
          Template of name based sequence watcher.
 
Method Summary
 void clear()
          Clear internal status to reuse itself.
 boolean gainsInterest(ConsumerContext context, Token token)
          Examine whether specified token is first one of interest sequence.
 boolean losesInterest(ConsumerContext context, Token token)
          Examine whether specified token is last one of interest sequence.
 

Method Detail

gainsInterest

public boolean gainsInterest(ConsumerContext context,
                             Token token)
Examine whether specified token is first one of interest sequence.

This method is never invoked until losesInterest() returns true after once this returns true.

ATTENTION:

The token with which this method returns true is included by "sequence" as part of it.

Parameters:
context - context to depend on
token - token to be examined
Returns:
whether given token is first one of target sub sequence.

losesInterest

public boolean losesInterest(ConsumerContext context,
                             Token token)
Examine whether specified token is last one of interest sequence.

This method is not invoked before gainsInterest() returns true, but invoked on the same token which causes gainsInterest() returning true.

You can implement watcher which returns true both gainsInterest() and this on the same token. In this case, the "interest sequence" consists of only one token.

ATTENTION:

The token with which this method returns true is included by "sequence" as part of it.

Parameters:
context - context to depend on
token - token to be examined
Returns:
whether given token is last one of target sub sequence.

clear

public void clear()
Clear internal status to reuse itself.

This is invoked at the end of token (sub)sequence (= when associated filter is flushed), or at the invocation of Filter.clear().

This allows you to re-use watcher instance after invocation of this method even though it is context-full.

Since:
PageMixer 2.0

PageMixer API - 3.1