KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > spider > docfilter > FilterChain


1 package net.matuschek.spider.docfilter;
2
3 /*********************************************
4     Copyright (c) 2001 by Daniel Matuschek
5 *********************************************/

6
7 import java.util.Vector JavaDoc;
8
9 import net.matuschek.http.HttpDoc;
10
11 /**
12  * This object defines a chain of DocumentFilters
13  *
14  * @author Daniel Matuschek
15  * @version $Revision: 1.1 $
16  */

17 public class FilterChain {
18
19   /** All filters */
20   Vector JavaDoc<DocumentFilter> filters = new Vector JavaDoc<DocumentFilter>();
21
22   /**
23    * Creates a new FilterChain without any installed filters
24    */

25   public FilterChain() {
26   }
27
28   /**
29    * Adds a new filter to the filter chain
30    */

31   public void add(DocumentFilter filter) {
32     filters.add(filter);
33   }
34
35
36   /**
37    * Processes a HttpDoc by the defined filter chain
38    *
39    * @param doc the input document to process
40    * @return a HttpDoc that is the result of filtering
41    */

42   public HttpDoc process(HttpDoc doc)
43     throws FilterException
44   {
45     for (int i=0; i<filters.size(); i++) {
46       DocumentFilter filter = filters.elementAt(i);
47       doc = filter.process(doc);
48     }
49     return doc;
50   }
51 }
52
Popular Tags