The SAX Filter Framework enables the creation of robust, complex XML
processing applications using the SAX API.
Loading SAX Pipelines
Using a pipeline configuration file to create a usable SAX construct
consists of three steps.
- Use the {@link com.puck.saxfilter.PipelineBuilder} to load
the pipeline configuration into a {@link
com.puck.saxfilter.PipelineConfig} object.
- Create a {@link com.puck.saxfilter.PipelineContext} object
and load it with the runtime parameters for the pipeline.
- Call {@link
com.puck.saxfilter.PipelineConfig#instantiate(com.puck.saxfilter.PipelineContext)}
to create a configured {@link com.puck.saxfilter.FilterChain}.
The resulting
FilterChain
object can be used in one of two ways.
- The filter geometry can be exercised in a standalone way by
calling {@link com.puck.saxfilter.FilterChain#execute()}.
- Because the
FilterChain
implements the org.xml.sax.XMLFilter
interface, the chain can be plugged into other SAX-based
applications.
PipelineConfig cfg = PipelineBuilder.buildPipeline(pipelineFile);
PipelineContext cxt = new PipelineContext();
cxt.addParameter("foo", "bar");
FilterChain fc = cfg.instantiate(cxt);
fc.execute();
Developing Filters
In theory, any Java class implementing the org.xml.sax.SAXFilter
interface
could be used as a filter in a pipeline. However, in practice, it is preferable for custom
filters to implement the {@link com.puck.saxfilter.SAXFilter} interface, which
provides some additional methods ensuring full coverage of the various SAX interfaces.
The framework provides a number of base classes that can be used to simplify new
filter development.
- {@link com.puck.saxfilter.BaseFilterImpl} - A basic
passthroug SAX filter.
- {@link com.puck.saxfilter.SAXEventDelegator} - Provides a
mechanism to deal with SAX events as objects instead of method calls.
- {@link com.puck.saxfilter.buffer.SAXEventBuffer} - Provides
event buffering support.