private static String htmlencode(String str){
  if (str == null) {
    return "";
  }
 else {
    StringBuilder buf=new StringBuilder();
    for (    char ch : str.toCharArray()) {
switch (ch) {
case '<':
        buf.append("&lt;");
      break;
case '>':
    buf.append("&gt;");
  break;
case '&':
buf.append("&amp;");
break;
default :
buf.append(ch);
break;
}
}
return buf.toString();
}
}

private static String htmlencode ( String str ) { if ( str == null ) { return "" ; } else { StringBuilder buf = new StringBuilder ( ) ; for ( char ch : str . toCharArray ( ) ) { switch ( ch ) { case '<' : buf . append ( "&lt;" ) ; break ; case '>' : buf . append ( "&gt;" ) ; break ; case '&' : buf . append ( "&amp;" ) ; break ; default : buf . append ( ch ) ; break ; } } return buf . toString ( ) ; } }
escapes all ' < ' , ' > ' and ' & ' characters in a string .
