KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > task > LuceneTask


1 /* $Id: LuceneTask.java 43169 2004-08-02 00:19:42Z michi $ */
2
3 package org.apache.lenya.cms.task;
4
5 import org.apache.log4j.Category;
6
7 import java.io.File JavaDoc;
8
9 import org.apache.lenya.lucene.index.Index;
10 import org.apache.lenya.lucene.index.Indexer;
11
12 public class LuceneTask extends AbstractTask {
13     Category log = Category.getInstance(LuceneTask.class);
14
15     /**
16      * @see org.apache.lenya.cms.task.Task#execute(java.lang.String)
17      */

18     public void execute(String JavaDoc servletContextPath) throws ExecutionException {
19         try {
20             //outputParameters();
21

22             log.debug("Servlet context path: " + servletContextPath);
23
24             String JavaDoc publicationId = getParameters().getParameter("publication-id");
25             log.debug("Publication ID: " + publicationId);
26
27             String JavaDoc files = getParameters().getParameter("properties.files2index");
28             log.debug("Files 2 index: " + files);
29
30             String JavaDoc luceneConfig = getParameters().getParameter("config");
31             log.debug("Lucene configuration: " + luceneConfig);
32
33             String JavaDoc luceneConfigAbsolutePath = servletContextPath + File.separator + "lenya" + File.separator + "pubs" + File.separator + publicationId + File.separator + luceneConfig;
34             log.debug("Lucene configuration: " + luceneConfigAbsolutePath);
35
36             Indexer indexer = Index.getIndexer(luceneConfigAbsolutePath);
37         indexer.indexDocument(new File JavaDoc(files));
38         } catch (Exception JavaDoc e) {
39             log.error("" + e);
40         }
41     }
42
43     /**
44      * Output parameters for debugging
45      */

46     public void outputParameters() throws Exception JavaDoc {
47         String JavaDoc[] names = getParameters().getNames();
48         for (int i = 0; i < names.length; i++) {
49             log.error("Name: " + names[i]);
50             log.error("Value: " + getParameters().getParameter(names[i]));
51         }
52     }
53 }
54
Popular Tags