question: 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 ( ) ; } }
target:  Escapes all '<', '>' and '&' characters in a string.