KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > workbench > LabelPredicate


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * 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 LabelPredicate implements LinkPredicate, PagePredicate {
38     String JavaDoc labels;
39     boolean orTerms;
40
41     public LabelPredicate (String JavaDoc labels, boolean orTerms) {
42         this.labels = labels;
43         this.orTerms = orTerms;
44     }
45
46     public boolean equals (Object JavaDoc object) {
47         if (! (object instanceof LabelPredicate))
48             return false;
49         LabelPredicate p = (LabelPredicate)object;
50         return p.labels.equals (labels)
51             && p.orTerms == orTerms;
52     }
53
54     public String JavaDoc getLabels () {
55         return labels;
56     }
57
58     public boolean getOrTerms () {
59         return orTerms;
60     }
61
62     public void connected (Crawler crawler) {}
63     public void disconnected (Crawler crawler) {}
64     
65     public boolean shouldVisit (Link link) {
66         return orTerms ? link.hasAnyLabels (labels) : link.hasAllLabels (labels);
67     }
68
69     public boolean shouldActOn (Page page) {
70         return orTerms ? page.hasAnyLabels (labels) : page.hasAllLabels (labels);
71     }
72 }
73
74
Popular Tags