KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > indexer > IndexingFilters


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.indexer;
5
6 import java.util.HashMap JavaDoc;
7
8 import org.apache.lucene.document.Document;
9
10 import net.nutch.plugin.*;
11 import net.nutch.parse.Parse;
12 import net.nutch.fetcher.FetcherOutput;
13
14 /** Creates and caches {@link IndexingFilter} implementing plugins.*/
15 public class IndexingFilters {
16
17   private static final IndexingFilter[] CACHE;
18   static {
19     try {
20       ExtensionPoint point = PluginRepository.getInstance()
21         .getExtensionPoint(IndexingFilter.X_POINT_ID);
22       if (point == null)
23         throw new RuntimeException JavaDoc(IndexingFilter.X_POINT_ID+" not found.");
24       Extension[] extensions = point.getExtentens();
25       HashMap JavaDoc filterMap = new HashMap JavaDoc();
26       for (int i = 0; i < extensions.length; i++) {
27         Extension extension = extensions[i];
28         IndexingFilter filter = (IndexingFilter)extension.getExtensionInstance();
29         if (!filterMap.containsKey(filter.getClass().getName())) {
30             filterMap.put(filter.getClass().getName(), filter);
31         }
32       }
33       CACHE = (IndexingFilter[])filterMap.values().toArray(new IndexingFilter[0]);
34     } catch (PluginRuntimeException e) {
35       throw new RuntimeException JavaDoc(e);
36     }
37   }
38
39   private IndexingFilters() {} // no public ctor
40

41   /** Run all defined filters. */
42   public static Document filter(Document doc, Parse parse, FetcherOutput fo)
43     throws IndexingException {
44
45     for (int i = 0; i < CACHE.length; i++) {
46       doc = CACHE[i].filter(doc, parse, fo);
47     }
48
49     return doc;
50   }
51 }
52
Popular Tags