FastOdsXMLEscaper implements XMLEscaper { @Override public String escapeXMLContent(final String s) { if (s == null) { return null; } final String cached = this.contentCacheMap.get(s); if (cached != null) { return cached; } final String escaped = this.getEscapedString(s, CHAR_SUBSTITUTES_IN_CONTENT); this.contentCacheMap.put(s, escaped); return escaped; } FastOdsXMLEscaper(final int bufferSize); static FastOdsXMLEscaper create(); @Override String escapeXMLAttribute(final String s); @Override String escapeXMLContent(final String s);  }
@Test public final void testContentBuffer() { final XMLEscaper escaper = new FastOdsXMLEscaper(124); final StringBuilder sb1 = new StringBuilder(8 * (2 << 5)); final StringBuilder sb2 = new StringBuilder(8 * (2 << 5)); sb1.append("'ae< >"); sb2.append("'ae&lt; &gt;"); for (int i = 0; i < 5; i++) { sb1.append(sb1.toString()).append(sb1.toString()); sb2.append(sb2.toString()).append(sb2.toString()); } Assert.assertEquals(sb2.toString(), escaper.escapeXMLContent(sb1.toString())); }
@Test public final void testContentBuffer2() { final XMLEscaper escaper = new FastOdsXMLEscaper(5); final String expected = "<ae"; final String actual = "&lt;ae"; Assert.assertEquals(actual, escaper.escapeXMLContent(expected)); }
@Test public final void testContentNullString() { Assert.assertNull(this.escaper.escapeXMLContent(null)); }