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   * BasicScope.java
20   * Created on Oct 1, 2003
21   *
22   * $Header$
23   */
24  package org.archive.crawler.deciderules;
25  
26  
27  import javax.management.AttributeNotFoundException;
28  
29  import org.archive.crawler.framework.CrawlScope;
30  
31  /***
32   * DecidingScope: a Scope which makes its accept/reject decision based on 
33   * whatever DecideRules have been set up inside it.
34   * @author gojomo
35   */
36  public class DecidingScope extends CrawlScope {
37  
38      private static final long serialVersionUID = -2942787757512964906L;
39  
40      //private static Logger logger =
41      //    Logger.getLogger(DecidingScope.class.getName());
42      public static final String ATTR_DECIDE_RULES = "decide-rules";
43  
44      public DecidingScope(String name) {
45          super(name);
46          setDescription(
47              "DecidingScope. A Scope that applies one or " +
48              "more DecideRules to determine whether a URI is accepted " +
49              "or rejected (returns false).");
50          addElementToDefinition(new DecideRuleSequence(
51              ATTR_DECIDE_RULES));
52      }
53      
54      protected DecideRule getDecideRule(Object o) {
55          try {
56              return (DecideRule)getAttribute(o, ATTR_DECIDE_RULES);
57          } catch (AttributeNotFoundException e) {
58              throw new RuntimeException(e);
59          }
60      }
61  
62      protected boolean innerAccepts(Object o) {
63          // would like to use identity test '==' here, but at some
64          // step string is being copied, and 'legal-type' mechanism
65          // doesn't enforce/maintain identity
66          return getDecideRule(o).decisionFor(o).equals(DecideRule.ACCEPT);
67      }
68      
69      /***
70       * Note that configuration updates may be necessary. Pass to
71       * constituent rules.
72       */
73      public void kickUpdate() {
74          super.kickUpdate();
75          // TODO: figure out if there's any way to reconcile this with
76          // overrides/refinement rules
77          getDecideRule(null).kickUpdate();
78      }
79  }