View Javadoc

1   /* Copyright (C) 2003 Internet Archive.
2    *
3    * This file is part of the Heritrix web crawler (crawler.archive.org).
4    *
5    * Heritrix is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser Public License as published by
7    * the Free Software Foundation; either version 2.1 of the License, or
8    * any later version.
9    *
10   * Heritrix is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser Public License
16   * along with Heritrix; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *
19   * OrFilter.java
20   * Created on Nov 13, 2003
21   *
22   * $Header$
23   */
24  package org.archive.crawler.deciderules;
25  
26  import javax.management.AttributeNotFoundException;
27  
28  import org.archive.crawler.framework.Filter;
29  
30  /***
31   * DecidingFilter: a classic Filter which makes its accept/reject
32   * decision based on whatever {@link DecideRule}s have been set up inside
33   * it. 
34   *
35   * @author gojomo
36   *
37   */
38  public class DecidingFilter extends Filter {
39  
40      private static final long serialVersionUID = -7275555425381445477L;
41      //private static final Logger logger =
42      //    Logger.getLogger(DecidingFilter.class.getName());
43      public static final String ATTR_DECIDE_RULES = "decide-rules";
44      
45      public DecidingFilter(String name, String description) {
46          this(name);
47          setDescription(description);
48      }
49  
50      public DecidingFilter(String name) {
51          super(name,
52              "DecidingFilter. A filter that applies one or " +
53              "more DecideRules " +
54              "to determine whether a URI is accepted (returns true) or " +
55              "rejected (returns false). Only a final decision of " +
56              "ACCEPT returns true from the filter; either REJECT or " +
57              "PASS returns false.");
58          addElementToDefinition(
59              new DecideRuleSequence(ATTR_DECIDE_RULES));
60      }
61  
62      protected DecideRule getDecideRule(Object o) {
63          try {
64              return (DecideRule)getAttribute(o, ATTR_DECIDE_RULES);
65          } catch (AttributeNotFoundException e) {
66              throw new RuntimeException(e);
67          }
68      }
69  
70      protected boolean innerAccepts(Object o) {
71          return getDecideRule(o).decisionFor(o) == DecideRule.ACCEPT;
72      }
73  
74      /***
75       * Note that configuration updates may be necessary. Pass to
76       * constituent filters.
77       */
78      public void kickUpdate() {
79          // TODO: figure out if there's any way to reconcile this with
80          // overrides/refinement filters
81          getDecideRule(null).kickUpdate();
82      }
83  }