Java Utililty Methods HTML Encode

List of utility methods to do HTML Encode

Description

The list of methods to do HTML Encode are organized into topic(s).

Method

StringencodeHTML(String aText)
encode HTML
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        result.append("&lt;");
    } else if (character == '>') {
        result.append("&gt;");
...
StringencodeHTML(String s)
TODO: replace with JTidy or AntiSamy http://jtidy.sourceforge.net/multiproject/jtidyservlet/clover/org/w3c/tidy/servlet/util/HTMLEncode.html
return encode(s, "\n");
StringforHTML(final String aText)
Encodes the string to be used in HTML.
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '\"') {
        result.append("DOUBLE_QUOTE");
    } else if (character == '\r') {
        result.append("RETURN_CAR");
...
StringforHTML(String aText)
Escape characters for text appearing in HTML markup.
if (aText == null)
    return null;
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        result.append("&lt;");
...
StringforHtmlComplete(final String aText)
Encodes the string to be used in HTML.
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(aText);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        result.append("&lt;");
    } else if (character == '>') {
        result.append("&gt;");
...
StringforHTMLTag(String aTagFragment)
Replace characters having special meaning inside HTML tags with their escaped equivalents, using character entities such as '&'.
final StringBuffer result = new StringBuffer();
final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        result.append("&lt;");
    } else if (character == '>') {
        result.append("&gt;");
...
StringforHTMLTag(String aTagFragment)
Replace characters having special meaning inside HTML tags with their escaped equivalents, using character entities such as '&'.
final StringBuffer result = new StringBuffer();
final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);
for (char character = iterator.current(); character != CharacterIterator.DONE; character = iterator
        .next()) {
    switch (character) {
    case '<':
        result.append("&lt;");
        break;
...
Stringhtml(String text)
Creates an html element.
return "<html>" + text + "</html>";
Stringhtml(String text)
Wraps text with tags
StringBuilder sb = new StringBuilder(text.length() + 14);
return sb.append("<html>").append(text).append("</html>").toString();
Stringhtml_encode(String input_string)
htmencode
char[] input = input_string.toCharArray();
StringBuffer encoded_html_string = new StringBuffer();
for (int x = 0; x < input.length; x++) {
    if ((input[x] >= '0' && input[x] <= '9') || (input[x] >= 'A' && input[x] <= 'Z')
            || (input[x] >= 'a' && input[x] <= 'z')) {
        encoded_html_string.append(input[x]);
    else if (input[x] <= ' ') {
...