code: public static String HTMLEntityEncode(String input) {
          String next = scriptPattern.matcher(input).replaceAll("&#x73;cript");
  
          StringBuffer sb = new StringBuffer();
          for (int i = 0; i < next.length(); ++i) {
              char ch = next.charAt(i);
  
              if (ch == '<') {
                  sb.append("&lt;");
              } else if (ch == '>') {
                  sb.append("&gt;");
              } else {
                  sb.append(ch);
              }
          }
  
          return sb.toString();
      }
docs: Encode HTML entities.
  
  @param input the input string to be encoded
  @return the encoded string