public String sanitizeString(String string){
  StringBuilder retval=new StringBuilder();
  StringCharacterIterator iterator=new StringCharacterIterator(string);
  char character=iterator.current();
  while (character != java.text.CharacterIterator.DONE) {
    if (character == '<') {
      retval.append("&lt;");
    }
 else     if (character == '>') {
      retval.append("&gt;");
    }
 else     if (character == '&') {
      retval.append("&amp;");
    }
 else     if (character == '\"') {
      retval.append("&quot;");
    }
 else     if (character == '\t') {
      addCharEntity(9,retval);
    }
 else     if (character == '!') {
      addCharEntity(33,retval);
    }
 else     if (character == '#') {
      addCharEntity(35,retval);
    }
 else     if (character == '$') {
      addCharEntity(36,retval);
    }
 else     if (character == '%') {
      addCharEntity(37,retval);
    }
 else     if (character == '\'') {
      addCharEntity(39,retval);
    }
 else     if (character == '(') {
      addCharEntity(40,retval);
    }
 else     if (character == ')') {
      addCharEntity(41,retval);
    }
 else     if (character == '*') {
      addCharEntity(42,retval);
    }
 else     if (character == '+') {
      addCharEntity(43,retval);
    }
 else     if (character == ',') {
      addCharEntity(44,retval);
    }
 else     if (character == '-') {
      addCharEntity(45,retval);
    }
 else     if (character == '.') {
      addCharEntity(46,retval);
    }
 else     if (character == '/') {
      addCharEntity(47,retval);
    }
 else     if (character == ':') {
      addCharEntity(58,retval);
    }
 else     if (character == ';') {
      addCharEntity(59,retval);
    }
 else     if (character == '=') {
      addCharEntity(61,retval);
    }
 else     if (character == '?') {
      addCharEntity(63,retval);
    }
 else     if (character == '@') {
      addCharEntity(64,retval);
    }
 else     if (character == '[') {
      addCharEntity(91,retval);
    }
 else     if (character == '\\') {
      addCharEntity(92,retval);
    }
 else     if (character == ']') {
      addCharEntity(93,retval);
    }
 else     if (character == '^') {
      addCharEntity(94,retval);
    }
 else     if (character == '_') {
      addCharEntity(95,retval);
    }
 else     if (character == '`') {
      addCharEntity(96,retval);
    }
 else     if (character == '{') {
      addCharEntity(123,retval);
    }
 else     if (character == '|') {
      addCharEntity(124,retval);
    }
 else     if (character == '}') {
      addCharEntity(125,retval);
    }
 else     if (character == '~') {
      addCharEntity(126,retval);
    }
 else {
      retval.append(character);
    }
    character=iterator.next();
  }
  return retval.toString();
}

public String sanitizeString ( String string ) { StringBuilder retval = new StringBuilder ( ) ; StringCharacterIterator iterator = new StringCharacterIterator ( string ) ; char character = iterator . current ( ) ; while ( character != java . text . CharacterIterator . DONE ) { if ( character == '<' ) { retval . append ( "&lt;" ) ; } else if ( character == '>' ) { retval . append ( "&gt;" ) ; } else if ( character == '&' ) { retval . append ( "&amp;" ) ; } else if ( character == '\"' ) { retval . append ( "&quot;" ) ; } else if ( character == '\t' ) { addCharEntity ( 9 , retval ) ; } else if ( character == '!' ) { addCharEntity ( 33 , retval ) ; } else if ( character == '#' ) { addCharEntity ( 35 , retval ) ; } else if ( character == '$' ) { addCharEntity ( 36 , retval ) ; } else if ( character == '%' ) { addCharEntity ( 37 , retval ) ; } else if ( character == '\'' ) { addCharEntity ( 39 , retval ) ; } else if ( character == '(' ) { addCharEntity ( 40 , retval ) ; } else if ( character == ')' ) { addCharEntity ( 41 , retval ) ; } else if ( character == '*' ) { addCharEntity ( 42 , retval ) ; } else if ( character == '+' ) { addCharEntity ( 43 , retval ) ; } else if ( character == ',' ) { addCharEntity ( 44 , retval ) ; } else if ( character == '-' ) { addCharEntity ( 45 , retval ) ; } else if ( character == '.' ) { addCharEntity ( 46 , retval ) ; } else if ( character == '/' ) { addCharEntity ( 47 , retval ) ; } else if ( character == ':' ) { addCharEntity ( 58 , retval ) ; } else if ( character == ';' ) { addCharEntity ( 59 , retval ) ; } else if ( character == '=' ) { addCharEntity ( 61 , retval ) ; } else if ( character == '?' ) { addCharEntity ( 63 , retval ) ; } else if ( character == '@' ) { addCharEntity ( 64 , retval ) ; } else if ( character == '[' ) { addCharEntity ( 91 , retval ) ; } else if ( character == '\\' ) { addCharEntity ( 92 , retval ) ; } else if ( character == ']' ) { addCharEntity ( 93 , retval ) ; } else if ( character == '^' ) { addCharEntity ( 94 , retval ) ; } else if ( character == '_' ) { addCharEntity ( 95 , retval ) ; } else if ( character == '`' ) { addCharEntity ( 96 , retval ) ; } else if ( character == '{' ) { addCharEntity ( 123 , retval ) ; } else if ( character == '|' ) { addCharEntity ( 124 , retval ) ; } else if ( character == '}' ) { addCharEntity ( 125 , retval ) ; } else if ( character == '~' ) { addCharEntity ( 126 , retval ) ; } else { retval . append ( character ) ; } character = iterator . next ( ) ; } return retval . toString ( ) ; }
sanitize strings for output . copy from anet_java_sdk_sample_app \ common \ helper . jsp
