public final static String htmlEscape(String line)
    {
        StringBuilder sb = new StringBuilder();
        char[] chars = line.toCharArray();
        for (int i=0; i<chars.length; i++) {
            char cur = chars[i];
            if ((cur == '\n') || (cur == '\r') || (cur == '\t')) {
                sb.append(cur);
            }
            else if ((cur >= ' ') && (cur <= '~') &&
                (cur != '<') && (cur != '>') && (cur != '&')) {
                sb.append(cur);
            }
            else {
                sb.append("&#");
                sb.append(Integer.toString(cur));
                sb.append(";");
            }
        }
        return sb.toString();
    }