Java HTML Filter filterHtmlAndTruncate(String s)

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

Description

filter Html And Truncate

License

Apache License

Declaration

public static String filterHtmlAndTruncate(String s) 

Method Source Code

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

public class Main {
    public static final int DEFAULT_MAX_CONTENT_LENGTH = 255;

    public static String filterHtmlAndTruncate(String s) {
        return filterHtmlAndTruncate(s, DEFAULT_MAX_CONTENT_LENGTH);
    }/*from  ww  w.  j av  a 2 s. c o m*/

    public static String filterHtmlAndTruncate(String s, int maxLength) {
        String content = filterHtml(s);
        if (content == null) {
            return "";
        } else {
            if (content.length() > maxLength) {
                return content.substring(0, maxLength - 3) + "...";
            } else {
                return content;
            }
        }
    }

    public static String filterHtml(String s) {
        if (s == null) {
            return null;
        }

        s = s.replaceAll("<", "");
        s = s.replaceAll(">", "");
        s = s.replaceAll(" ", "");
        s = s.replaceAll("(?s)<!--.*?-->", "");
        return s.replaceAll("(?s)<.*?>", "");
    }
}

Related

  1. filterHTML(String input)
  2. filterHtml(String input)
  3. filterHTML(String s)
  4. filterHtml(String s)
  5. filterHtmlAndTruncate(String s)
  6. filterHtmlTag(String body)
  7. filterHtmlTag(String content)
  8. filterHtmlTag(String input)