src/it/finsiel/siged/util/HtmlParser.java
public static String substituteSpecialCharactersInHeaderfields(String s) {
        StringBuffer sb = new StringBuffer(s.length());
        StringReader sr = new StringReader(s);
        BufferedReader br = new BufferedReader(sr);
        String ss = null;

        // TODO: Extend handling of special entities as in
        // restoreSpecialCharacters

        try {
            while ((ss = br.readLine()) != null) {
                int i = 0;

                while (i < ss.length()) {
                    switch (ss.charAt(i)) {
                    case '<':
                        sb.append("&lt;");
                        i++;

                        break;

                    case '>':
                        sb.append("&gt;");
                        i++;

                        break;

                    case '&':
                        sb.append("&amp;");
                        i++;

                        break;

                    case '"':
                        sb.append("&quot;");
                        i++;

                        break;

                    case '\'':
                        sb.append("&apos;");
                        i++;

                        break;

                    case ' ':

                        if (ss.substring(i).startsWith("    ")) {
                            sb.append("&nbsp; ");
                            i = i + 2;
                        } else if (ss.substring(i).startsWith("   ")) {
                            sb.append("&nbsp;&nbsp; ");
                            i = i + 3;
                        } else if (ss.substring(i).startsWith("  ")) {
                            sb.append("&nbsp; ");
                            i = i + 2;
                        } else {
                            sb.append(' ');
                            i++;
                        }

                        break;

                    case '\t':
                        sb.append("&nbsp;&nbsp;&nbsp;&nbsp;");
                        i++;

                        break;

                    case '\n':
                        sb.append("<br>");
                        i++;

                        break;

                    default:
                        sb.append(ss.charAt(i));
                        i++;

                        break;
                    }
                }
            }
        } catch (Exception e) {
            logger.warn("Error substituting special characters: "
                    + e.getMessage(), e);

            return null; // error
        }

        return sb.toString();
    }
/**
     * 
     * substitute special characters like: <,>,&,\t,\n with special entities
     * used in html <br>
     * This is the same as substituteSpecialCharacters, but here an extra
     * newline character is not inserted.
     * 
     * @param s
     *            input string containing special characters
     * @return output with special characters substituted (null on error)
     */
substitute special characters like: <,>,&,\t,\n with special entities
used in html 
This is the same as substituteSpecialCharacters, but here an extra
newline character is not inserted.

@param s
input string containing special characters
@return output with special characters substituted (null on error)
substitute special characters like : < > & \ t \ n with special entities used in html This is the same as substituteSpecialCharacters but here an extra newline character is not inserted . @param s input string containing special characters @return output with special characters substituted ( null on error )
public static String substituteSpecialCharactersInHeaderfields(String s) {
        StringBuffer sb = new StringBuffer(s.length());
        StringReader sr = new StringReader(s);
        BufferedReader br = new BufferedReader(sr);
        String ss = null;
        try {
            while ((ss = br.readLine()) != null) {
                int i = 0;
                while (i < ss.length()) {
                    switch (ss.charAt(i)) {
                    case '<':
                        sb.append("&lt;");
                        i++;
                        break;
                    case '>':
                        sb.append("&gt;");
                        i++;
                        break;
                    case '&':
                        sb.append("&amp;");
                        i++;
                        break;
                    case '"':
                        sb.append("&quot;");
                        i++;
                        break;
                    case '\'':
                        sb.append("&apos;");
                        i++;
                        break;
                    case ' ':
                        if (ss.substring(i).startsWith("    ")) {
                            sb.append("&nbsp; ");
                            i = i + 2;
                        } else if (ss.substring(i).startsWith("   ")) {
                            sb.append("&nbsp;&nbsp; ");
                            i = i + 3;
                        } else if (ss.substring(i).startsWith("  ")) {
                            sb.append("&nbsp; ");
                            i = i + 2;
                        } else {
                            sb.append(' ');
                            i++;
                        }
                        break;
                    case '\t':
                        sb.append("&nbsp;&nbsp;&nbsp;&nbsp;");
                        i++;
                        break;
                    case '\n':
                        sb.append("<br>");
                        i++;
                        break;
                    default:
                        sb.append(ss.charAt(i));
                        i++;
                        break;
                    }
                }
            }
        } catch (Exception e) {
            logger.warn("Error substituting special characters: "
                    + e.getMessage(), e);
            return null; 
        }
        return sb.toString();
    }
public static String substituteSpecialCharactersInHeaderfields ( String s ) { StringBuffer sb = new StringBuffer ( s . length ( ) ) ; StringReader sr = new StringReader ( s ) ; BufferedReader br = new BufferedReader ( sr ) ; String ss = null ; try { while ( ( ss = br . readLine ( ) ) != null ) { int i = 0 ; while ( i < ss . length ( ) ) { switch ( ss . charAt ( i ) ) { case '<' : sb . append ( "&lt;" ) ; i ++ ; break ; case '>' : sb . append ( "&gt;" ) ; i ++ ; break ; case '&' : sb . append ( "&amp;" ) ; i ++ ; break ; case '"' : sb . append ( "&quot;" ) ; i ++ ; break ; case '\'' : sb . append ( "&apos;" ) ; i ++ ; break ; case ' ' : if ( ss . substring ( i ) . startsWith ( "    " ) ) { sb . append ( "&nbsp; " ) ; i = i + 2 ; } else if ( ss . substring ( i ) . startsWith ( "   " ) ) { sb . append ( "&nbsp;&nbsp; " ) ; i = i + 3 ; } else if ( ss . substring ( i ) . startsWith ( "  " ) ) { sb . append ( "&nbsp; " ) ; i = i + 2 ; } else { sb . append ( ' ' ) ; i ++ ; } break ; case '\t' : sb . append ( "&nbsp;&nbsp;&nbsp;&nbsp;" ) ; i ++ ; break ; case '\n' : sb . append ( "<br>" ) ; i ++ ; break ; default : sb . append ( ss . charAt ( i ) ) ; i ++ ; break ; } } } } catch ( Exception e ) { logger . warn ( "Error substituting special characters: " + e . getMessage ( ) , e ) ; return null ; } return sb . toString ( ) ; }
substitute special characters like: <,>,&,\t,\n with special entities
 used in html <br>
 This is the same as substituteSpecialCharacters, but here an extra
 newline character is not inserted.
substitute special characters like : < > & \ t \ n with special entities used in html <br > This is the same as substituteSpecialCharacters but here an extra newline character is not inserted .
// TODO: Extend handling of special entities as in // restoreSpecialCharacters // error