KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > LinkEvent


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;
34
35 /**
36  * Link event. A LinkEvent is issued when the crawler
37  * starts or stops retrieving a link, and when it makes
38  * a decision about a link.
39  */

40 public class LinkEvent
41 {
42     Crawler crawler;
43     int id;
44     Link link;
45     Throwable JavaDoc exception;
46
47     /**
48      * No event occured on this link yet. Never delivered in a LinkEvent,
49      * but may be returned by link.getStatus().
50      */

51     public static final int NONE = 0;
52     
53     /**
54      * Link was rejected by shouldVisit()
55      */

56     public static final int SKIPPED = 1;
57
58     /**
59      * Link has already been visited during the crawl, so it was skipped.
60      */

61     public static final int ALREADY_VISITED = 2;
62
63     /**
64      * Link was accepted by walk() but exceeds the maximum depth from the start set.
65      */

66     public static final int TOO_DEEP = 3;
67
68     /**
69      * Link was accepted by walk() and is waiting to be downloaded
70      */

71     public static final int QUEUED = 4;
72
73     /**
74      * Link is being retrieved
75      */

76     public static final int RETRIEVING = 5;
77
78     /**
79      * An error occurred in retrieving the page.
80      * The error can be obtained from getException().
81      */

82     public static final int ERROR = 6;
83
84     /**
85      * Link has been retrieved
86      */

87     public static final int DOWNLOADED = 7;
88
89     /**
90      * Link has been thoroughly processed by crawler
91      */

92     public static final int VISITED = 8;
93
94     /**
95      * Map from id code (RETRIEVING) to name ("retrieving")
96      */

97     public static final String JavaDoc[] eventName = {
98         "none",
99         "skipped",
100         "already visited",
101         "too deep",
102         "queued",
103         "retrieving",
104         "error",
105         "downloaded",
106         "visited"
107     };
108
109     /**
110      * Make a LinkEvent.
111      * @param crawler Crawler that generated this event
112      * @param id event code, like LinkEvent.RETRIEVING
113      * @param link Link on which this event occurred
114      */

115     public LinkEvent (Crawler crawler, int id, Link link) {
116         this.crawler = crawler;
117         this.id = id;
118         this.link = link;
119     }
120
121     /**
122      * Make a LinkEvent for an error.
123      * @param crawler Crawler that generated this event
124      * @param id Event code, usually ERROR
125      * @param link Link on which this event occurred
126      * @param exception Throwable
127      */

128     public LinkEvent (Crawler crawler, int id, Link link, Throwable JavaDoc exception) {
129         this.crawler = crawler;
130         this.id = id;
131         this.link = link;
132         this.exception = exception;
133     }
134
135     /**
136      * Get crawler that generated the event
137      * @return crawler
138      */

139     public Crawler getCrawler () {
140         return crawler;
141     }
142
143     /**
144      * Get event id
145      * @return id
146      */

147     public int getID () { return id; }
148
149     /**
150      * Get event name (string equivalent to its ID)
151      * @return id
152      */

153     public String JavaDoc getName () { return eventName[id]; }
154
155     /**
156      * Get link to which this event occurred.
157      * @return link
158      */

159     public Link getLink () { return link; }
160
161     /**
162      * Get exception related to this event. Valid when ID == ERROR.
163      * @return exception object
164      */

165     public Throwable JavaDoc getException () { return exception; }
166
167     /**
168      * Convert this event to a String describing it.
169      */

170     public String JavaDoc toString () {
171         String JavaDoc result;
172         if (id == ERROR)
173             result = exception.toString();
174         else
175             result = eventName[id];
176         result += " " + link.toDescription ();
177         return result;
178     }
179 }
180
Popular Tags