org.inria.ns.reflex.xml.filter
Class AbstractFilter

java.lang.Object
  extended by org.inria.ns.reflex.xml.filter.AbstractFilter
All Implemented Interfaces:
Filter, RuleBasedFilter, RunnableRuleBasedFilter
Direct Known Subclasses:
DOMFilter

public abstract class AbstractFilter
extends Object
implements RunnableRuleBasedFilter

Filters an XML entry thanks to a set of rules (XPath patterns, regular expressions, CSS selectors, etc).

This class is the skeleton implementation of runnable rule-based filters for SAX and DOM inputs.

The entry point of this class should be applyFilter(Object) with the document node (DOM or SAX) as the argument ; before invoking this method, an XML context (the #main channel to write to) must be put in the current context of the dataset.

Author:
Philippe Poulard
See Also:
XPathFilter, XMLContext

Constructor Summary
AbstractFilter(List rules, boolean normalize, PatternContext context, FilterContextFactory filterContextFactory)
          Create a new filter.
AbstractFilter(RuleBasedFilter filterDef, boolean normalize, PatternContext context)
          Create a new filter.
 
Method Summary
 void applyFilter(Object node)
          Apply the filter on a node : test if a rule is appliable.
 FilterContextFactory getFilterContextFactory()
          Return the filter context factory.
 PatternContext getPatternContext()
          Return the context that this filter will use.
 List getRules()
          Return the list of rules used by this filter.
 boolean normalize()
          Indicates what is the default behaviour regarding text normalization.
abstract  void normalize(Object node)
          Normalize the node : adjacent text nodes are merged.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.inria.ns.reflex.xml.filter.RunnableRuleBasedFilter
applyRules, forward, ignore
 

Constructor Detail

AbstractFilter

public AbstractFilter(List rules,
                      boolean normalize,
                      PatternContext context,
                      FilterContextFactory filterContextFactory)
Create a new filter.

*** The rules MUST have been sorted previously. This filter doesn't sort the rules by itself. ***

Parameters:
rules - The list of sorted rules.
normalize - The default value for text normalization if not specified at rule level.
context - The context to use when running rules.
filterContextFactory - The factory that can create a new filter context.
See Also:
Rule, Rule.COMPARATOR

AbstractFilter

public AbstractFilter(RuleBasedFilter filterDef,
                      boolean normalize,
                      PatternContext context)
Create a new filter.

*** The rules MUST have been sorted previously. This filter doesn't sort the rules by itself. ***

Parameters:
filterDef - The definition of the filter that contains the list of sorted rules.
normalize - The default value for text normalization if not specified at rule level.
context - The context to use when running rules.
See Also:
Rule, Rule.COMPARATOR
Method Detail

applyFilter

public void applyFilter(Object node)
                 throws PatternEvaluationException,
                        ExecutionException
Apply the filter on a node : test if a rule is appliable.

***

The candidate rules are the rules held by this filter + the default rules.

If no user-specific rule is appliable, the default rule is applied.

***

Specified by:
applyFilter in interface RunnableRuleBasedFilter
Parameters:
node - The candidate node.
Throws:
ExecutionException
PatternEvaluationException
See Also:
Rule, Rule.DEFAULT_RULES, Node, SAXNode

normalize

public boolean normalize()
Indicates what is the default behaviour regarding text normalization.

This is the default behaviour specified at the filter level, that might be override at the rule level. If a rule doesn't specify a behaviour, this value will be used.

Specified by:
normalize in interface RuleBasedFilter
Returns:
true if text nodes must be normalized by default, false otherwise.
See Also:
RuleBasedFilter.normalize()

normalize

public abstract void normalize(Object node)
Normalize the node : adjacent text nodes are merged.

Parameters:
node - Merge the adjacent text nodes of the children of that node.

getRules

public List getRules()
Return the list of rules used by this filter.

Specified by:
getRules in interface RuleBasedFilter
Returns:
The non-null list of rules used by this filter.
See Also:
getRulesIterator(), Rule

getPatternContext

public PatternContext getPatternContext()
Return the context that this filter will use.

Returns:
The context.

getFilterContextFactory

public FilterContextFactory getFilterContextFactory()
Return the filter context factory.

Specified by:
getFilterContextFactory in interface RuleBasedFilter
Returns:
The filter context factory.
See Also:
RuleBasedFilter.getFilterContextFactory()