Class LinkToUrlFilter
java.lang.Object
org.shredzone.commons.text.filter.LinkToUrlFilter
- All Implemented Interfaces:
Function<CharSequence,CharSequence>,TextFilter
A filter that detects links in a text, and creates an HTML <a> tag around each
link. http, https and ftp protocols are detected.
- Author:
- Richard "Shred" Körber
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(CharSequence text)Applies the filter on aCharSequenceand returns a newCharSequencewith the modified text.voidsetFollow(boolean follow)Deprecated.voidsetNoFollow(boolean noFollow)Sets the way search engines evaluate the created link.voidsetNoOpener(boolean noOpener)Sets whether links with target "_blank" should have a "noopener" relationship.voidsetNoReferrer(boolean noReferrer)Sets wheter a "noreferrer" relationship shall be used.voidSets the link's target attribute.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
-
LinkToUrlFilter
public LinkToUrlFilter()Creates a newLinkToUrlFilter.
-
-
Method Details
-
setFollow
Deprecated.It is confusing that this property must be set tofalsein order to have a "nofollow" relationship. UsesetNoFollow(boolean)instead.Sets the way search engines evaluate the created link. If set tofalse, arel="nofollow"attribute is added to the link, so web crawlers will not follow to the target.- Parameters:
follow-trueif links should be followed by web crawlers. Defaults totrue.
-
setNoFollow
Sets the way search engines evaluate the created link. If set totrue, arel="nofollow"attribute is added to the link, so web crawlers will not follow to the target.- Parameters:
noFollow-trueif links should not be followed by web crawlers. Defaults tofalse.- Since:
- 2.6
-
setNoOpener
Sets whether links with target "_blank" should have a "noopener" relationship. Activated by default. Note that deactivation poses a security risk for your website, and should only be done for a very good reason!- Parameters:
noOpener-trueto set "noopener" relationships on all links with a "_blank" target. This is the default.- Since:
- 2.6
-
setNoReferrer
Sets wheter a "noreferrer" relationship shall be used. Iftrue(and supported by the browser), the browser won't send a "Referer" header when following a link.- Parameters:
noReferrer- Iftrue, a "noreferrer" relation is added to each link.falseby default.- Since:
- 2.6
-
setTarget
Sets the link's target attribute.- Parameters:
target- Link target, ornullif no target is to be set.
-
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.
-
falsein order to have a "nofollow" relationship.