From 1a22532991dc57f1cbdb8dbd4021575b8230984d Mon Sep 17 00:00:00 2001
From: Henri Yandell
Here we see that ESCAPE_XML
is a 'CharSequenceTranslator
', which in turn is made up of two lookup translators based on the basic XML escapes and another to escape apostrophes. This shows one way to combine translators. Another can be shown by looking at the example to achieve the old XML escaping functionality (escaping non-ASCII):
- StringEscapeUtils.ESCAPE_XML.with( new UnicodeEscaper(Range.between(0x7f, Integer.MAX_VALUE) ) ); + StringEscapeUtils.ESCAPE_XML.with( NumericEntityEscaper.between(0x7f, Integer.MAX_VALUE) );
That takes the standard Commons Lang provided escape functionality, and adds on another translation layer. Another JIRA requested option was to also escape non-printable ASCII, this is now achievable with a modification of the above:
StringEscapeUtils.ESCAPE_XML.with( new AggregateTranslator( - new UnicodeEscaper(Range.between(0, 31)), - new UnicodeEscaper(Range.between(0x80, Integer.MAX_VALUE)) + NumericEntityEscaper.between(0, 31), + NumericEntityEscaper.between(0x80, Integer.MAX_VALUE) ) )