EncodersImpl implements Encoders { public String html(String s) { if (s == null) { return null; } final int l = s.length(); final StringBuffer sb = new StringBuffer(l); for (int i = 0; i < l; i++) { final char ch = s.charAt(i); switch (ch) { case '&': sb.append("&amp;"); break; case '<': sb.append("&lt;"); break; case '>': sb.append("&gt;"); break; case '"': sb.append("&#34;"); break; case '\'': sb.append("&#39;"); break; default: sb.append(ch); } } return sb.toString(); }  String js(String s); String html(String s);  }
@Test public void testEncoderHtml() { assertEquals("&amp; &lt; &gt; &#39; &#34;", encoders.html("& < > ' \"")); assertEquals("&lt;html&gt;&lt;div id=&#34;foo&#34;&gt;&amp;&amp;&lt;/div&gt;&lt;/html&gt;", encoders.html("<html><div id=\"foo\">&&</div></html>")); assertNull(encoders.html(null)); }