Package org.linkki.core.util
Class HtmlSanitizer
- java.lang.Object
-
- org.linkki.core.util.HtmlSanitizer
-
public class HtmlSanitizer extends Object
Utility class for sanitizing HTML text.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringescapeText(String text)Escapes HTML characters (& < > " ') in the given text, in order to make the text safe for inclusion in HTML content.static StringsanitizeText(String htmlText)Sanitizes the given HTML text and removes potentially dangerous tags and attributes.
-
-
-
Method Detail
-
sanitizeText
@CheckForNull public static String sanitizeText(@CheckForNull String htmlText)
Sanitizes the given HTML text and removes potentially dangerous tags and attributes.Allowed tags and attributes are defined by
Safelist.basicWithImages(), which includes basic styling tags as well as 'img'.Additionally, the 'style' attribute is whitelisted for the tags 'b', 'i', 'strong', 'em', 'u'. The attributes 'style', 'class' and 'id' are whitelisted for 'div'. 'img' can be used with a relative or absolute image source.
The 'vaadin-icon' tag is also whitelisted together with the attributes 'id', 'class', 'width', 'height', 'style' and 'icon'.
- Parameters:
htmlText- the HTML text to be sanitized, may benull- Returns:
- the sanitized content, or
nullif the input isnull
-
escapeText
@CheckForNull public static String escapeText(@CheckForNull String text)
Escapes HTML characters (& < > " ') in the given text, in order to make the text safe for inclusion in HTML content.- Parameters:
text- the text to be escaped, may benull- Returns:
- the escaped content, or
nullif the input isnull
-
-