Source code: org/acs/damsel/client/search/SearchAction.java
1 package org.acs.damsel.client.search;
2
3 import org.apache.struts.action.*;
4 import javax.servlet.http.*;
5 import org.acs.damsel.srvr.collection.*;
6 import org.acs.damsel.client.ClientApp;
7 import org.acs.damsel.srvr.search.*;
8 import java.sql.*;
9 import org.apache.log4j.*;
10
11 /** This checks for a keyword input. If a keyword is provided, the user is
12 * forwarded to the search results page, otherwise he/she is redirected to the
13 * search page where an error is generated.
14 * */
15
16 public class SearchAction extends Action {
17 public ActionForward execute(ActionMapping actionMapping,
18 ActionForm actionForm,
19 HttpServletRequest httpServletRequest,
20 HttpServletResponse httpServletResponse) {
21
22 Logger log = Logger.getLogger(SearchAction.class);
23
24 SearchForm searchForm = (SearchForm) actionForm;
25 String searchKeyword = (String) searchForm.getSearchKeyword();
26 String collectionName = (String) searchForm.getCollectionSelect();
27
28 /* Notify the session which type of search this is -- is used by searchResults.jsp
29 to intelligently display correct search results depending on type */
30 String searchType = "search";
31 httpServletRequest.getSession().setAttribute("searchType", searchType);
32 httpServletRequest.getSession().setAttribute("collectionName", collectionName);
33
34 if(searchKeyword.trim().equals("") || searchKeyword.trim().length() == 0) {
35 ActionErrors errors = new ActionErrors();
36 errors.add("search", new ActionError("search.input.blank"));
37 this.saveErrors(httpServletRequest, errors);
38 return actionMapping.findForward("search");
39 }
40 else {
41 SearchMgr mgr = ClientApp.instance().getSearchMgr();
42 try {
43 CollectionView colView = mgr.simpleSearch(searchKeyword, collectionName);
44 httpServletRequest.getSession().setAttribute("colView", colView);
45 return actionMapping.findForward("searchResults");
46 }
47 catch (SQLException ex) {
48 log.warn("Unexpected SQLException thrown in SearchAction");
49 return actionMapping.findForward("search");
50 }
51 }
52 }
53 }