[jdom-interest] using XMLFilter
Joseph Bowbeer
jozart at csi.com
Sat Jul 14 03:51:51 PDT 2001
Bruce Ritchie writes:
> Something isn't missing, the SAXBuilder class is broken.
> Take the [installFilter] from configureParser and stick it at the
> end of createParser(just before the return parser; statement.
I suggest moving the installFilter part into build(InputSource), after
createParser() and before configureParser(XMLReader), as follows:
public Document build(InputSource in) throws JDOMException {
SAXHandler contentHandler = null;
try {
// Create and configure the content handler.
contentHandler = createContentHandler();
configureContentHandler(contentHandler);
// Create and configure the parser.
XMLReader parser = createParser();
// Install optional filter
if (saxXMLFilter != null) {
// Connect filter chain to parser
XMLFilter root = saxXMLFilter;
while (root.getParent() instanceof XMLFilter) {
root = (XMLFilter)root.getParent();
}
root.setParent(parser);
// Read from filter
parser = saxXMLFilter;
}
configureParser(parser, contentHandler);
This "separation of concerns" simplifies createParser() for the benefit of
overriders, and prepares for an eventual installFilter() protected method.
In any event, the javadoc needs to be brought into line with the change.
Placing the installFilter part in build() as I have above, updated javadoc
for configureParser follows. (If installFilter remains in createParser,
then createParser's documentation also needs to be updated.)
/**
* <p>
* This configures the XMLReader to be used for reading the XML
document.
* </p>
* <p>
* The default implementation will set various options on the given
* XMLReader, (such as validation flag, DTD resolver, and entity
handler),
* according to the options that were set (e.g. via setEntityResolver),
* and it will set various SAX properties and features that it needs set
* in order to work correctly. These options may change in future
releases.
* Change this behavior at your own risk.
* </p>
*/
protected void configureParser ...
Here's a cvs diff:
Index: jdom/src/java/org/jdom/input/SAXBuilder.java
===================================================================
RCS file: /home/cvspublic/jdom/src/java/org/jdom/input/SAXBuilder.java,v
retrieving revision 1.54
diff -r1.54 SAXBuilder.java
283a284,297
>
> // Install optional filter
> if (saxXMLFilter != null) {
> // Connect filter chain to parser
> XMLFilter root = saxXMLFilter;
> while (root.getParent() instanceof XMLFilter) {
> root = (XMLFilter)root.getParent();
> }
> root.setParent(parser);
>
> // Read from filter
> parser = saxXMLFilter;
> }
>
416,428d429
< // Install optional filter
< if (saxXMLFilter != null) {
< // Connect filter chain to parser
< XMLFilter root = saxXMLFilter;
< while (root.getParent() instanceof XMLFilter) {
< root = (XMLFilter)root.getParent();
< }
< root.setParent(parser);
<
< // Read from filter
< parser = saxXMLFilter;
< }
<
437,439c438,439
< * The default implementation will set various options on the returned
XMLReader,
< * and that those options may change in future releases. It will set
the
< * validation flag, the XMLFilter, the DTD resolver, and the entity
handler
---
> * The default implementation will set various options on the given
> * XMLReader, (such as validation flag, DTD resolver, and entity
handler),
442c442,443
< * in order to work correctly. Change this behavior at your own risk.
---
> * in order to work correctly. These options may change in future
releases.
> * Change this behavior at your own risk.
I tried samples.sax.FilterTest with this patch and it works..
--
Joe Bowbeer
More information about the jdom-interest
mailing list