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 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
42
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
80
81 getDecideRule(null).kickUpdate();
82 }
83 }