01: /*
02: * WebSphinx web-crawling toolkit
03: *
04: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
05: * reserved.
06: *
07: * Redistribution and use in source and binary forms, with or without
08: * modification, are permitted provided that the following conditions
09: * are met:
10: *
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: *
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in
16: * the documentation and/or other materials provided with the
17: * distribution.
18: *
19: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30: *
31: */
32:
33: package websphinx.workbench;
34:
35: import websphinx.*;
36:
37: public class DualPredicate implements LinkPredicate, PagePredicate {
38: Object positive, negative;
39:
40: public DualPredicate(Object positive, Object negative) {
41: this .positive = positive;
42: this .negative = negative;
43: }
44:
45: public boolean equals(Object object) {
46: if (!(object instanceof DualPredicate))
47: return false;
48: DualPredicate p = (DualPredicate) object;
49: return p.positive.equals(positive)
50: && p.negative.equals(negative);
51: }
52:
53: public Object getPositivePredicate() {
54: return positive;
55: }
56:
57: public Object getNegativePredicate() {
58: return negative;
59: }
60:
61: public void connected(Crawler crawler) {
62: if (positive instanceof LinkPredicate)
63: ((LinkPredicate) positive).connected(crawler);
64: else if (positive instanceof PagePredicate)
65: ((LinkPredicate) positive).connected(crawler);
66:
67: if (negative instanceof LinkPredicate)
68: ((LinkPredicate) negative).connected(crawler);
69: else if (negative instanceof PagePredicate)
70: ((LinkPredicate) negative).connected(crawler);
71: }
72:
73: public void disconnected(Crawler crawler) {
74: if (positive instanceof LinkPredicate)
75: ((LinkPredicate) positive).disconnected(crawler);
76: else if (positive instanceof PagePredicate)
77: ((LinkPredicate) positive).disconnected(crawler);
78:
79: if (negative instanceof LinkPredicate)
80: ((LinkPredicate) negative).disconnected(crawler);
81: else if (negative instanceof PagePredicate)
82: ((LinkPredicate) negative).disconnected(crawler);
83: }
84:
85: public boolean shouldVisit(Link link) {
86: return ((LinkPredicate) positive).shouldVisit(link)
87: && !((LinkPredicate) negative).shouldVisit(link);
88: }
89:
90: public boolean shouldActOn(Page page) {
91: return ((PagePredicate) positive).shouldActOn(page)
92: && !((PagePredicate) negative).shouldActOn(page);
93: }
94: }
|