I'm on the incubating Apache JSPWiki team and trying to upgrade our project from JDOM 1.1.2 to JDOM 2.0.5. 98% of the conversion seems to work fine but I've come across one problem preventing us from upgrading, involving JDOM2's XMLOutputter.outputElementContent(). Namely, we always add a processing instruction to disable output escaping but we still expect ampersands and quotes within attributes to be escaped to & and ". JDOM1 handles this PI as we want, but JDOM2 interprets this instruction to also shut off output escaping within attribute values. I'm unsure if this is a bug/feature in JDOM2 or if JSPWiki is improperly relying on a bug/feature in JDOM1. [1] shows how we configure the Format element in JSPWiki prior to calling outputElementContent().
For example, in JDOM1:
<a href="http://www.google.com/?p=a&c=d">Hello</a>
gets rendered as:
<a href="http://www.google.com/?p=a&c=d">Hello</a> (good, ampersand is escaped)
This is because in JDOM1, XMLOutputter.printAttibutes()[2] escapes the attribute values regardless of the processing instruction.
but in JDOM2 we get:
<a href="http://www.google.com/?p=a&c=d">Hello</a> (bad, still an ampersand character)
... because in JDOM2, AbstractXMLOutputProcessor's attributeEscapedEntitiesFilter[3] will do the escaping only if "getEscapeOutput()" is true, but getEscapeOutput is automatically set to false[4] if the disable-output-escaping PI is set.
If we call Format.setIgnoreTrAXEscapingPIs() (or just not add the disable-output-escaping PI to begin with), we end up having the opposite problem of the tag being escaped.
Can anyone think of a good/simple solution for us?
Thanks, Glen