public static String escapeHtml(final String str) {
    final StringBuffer buf = new StringBuffer();
    final int len = str == null ? 0 : str.length();

    for (int i = 0; i < len; i++) {
      final char ch = str.charAt(i);
      if (Character.isLetterOrDigit(ch)) {
        buf.append(ch);
      } else {
        buf.append("&#" + (int) ch + ";");
      }
    }
    return buf.toString();
  }
Escapes the characters in a <code>String</code> using HTML entities.

@param str the <code>String</code> to escape, may be <code>null</code>
@return a new escaped <code>String</code>, empty if <code>null</code> string input
java/ui/src/main/java/com/google/security/zynamics/bindiff/utils/HtmlUtils.java