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
-
Method Summary
Modifier and TypeMethodDescriptionapply(CharSequence text)
Applies the filter on aCharSequence
and returns a newCharSequence
with the modified text.void
setFollow(boolean follow)
Deprecated.void
setNoFollow(boolean noFollow)
Sets the way search engines evaluate the created link.void
setNoOpener(boolean noOpener)
Sets whether links with target "_blank" should have a "noopener" relationship.void
setNoReferrer(boolean noReferrer)
Sets wheter a "noreferrer" relationship shall be used.void
Sets the link's target attribute.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 tofalse
in 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
-true
if 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
-true
if 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
-true
to 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.false
by default.- Since:
- 2.6
-
setTarget
Sets the link's target attribute.- Parameters:
target
- Link target, ornull
if no target is to be set.
-
apply
Description copied from interface:TextFilter
Applies the filter on aCharSequence
and returns a newCharSequence
with the modified text.- Specified by:
apply
in interfaceFunction<CharSequence,CharSequence>
- Specified by:
apply
in interfaceTextFilter
- Parameters:
text
-CharSequence
with the contents to be filtered. If this is aStringBuilder
instance, its contents may have changed after invocation, and this instance should not be used any more.- Returns:
CharSequence
with the filtered text.
-
false
in order to have a "nofollow" relationship.