Java HTML Escape escapeHtml(String s)

Here you can find the source of escapeHtml(String s)

Description

escape Html

License

Apache License

Declaration

public static String escapeHtml(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;

public class Main {
    public static String escapeHtml(String s) {
        final StringBuilder out = new StringBuilder(
                Math.max(16, s.length()));
        for (int i = 0; i < s.length(); i++) {
            final char c = s.charAt(i);
            if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') {
                out.append("&#");
                out.append((int) c);
                out.append(';');
            } else {
                out.append(c);//from  ww w  .j  a  v  a 2 s.  c  om
            }
        }
        return out.toString();
    }

    public static String toString(Object object) {
        if (object == null) {
            return "null";
        }
        return object.toString();
    }

    public static String toString(Iterable<?> it, String separator) {
        final StringBuilder builder = new StringBuilder();
        final Iterator<?> iterator = it.iterator();
        while (iterator.hasNext()) {
            builder.append(iterator.next().toString());
            if (iterator.hasNext()) {
                builder.append(separator);
            }
        }
        return builder.toString();
    }
}

Related

  1. escapeHTML(String aText)
  2. escapeHtml(String s)
  3. escapeHTML(String s)
  4. escapeHTML(String s)
  5. escapeHTML(String text)
  6. escapeHTML(String text)
  7. escapeHTMLLine(String line)
  8. escapeHTMLSpecialChars(String aText)