01: /* Copyright (C) 2003 Internet Archive.
02: *
03: * This file is part of the Heritrix web crawler (crawler.archive.org).
04: *
05: * Heritrix is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU Lesser Public License as published by
07: * the Free Software Foundation; either version 2.1 of the License, or
08: * any later version.
09: *
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: import javax.management.AttributeNotFoundException;
27:
28: import org.archive.crawler.framework.CrawlScope;
29:
30: /**
31: * DecidingScope: a Scope which makes its accept/reject decision based on
32: * whatever DecideRules have been set up inside it.
33: * @author gojomo
34: */
35: public class DecidingScope extends CrawlScope {
36:
37: private static final long serialVersionUID = -2942787757512964906L;
38:
39: //private static Logger logger =
40: // Logger.getLogger(DecidingScope.class.getName());
41: public static final String ATTR_DECIDE_RULES = "decide-rules";
42:
43: public DecidingScope(String name) {
44: super (name);
45: setDescription("DecidingScope. A Scope that applies one or "
46: + "more DecideRules to determine whether a URI is accepted "
47: + "or rejected (returns false).");
48: addElementToDefinition(new DecideRuleSequence(ATTR_DECIDE_RULES));
49: }
50:
51: protected DecideRule getDecideRule(Object o) {
52: try {
53: return (DecideRule) getAttribute(o, ATTR_DECIDE_RULES);
54: } catch (AttributeNotFoundException e) {
55: throw new RuntimeException(e);
56: }
57: }
58:
59: protected boolean innerAccepts(Object o) {
60: // would like to use identity test '==' here, but at some
61: // step string is being copied, and 'legal-type' mechanism
62: // doesn't enforce/maintain identity
63: return getDecideRule(o).decisionFor(o)
64: .equals(DecideRule.ACCEPT);
65: }
66:
67: /**
68: * Note that configuration updates may be necessary. Pass to
69: * constituent rules.
70: */
71: public void kickUpdate() {
72: super .kickUpdate();
73: // TODO: figure out if there's any way to reconcile this with
74: // overrides/refinement rules
75: getDecideRule(null).kickUpdate();
76: }
77: }
|