org.apache.nutch.urlfilter.api

## Class RegexURLFilterBase

- java.lang.Object
- - org.apache.nutch.urlfilter.api.RegexURLFilterBase

- All Implemented Interfaces:
    Configurable, URLFilter, Pluggable
  Direct Known Subclasses:
    AutomatonURLFilter, RegexURLFilter

      public abstract class RegexURLFilterBase
      extends java.lang.Object
      implements URLFilter

  Generic `URL filter` based on regular expressions.

  The regular expressions rules are expressed in a file. The file of rules is determined for each implementation using the `getRulesReader(Configuration conf)` method.

  The format of this file is made of many rules (one per line):
  `[+-]<regex>`
  where plus (`+`)means go ahead and index it and minus ( `-`)means no.

  Author:
    Jérôme Charron

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `hasHostDomainRules` Whether there are host- or domain-specific rules.

    - ### Fields inherited from interface org.apache.nutch.net.URLFilter

      `X_POINT_ID`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `RegexURLFilterBase()` Constructs a new empty RegexURLFilterBase
    `` | `RegexURLFilterBase(java.io.File filename)` Constructs a new RegexURLFilter and init it with a file of rules.
    `protected` | `RegexURLFilterBase(java.io.Reader reader)` Constructs a new RegexURLFilter and init it with a Reader of rules.
    `` | `RegexURLFilterBase(java.lang.String rules)` Constructs a new RegexURLFilter and inits it with a list of rules.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract RegexRule` | `createRule(boolean sign, java.lang.String regex)` Creates a new `RegexRule`.
    `protected abstract RegexRule` | `createRule(boolean sign, java.lang.String regex, java.lang.String hostOrDomain)` Creates a new `RegexRule`.
    `java.lang.String` | `filter(java.lang.String url)`
    `Configuration` | `getConf()`
    `protected abstract java.io.Reader` | `getRulesReader(Configuration conf)` Returns the name of the file of rules to use for a particular implementation.
    `static void` | `main(RegexURLFilterBase filter, java.lang.String[] args)` Filter the standard input using a RegexURLFilterBase.
    `void` | `setConf(Configuration conf)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### hasHostDomainRules

          protected boolean hasHostDomainRules

      Whether there are host- or domain-specific rules. If there are no specific rules host and domain name are not extracted from the URL to speed up the matching. `readRules(Reader)` automatically sets this to true if host- or domain-specific rules are used in the rule file.

  - ### Constructor Detail

    - #### RegexURLFilterBase

          public RegexURLFilterBase()

      Constructs a new empty RegexURLFilterBase

    - #### RegexURLFilterBase

          public RegexURLFilterBase(java.io.File filename)
                             throws java.io.IOException,
                                    java.lang.IllegalArgumentException

      Constructs a new RegexURLFilter and init it with a file of rules.
      Parameters:
        `filename` - is the name of rules file.
      Throws:
        `java.io.IOException`
        `java.lang.IllegalArgumentException`

    - #### RegexURLFilterBase

          public RegexURLFilterBase(java.lang.String rules)
                             throws java.io.IOException,
                                    java.lang.IllegalArgumentException

      Constructs a new RegexURLFilter and inits it with a list of rules.
      Parameters:
        `rules` - string with a list of rules, one rule per line
      Throws:
        `java.io.IOException`
        `java.lang.IllegalArgumentException`

    - #### RegexURLFilterBase

          protected RegexURLFilterBase(java.io.Reader reader)
                                throws java.io.IOException,
                                       java.lang.IllegalArgumentException

      Constructs a new RegexURLFilter and init it with a Reader of rules.
      Parameters:
        `reader` - is a reader of rules.
      Throws:
        `java.io.IOException`
        `java.lang.IllegalArgumentException`

  - ### Method Detail

    - #### createRule

          protected abstract RegexRule createRule(boolean sign,
                                                  java.lang.String regex)

      Creates a new `RegexRule`.
      Parameters:
        `sign` - of the regular expression. A `true` value means that any URL matching this rule must be included, whereas a `false` value means that any URL matching this rule must be excluded.
        `regex` - is the regular expression associated to this rule.

    - #### createRule

          protected abstract RegexRule createRule(boolean sign,
                                                  java.lang.String regex,
                                                  java.lang.String hostOrDomain)

      Creates a new `RegexRule`.
      Parameters:
        `sign` - of the regular expression. A `true` value means that any URL matching this rule must be included, whereas a `false` value means that any URL matching this rule must be excluded.
        `regex` - is the regular expression associated to this rule.
        `hostOrDomain` - the host or domain to which this regex belongs

    - #### getRulesReader

          protected abstract java.io.Reader getRulesReader(Configuration conf)
                                                    throws java.io.IOException

      Returns the name of the file of rules to use for a particular implementation.
      Parameters:
        `conf` - is the current configuration.
      Returns:
        the name of the resource containing the rules to use.
      Throws:
        `java.io.IOException`

    - #### filter

          public java.lang.String filter(java.lang.String url)

      Specified by:
        `filter` in interface `URLFilter`

    - #### setConf

          public void setConf(Configuration conf)

      Specified by:
        `setConf` in interface `Configurable`

    - #### getConf

          public Configuration getConf()

      Specified by:
        `getConf` in interface `Configurable`

    - #### main

          public static void main(RegexURLFilterBase filter,
                                  java.lang.String[] args)
                           throws java.io.IOException,
                                  java.lang.IllegalArgumentException

      Filter the standard input using a RegexURLFilterBase.
      Parameters:
        `filter` - is the RegexURLFilterBase to use for filtering the standard input.
        `args` - some optional parameters (not used).
      Throws:
        `java.io.IOException`
        `java.lang.IllegalArgumentException`

Copyright © 2019 The Apache Software Foundation