1 /* ConfiguredDecideRule
2 *
3 * $Id: ConfiguredDecideRule.java 4649 2006-09-25 17:16:55Z paul_jack $
4 *
5 * Created on Mar 3, 2005
6 *
7 * Copyright (C) 2005 Internet Archive.
8 *
9 * This file is part of the Heritrix web crawler (crawler.archive.org).
10 *
11 * Heritrix is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * any later version.
15 *
16 * Heritrix is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser Public License
22 * along with Heritrix; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 package org.archive.crawler.deciderules;
26
27 import org.archive.crawler.settings.SimpleType;
28
29
30 /***
31 * Rule which can be configured to ACCEPT or REJECT at
32 * operator's option.
33 *
34 * @author gojomo
35 */
36 public class ConfiguredDecideRule extends DecideRule {
37
38 private static final long serialVersionUID = -7084695808452312555L;
39
40 public final static String ATTR_DECISION = "decision";
41 public final static String[] ALLOWED_TYPES = new String[] {ACCEPT, REJECT};
42
43 public ConfiguredDecideRule(String name) {
44 super(name);
45 setDescription("FRAMEWORK: Should not appear as choice");
46 addElementToDefinition(new SimpleType(ATTR_DECISION,
47 "Decision applied if this rule is triggered. " +
48 "Otherwise PASS.", ACCEPT, ALLOWED_TYPES));
49 }
50
51 public Object decisionFor(Object object) {
52 return singlePossibleNonPassDecision(object);
53 }
54
55 public Object singlePossibleNonPassDecision(Object object) {
56 Object decision = getUncheckedAttribute(object, ATTR_DECISION);
57 // We're not always getting back from the settings system the
58 // interned versions of ACCEPT and REJECT. Guard against this.
59 Object result = PASS;
60 for (int i = 0; i < ALLOWED_TYPES.length; i++) {
61 if (ALLOWED_TYPES[i] == decision ||
62 ALLOWED_TYPES[i].equals(decision)) {
63 result = ALLOWED_TYPES[i];
64 break;
65 }
66 }
67 return result;
68 }
69 }