1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
41
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
64
65
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
76
77 getDecideRule(null).kickUpdate();
78 }
79 }