public static String escape(String str) {
    StringBuffer result = new StringBuffer();
    StringTokenizer tokenizer = new StringTokenizer(str, DELIMITER, true);
    while(tokenizer.hasMoreTokens()) {
      String currentToken = tokenizer.nextToken();
      if(ESCAPED_CHARS.containsKey(currentToken)) {
        result.append(ESCAPED_CHARS.get(currentToken));
      } else {
        result.append(currentToken);
      }
    }
    return result.toString();
  }
public static String escape ( String str ) { StringBuffer result = new StringBuffer ( ) ; StringTokenizer tokenizer = new StringTokenizer ( str , DELIMITER , true ) ; while ( tokenizer . hasMoreTokens ( ) ) { String currentToken = tokenizer . nextToken ( ) ; if ( ESCAPED_CHARS . containsKey ( currentToken ) ) { result . append ( ESCAPED_CHARS . get ( currentToken ) ) ; } else { result . append ( currentToken ) ; } } return result . toString ( ) ; }
Encoder special characters that may occur in a HTML so it can be displayed
safely.
@param str the original string
@return the escaped string