KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > net > admin > ManageSearchEngine


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002,2003 Fraunhofer Gesellschaft
5  * Fraunhofer Institut for Computer Architecture and Software Technology
6  * All Rights Reserved.
7  *
8  * Please visit http://snipsnap.org/ for updates and contact.
9  *
10  * --LICENSE NOTICE--
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  * --LICENSE NOTICE--
25  */

26 package org.snipsnap.net.admin;
27
28 import org.snipsnap.app.Application;
29 import org.snipsnap.config.Configuration;
30 import org.snipsnap.container.Components;
31 import org.snipsnap.snip.SnipSpace;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Map JavaDoc;
37
38 public class ManageSearchEngine implements SetupHandler {
39   public String JavaDoc getName() {
40     return "search";
41   }
42
43   private Map JavaDoc indexerThreads = new HashMap JavaDoc();
44
45   public Map JavaDoc setup(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Configuration config, Map JavaDoc errors) {
46     if (request.getParameter("reset") != null) {
47       final String JavaDoc appOid = (String JavaDoc) Application.get().getObject(Application.OID);
48       Thread JavaDoc indexerThread = (Thread JavaDoc) indexerThreads.get(appOid);
49       if (indexerThread != null && indexerThread.isAlive()) {
50         if (request.getSession().getAttribute("running") == null) {
51           request.getSession().setAttribute("running", new HashMap JavaDoc());
52         }
53         return errors;
54       } else if (indexerThread != null) {
55         request.getSession().removeAttribute("running");
56         indexerThreads.remove(appOid);
57         indexerThread = null;
58       }
59       indexerThread = new Thread JavaDoc() {
60         public void run() {
61           Application.get().storeObject(Application.OID, appOid);
62           ((SnipSpace) Components.getComponent(SnipSpace.class)).reIndex();
63         }
64       };
65       indexerThread.start();
66       request.getSession().setAttribute("indexerThread", indexerThread);
67       request.getSession().setAttribute("running", new HashMap JavaDoc());
68     }
69
70     return errors;
71   }
72 }
73
Popular Tags