Styler Customisation

Processors to handle additional file and transform types may be added relatively easily if they have SAX interfaces. The steps are:

  1. Wrap the additional parser, transformer or serializer implementation in the appropriate interface.
  2. Deploy its in a jar file in the ant lib directory or elsewhere on Ant's classpath.
  3. Register the implementation with one or more file or transform types in the type.properties file.

Interfaces

The interfaces that the styler task uses for various purposes are:

Purpose Styler Element Interface
Parser

<input type="X" file="f.X"/>

org.xml.sax.XMLReader
Transformer (hard coded) <transform type="X"/> org.xml.sax.XMLFilter
Serializer <output type="X" file="f.X"/> au.com.Langdale.sax.XMLWriter
Template <transform type="X" file="f.X"/> au.com.Langdale.sax.XMLTemplate

The latter two interfaces are SAX extensions explained (or justified?) below and in the javadoc.

A custom processor is required to implement the indicated interface and must provide a no-arg constructor.

In the case of transformers, there are two options. A class that performs a specific, hard-coded transformation is easy to add. It is just an XMLFilter.

A transformer that is driven by a rules file is slightly more complicated. It may require as many as three components:

The template and (optional) rule parser are registered in type.properties but the transformer (XMLFilter) is not. (Instances of the transformer are created by the template.)

Registering Types

Each implementation is registered against the interface it supports and the file or transform type it supports. The following line is added to the type.properties file in the au.com.Langdale.styler package:

interfacename-mytype: myclass

Where:

See also the comments in the type.properties file.

SAX Use and Abuse

All input and transform rule files are read by SAX XMLReader classes. Any file format could be accommodated provided it can be converted to SAX events. Such is the power of SAX.

Transforms are performed by XMLFilter instances. This makes it easy to implement simple, hard-coded transformers, which was a goal.

But, you cannot set a stylesheet parameter on an XMLFilter. And the TraX API used in Xalan provides no help here either. There is no TraX API to prime an XMLFilter with a parameter value. We ended up introducing two custom interfaces:

Wrappers bridging these to the TrAX equivalents were then implemented.

Output is generated by SAX XMLFilter classes which are configured with a parent but no children. Again, a custom interface, XMLWriter, was introduced that extends XMLFilter to set the output. This interface (au.com.Langdale.sax.XMLWriter) is patterned on Megginson's XMLWriter implementation (a class, not an interface).


Copyright 2001, 2002 Langdale Consultants
Contact Arnold deVos for further information.