KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > search > SearchAction


1 package org.nextime.ion.backoffice.action.search;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 import javax.servlet.ServletException JavaDoc;
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9
10 import org.apache.struts.action.ActionError;
11 import org.apache.struts.action.ActionErrors;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionForward;
14 import org.apache.struts.action.ActionMapping;
15 import org.nextime.ion.backoffice.action.BaseAction;
16 import org.nextime.ion.framework.config.Config;
17 import org.nextime.ion.framework.helper.Searcher;
18 import org.nextime.ion.framework.mapping.Mapping;
19
20 public class SearchAction extends BaseAction {
21
22     public ActionForward perform(
23         ActionMapping mapping,
24         ActionForm form,
25         HttpServletRequest JavaDoc request,
26         HttpServletResponse JavaDoc response)
27         throws IOException JavaDoc, ServletException JavaDoc {
28
29         // check if user is correctly logged
30
checkUser(request);
31
32         // get the keywords
33
String JavaDoc keyWords = request.getParameter("keyWords");
34         
35         // put the index list
36
request.setAttribute( "indexs", Config.getInstance().getIndexNames() );
37
38         if (keyWords != null) {
39             if (!keyWords.trim().equals("")) {
40                 try {
41                     Mapping.begin();
42                     Vector JavaDoc result = Searcher.search(keyWords, request.getParameter("index"));
43                     if( result.size()>0 ) {
44                         request.setAttribute("result", result);
45                     }
46                     Mapping.rollback();
47                 } catch (Exception JavaDoc e) {
48                     Mapping.rollback();
49                     throw new ServletException JavaDoc(e);
50                 }
51             } else {
52                 ActionErrors errors = new ActionErrors();
53                 ActionError error = new ActionError("error.search.noKeyWords");
54                 errors.add("keys",error);
55                 request.setAttribute(ERROR_KEY,errors);
56             }
57         }
58
59         // Forward to the next page
60
return (mapping.findForward("view"));
61     }
62
63 }
64
Popular Tags