Class RegexEgressFilter

java.lang.Object
org.faceless.publisher.type.RegexEgressFilter
All Implemented Interfaces:
EgressFilter

public class RegexEgressFilter extends Object implements EgressFilter
An implementation of EgressFilter which works on regluar expressions. A list of patterns can be supplied, along with replacement patterns. This can be used to replace HTTP with HTTPS, for example, or to disallow access to files. Here's an example showing that.

  RegexEgressFilter f = new RegexEgressFilter("nofiles-and-https");
  f.add(null, "^file:", null);
  f.add(null, Pattern.compile("^http:(.*)"), "https:$1);
 
This can be set on the ReportFactory via ReportFactory.setEgressFilter(org.faceless.publisher.type.EgressFilter)
  • Constructor Details

    • RegexEgressFilter

      public RegexEgressFilter(Pattern base, Pattern search, String replace)
      Create a new RegexEgressFilter to match against the URL, and the replacement value to use
      Parameters:
      base - the pattern to match against the base uri, or null to match all of them
      search - the pattern to match against the uri
      replace - the replacement pattern, or null to delete the URL (and disallow access)
  • Method Details

    • getBasePattern

      public Pattern getBasePattern()
      Return the "base" pattern, which may be null to match everything
    • getSearchPattern

      public Pattern getSearchPattern()
      Return the "uri" pattern
    • getReplacement

      public String getReplacement()
      Return the "replace" pattern, or null if the URL is disallowed on match.
    • rewrite

      public URL2 rewrite(URL2 uri, URL2 base)
      Description copied from interface: EgressFilter
      This method will be supplied with the URL about to be loaded, and the base URL of the Document loading it. It can return the URL as it is to load it, a rewritten URL to load a new resource instead, or null to disallow the load.
      Specified by:
      rewrite in interface EgressFilter
      Parameters:
      uri - the destination URL
      base - the URL of the document, or null if we're testing the base URL of the document
      Returns:
      the URL to load, or null to disallow access
    • toString

      public String toString()
      Overrides:
      toString in class Object