[jdom-interest] Bug in SAXHandler.endPrefixMapping() (SAXBuilder.java)

Hugh Emberson hugh at embertech.com
Sun Nov 26 00:38:52 PST 2000


Hi, 

I was looking at the SAXBuilder today and noticed that the implementation of
endPrefixMapping() in SAXHandler looked wrong.  The method is declared in
org.xml.sax.ContentHandler as:

    public void endPrefixMapping (String prefix)
	throws SAXException;

but looked like this in SAXHandler:

    public void endPrefixMapping(String prefix, String uri)
        throws SAXException

this leads me to believe that it has never been called and no-one has ever
noticed. Instead the default, do-nothing, implementation in
org.xml.sax.helpers.DefaultHandler was being called.

I have taken a stab at fixing the method, but I don't understand Namespaces
well enough to know if it is correct.  I think it should look like this:

    /**
     * <p>
     * This will add the prefix mapping to the JDOM
     *   <code>Document</code> object.
     * </p>
     *
     * @param prefix <code>String</code> namespace prefix.
     */
    public void endPrefixMapping(String prefix)
        throws SAXException {
        if(!stack.empty()) {
	    Namespace ns = Namespace.getNamespace(prefix,
						  ((Element) (stack.peek())));
	    availableNamespaces.remove(ns);
	}
    }

I think should work, but I'm not sure what to do when the stack is empty -- I
think it probably doesn't matter.

On a related note, I have split SAXHandler into it's own file to make it
easier to integrate JDOM into systems that already use SAX but might want to
intercept some of the events for their own purposes.  I can provide a patch
for this if anyone is interested.

Cheers,
        Hugh





More information about the jdom-interest mailing list