Class LinkToUrlFilter

java.lang.Object
org.shredzone.commons.text.filter.LinkToUrlFilter
All Implemented Interfaces:
Function<CharSequence,​CharSequence>, TextFilter

public class LinkToUrlFilter extends Object implements 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 Details

  • Method Details

    • setFollow

      @Deprecated public void setFollow(boolean follow)
      Deprecated.
      It is confusing that this property must be set to false in order to have a "nofollow" relationship. Use setNoFollow(boolean) instead.
      Sets the way search engines evaluate the created link. If set to false, a rel="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 to true.
    • setNoFollow

      public void setNoFollow(boolean noFollow)
      Sets the way search engines evaluate the created link. If set to true, a rel="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 to false.
      Since:
      2.6
    • setNoOpener

      public void setNoOpener(boolean noOpener)
      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

      public void setNoReferrer(boolean noReferrer)
      Sets wheter a "noreferrer" relationship shall be used. If true (and supported by the browser), the browser won't send a "Referer" header when following a link.
      Parameters:
      noReferrer - If true, a "noreferrer" relation is added to each link. false by default.
      Since:
      2.6
    • setTarget

      public void setTarget(@Nullable String target)
      Sets the link's target attribute.
      Parameters:
      target - Link target, or null if no target is to be set.
    • apply

      public CharSequence apply(CharSequence text)
      Description copied from interface: TextFilter
      Applies the filter on a CharSequence and returns a new CharSequence with the modified text.
      Specified by:
      apply in interface Function<CharSequence,​CharSequence>
      Specified by:
      apply in interface TextFilter
      Parameters:
      text - CharSequence with the contents to be filtered. If this is a StringBuilder instance, its contents may have changed after invocation, and this instance should not be used any more.
      Returns:
      CharSequence with the filtered text.