public static String convertStringToHtml(String s){
  if (s == null) {
    return null;
  }
  if (s.length() == 0) {
    return s;
  }
  StringBuilder buff=new StringBuilder();
  for (int i=0; i < s.length(); i++) {
    char ch=s.charAt(i);
    String token=CODE_MAP.get(ch);
    if (token == null) {
      if (ch < 128) {
        buff.append(ch);
      }
 else {
        buff.append('&');
        buff.append('#');
        buff.append((int)ch);
        buff.append(';');
      }
    }
 else {
      buff.append('&');
      buff.append(token);
      buff.append(';');
    }
  }
  return buff.toString();
}

public static String convertStringToHtml ( String s ) { if ( s == null ) { return null ; } if ( s . length ( ) == 0 ) { return s ; } StringBuilder buff = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; String token = CODE_MAP . get ( ch ) ; if ( token == null ) { if ( ch < 128 ) { buff . append ( ch ) ; } else { buff . append ( '&' ) ; buff . append ( '#' ) ; buff . append ( ( int ) ch ) ; buff . append ( ';' ) ; } } else { buff . append ( '&' ) ; buff . append ( token ) ; buff . append ( ';' ) ; } } return buff . toString ( ) ; }
convert a string to html by encoding all required characters .
