FastOdsXMLEscaper implements XMLEscaper { @Override public String escapeXMLAttribute(final String s) { if (s == null) { return null; } final String cached = this.attrCacheMap.get(s); if (cached != null) { return cached; } final String escaped = this.getEscapedString(s, CHAR_SUBSTITUTES_IN_ATTRIBUTE); this.attrCacheMap.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 testAttrBuffer() { 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("&apos;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.escapeXMLAttribute(sb1.toString())); }
@Test public final void testAttrNullString() { Assert.assertNull(this.escaper.escapeXMLAttribute(null)); }
@Test public final void testAttrBuffer2() { final XMLEscaper escaper = new FastOdsXMLEscaper(5); final String actual = "<ae"; final String expected = "&lt;ae"; Assert.assertEquals(expected, escaper.escapeXMLAttribute(actual)); }