Java HTML Encode toHTML(String org, boolean inputValue)

Here you can find the source of toHTML(String org, boolean inputValue)

Description

to HTML

License

Open Source License

Declaration

public static String toHTML(String org, boolean inputValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toHTML(String org, boolean inputValue) {
        StringBuffer result = new StringBuffer(org.length());
        char[] chars = org.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '\"')
                result.append("&quot;");
            else if (chars[i] == '<')
                result.append("&lt;");
            else if (chars[i] == '>')
                result.append("&gt;");
            else if (chars[i] == '&')
                result.append("&amp;");
            else if (chars[i] == '\r') {
                if (inputValue)
                    result.append(chars[i]);
                else {
                    result.append("<br/>");
                    if (i + 1 < chars.length && chars[i + 1] == '\n')
                        i++;//from   w  w w.j  av  a 2s .  c o m
                }
            } else if (chars[i] == '\n') {
                if (inputValue)
                    result.append(chars[i]);
                else
                    result.append("<br/>");
            } else if (chars[i] == ' ')
                if (inputValue)
                    result.append(chars[i]);
                else
                    result.append("&nbsp;");
            else
                result.append(chars[i]);
        }
        return result.toString();
    }

    public static String toHTML(String org) {
        return toHTML(org, false);
    }
}

Related

  1. textToHtml(String text)
  2. textToHTML(String text)
  3. textToHTML(String text)
  4. toHtml(String message)
  5. toHTML(String msg)
  6. toHtml(String p_str)
  7. toHTML(String plainText)
  8. toHTML(String rawText)
  9. toHTML(String s)