KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > deciderules > ConfiguredDecideRule


1 /* ConfiguredDecideRule
2 *
3 * $Id: ConfiguredDecideRule.java,v 1.10.16.1 2007/01/13 01:31:13 stack-sf Exp $
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 JavaDoc ATTR_DECISION = "decision";
41     public final static String JavaDoc[] ALLOWED_TYPES = new String JavaDoc[] {ACCEPT, REJECT};
42     
43     public ConfiguredDecideRule(String JavaDoc 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 JavaDoc decisionFor(Object JavaDoc object) {
52         return singlePossibleNonPassDecision(object);
53     }
54     
55     public Object JavaDoc singlePossibleNonPassDecision(Object JavaDoc object) {
56         Object JavaDoc 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 JavaDoc 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 }
70
Popular Tags