Class SimplifyHtmlFilter
java.lang.Object
org.shredzone.commons.text.filter.SimplifyHtmlFilter
- All Implemented Interfaces:
Function<CharSequence,CharSequence>,TextFilter
A filter that simplifies a HTML text. Only a given set of HTML tags (and attributes)
are accepted. Other HTML tags are completely removed.
This filter can be used to allow a site visitor to enter marked-up text, but remove everything that might be harmful or induce Cross Site Scripting.
- Author:
- Richard "Shred" Körber
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAcceptedTag(String tag)Adds a tag that is accepted by this filter, with all its attributes.voidaddAcceptedTag(String tag, String... attributes)Adds a tag that is accepted by this filter, along with accepted attributes.apply(CharSequence text)Applies the filter on aCharSequenceand returns a newCharSequencewith the modified text.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.shredzone.commons.text.TextFilter
toStringBuilder
-
Constructor Details
-
SimplifyHtmlFilter
public SimplifyHtmlFilter()
-
-
Method Details
-
addAcceptedTag
Adds a tag that is accepted by this filter, with all its attributes.- Parameters:
tag- HTML tag that is accepted (without angle brackets, e.g. "strong")
-
addAcceptedTag
Adds a tag that is accepted by this filter, along with accepted attributes.- Parameters:
tag- HTML tag that is accepted (without angle brackets, e.g. "img")attributes- an array of accepted attributes (e.g. "src", "alt")
-
apply
Description copied from interface:TextFilterApplies the filter on aCharSequenceand returns a newCharSequencewith the modified text.- Specified by:
applyin interfaceFunction<CharSequence,CharSequence>- Specified by:
applyin interfaceTextFilter- Parameters:
text-CharSequencewith the contents to be filtered. If this is aStringBuilderinstance, its contents may have changed after invocation, and this instance should not be used any more.- Returns:
CharSequencewith the filtered text.
-