code: static public String escapeTags(final String input) {
          // Check if the string is null, zero length or devoid of special characters
          // if so, return what was sent in.
  
          if(input == null
              || input.length() == 0
              || (input.indexOf('"') == -1 &&
              input.indexOf('&') == -1 &&
              input.indexOf('<') == -1 &&
              input.indexOf('>') == -1)) {
              return input;
          }
  
          StringBuilder buf = new StringBuilder(input.length() + 6);
          char ch;
  
          int len = input.length();
          for(int i=0; i < len; i++) {
              ch = input.charAt(i);
              if (ch > '>') {
                  buf.append(ch);
              } else if(ch == '<') {
                  buf.append("&lt;");
              } else if(ch == '>') {
                  buf.append("&gt;");
              } else if(ch == '&') {
                  buf.append("&amp;");
              } else if(ch == '"') {
                  buf.append("&quot;");
              } else {
                  buf.append(ch);
              }
          }
          return buf.toString();
      }
docs: This method takes a string which may contain HTML tags (ie,
  &lt;b&gt;, &lt;table&gt;, etc) and replaces any
  '<',  '>' , '&' or '"'
  characters with respective predefined entity references.
  
  @param input The text to be converted.
  @return The input string with the special characters replaced.