01: /* FetchStatusDecideRule
02: *
03: * $Id: FetchStatusDecideRule.java 4649 2006-09-25 17:16:55Z paul_jack $
04: *
05: * Created on Aug 11, 2006
06: *
07: * Copyright (C) 2006 Internet Archive.
08: *
09: * 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.datamodel.CrawlURI;
28: import org.archive.crawler.settings.SimpleType;
29:
30: /**
31: * Rule applies the configured decision for any URI which has a
32: * fetch status equal to the 'target-status' setting.
33: *
34: * @author gojomo
35: */
36: public class FetchStatusDecideRule extends PredicatedDecideRule {
37:
38: private static final long serialVersionUID = 5820599300395594619L;
39:
40: private static final String ATTR_TARGET_STATUS = "target-status";
41:
42: /**
43: * Default access so available to test code.
44: */
45: static final Integer DEFAULT_TARGET_STATUS = new Integer(0);
46:
47: /**
48: * Usual constructor.
49: * @param name Name of this DecideRule.
50: */
51: public FetchStatusDecideRule(String name) {
52: super (name);
53: setDescription("FetchStatusDecideRule. Applies configured decision "
54: + "to any URI that has a fetch status equal to the setting.");
55: addElementToDefinition(new SimpleType(ATTR_TARGET_STATUS,
56: "Fetch status for which the configured decision will be"
57: + "applied.", DEFAULT_TARGET_STATUS));
58: }
59:
60: /**
61: * Evaluate whether given object is over the threshold number of
62: * hops.
63: *
64: * @param object
65: * @return true if the mx-hops is exceeded
66: */
67: protected boolean evaluate(Object object) {
68: try {
69: CrawlURI curi = (CrawlURI) object;
70: return curi.getFetchStatus() == (Integer) getUncheckedAttribute(
71: curi, ATTR_TARGET_STATUS);
72: } catch (ClassCastException e) {
73: // if not CrawlURI, always disregard
74: return false;
75: }
76: }
77: }
|