KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > tool > impl > HeadersTool


1 package net.javacoding.jspider.tool.impl;
2
3 import net.javacoding.jspider.api.event.JSpiderEvent;
4 import net.javacoding.jspider.api.event.resource.*;
5 import net.javacoding.jspider.api.model.*;
6 import net.javacoding.jspider.tool.Parameters;
7
8 /**
9  * $Id: HeadersTool.java,v 1.3 2003/04/01 19:44:42 vanrogu Exp $
10  */

11 public class HeadersTool extends BaseToolImpl {
12
13     protected boolean done;
14
15     public HeadersTool() {
16         done = false;
17     }
18
19     public String JavaDoc getName() {
20         return "headers";
21     }
22
23     public boolean validateParams(Parameters parameters) {
24         return parameters.getValues().length == 0;
25     }
26
27     public void notify(JSpiderEvent event) {
28         if (!done) {
29             FetchTriedResource resource = null;
30             if (event instanceof ResourceFetchedEvent) {
31                 ResourceFetchedEvent rfe = (ResourceFetchedEvent) event;
32                 resource = rfe.getResource();
33                 done = true;
34             }
35             if (event instanceof ResourceFetchErrorEvent) {
36                 ResourceFetchErrorEvent rfe = (ResourceFetchErrorEvent) event;
37                 resource = rfe.getResource();
38                 done = true;
39             }
40             if (resource != null) {
41                 HTTPHeader[] headers = resource.getHeaders();
42                 for (int i = 0; i < headers.length; i++) {
43                     HTTPHeader header = headers[i];
44                     System.out.println(header.getName() + ":" + header.getValue());
45                 }
46             }
47         }
48     }
49 }
Popular Tags