Java HTML Sanitize sanitize(String html)

Here you can find the source of sanitize(String html)

Description

sanitize

License

Apache License

Declaration

public static String sanitize(String html) 

Method Source Code

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

public class Main {
    public static String[] sanitizeSrc = { "&", "<", ">", "\"", "'" };
    public static String[] sanitizeDesc = { "&amp;", "&lt;", "&gt;", "&quot;", "&#39;" };

    public static String sanitize(String html) {
        if (html == null || html.isEmpty()) {
            return html;
        }/* w w w. j  ava2 s .  com*/

        for (int i = 0; i < sanitizeSrc.length; i++) {
            html = html.replace(sanitizeSrc[i], sanitizeDesc[i]);
        }

        return html;
    }
}

Related

  1. sanitizeForHtmlTag(String string)
  2. sanitizeQuot(String html)