-
Notifications
You must be signed in to change notification settings - Fork 118
JDOM2 Feature Outputter Updates
The internals of XMLOutputter have been completely reworked. The public API itself is unchanged, but the implementation has been modified to meet the following goals:
- Consistency of output - Make XMLOutputter, DOMOutputter, SAXOutputter, and the new StAXOutputters produce the same results with the same inputs (Only the XMLOutputter supported the 'Format' concept in JDOM 1.x).
- Support output to StAX Streams
- Implement basic functionality - changing the way that Namespaces are output (the order of presentation) was hard to do without deep changes.
- Consistency of subclass-interface - people wanting to subclass the XMLOutputter had a real challenge finding the right hooks. The hooks for the XMLOutputter were different to the hooks for the other Outputters.
- Simplify the implementations - XMLOutputter (DOM and SAX Outputters were very rudimentary in comparison) contained three distinct concepts all mixed together: handling the actual output; formatting the output; and managing the input state.
- Improve the performance of the Outputters
The end result of the changes to the Outputters are that:
- All the outputters support the Format concept.
- All the outputters have similar hooks for customizing functionality.
- The managing of the intput data, the data formatting, and the output target are independant code items
Th change has a significant impact on people who sub-class the XMLOutputter, but the benefit on the subclassing-API is significant.
All the Outputers now share a common model. There is the client side API for the Outputter, and this API is given an implementation of an specific Outputter which does the actual work. The JDOM code supplies a default implementation that can be overriden to customize your output, if necessary. The output implementation is responsible for interfacing to the output destination, but it delegates the management of the input data, formatting, and other administration to existing JDOM classes.
An example is useful. The XMLOutputter is the client-side API for outputting JDOM content to an OutputStream or Writer (or String). The XMLOutputter does some simple client-side validation and handling (converts output String and OutputStream targets to simple Writer targets), and delegates the real work to the XMLOutputProcessor implementation. There is a default implementation called AbstractXMLOutputProcessor that does the real interface to the output Writer. The AbstractXMLOutputProcessor contains the actual output code, but it delegates the management of the formatting of the XML, and the handling of the Namespace stack to classes like the FormatStack, NamespaceStack, Walkers, and EscapeStrategy.
All the Outputters (XMLOutputter, DOMOutputter, SAXOutputter, StAXEventOutputter, and StAXStreamOutputter) use the same model for outputting data to their respective targets. Customizing the Outputters is thus a whole lot easier than JDOM 1.x.
JDOM 2.x now effectively differentiates between 5 areas of code required for output of JDOM content to some target destination. The following list identifies the 5 areas, and the code that performs the appropriate function:
- Managing Namespaces -
NamespaceStack
- Managing format configuration (indenting, etc.) -
Format
andFormatStack
. - Applying formatting to the output -
Walker
. - Escaping the output appropriately -
EscapeStrategy
- Managing the output process, and delivering the output to the target destination -
*OutputProcessor
.
This process allows the default system to implement high-performance and reusable classes for output, while at the same time making it easier to subclass and customize the output if you need to.
It is now possible to create a new formatter, and apply the same formatter (Walker) to any of the 5 output targets. Additionally, it is possible to create a new type of output target without having to worry about the actual formatting of the XML.
[JDOM Home](http://www.jdom.org)
Stable Release
- [Download](http://www.jdom.org/downloads/index.html)
- [JavaDoc](http://www.jdom.org/docs/apidocs/index.html)
JDOM 2.x
- Overview
- Getting Started
- JDOM on Android
- [JavaDoc](http://hunterhacker.github.com/jdom/jdom2/apidocs/index.html)
- [Coverage](http://hunterhacker.github.com/jdom/jdom2/coverage/index.html)
- [UnitTests](http://hunterhacker.github.com/jdom/jdom2/junit.report/index.html)
- Features
- JDOM 1.x to JDOM 2.x
- Dependencies
Developing JDOM