1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.jetspeed.modules.actions.portlets;
17
18 import java.util.List;
19 import org.apache.turbine.util.RunData;
20 import org.apache.velocity.context.Context;
21
22 import org.apache.jetspeed.portal.Portlet;
23 import org.apache.jetspeed.util.PortletSessionState;
24 import org.apache.jetspeed.services.search.Search;
25 import org.apache.jetspeed.services.search.ParsedObject;
26 import org.apache.jetspeed.services.search.SearchResults;
27
28 /***
29 * Search Actions built here
30 *
31 * @author <a href="mailto:taylor@apache.org">David Sean taylor</a>
32 * @version $Id: SearchAction.java,v 1.3 2004/02/23 02:56:58 jford Exp $
33 */
34
35 public class SearchAction extends GenericMVCAction
36 {
37 public final static String SEARCH_STRING = "search";
38 public final static String SEARCH_RESULTS = "search_results";
39 public final static String SEARCH_RESULTSIZE = "search_resultsize";
40
41 /***
42 * Subclasses must override this method to provide default behavior
43 * for the portlet action
44 */
45 public void buildNormalContext(Portlet portlet,
46 Context context,
47 RunData rundata)
48 throws Exception
49 {
50 List results = (List)rundata.getRequest().getAttribute(SEARCH_RESULTS);
51 if (null == results)
52 {
53 results = (List)PortletSessionState.getAttribute(rundata, SEARCH_RESULTS);
54
55
56 }
57 else
58 {
59
60 PortletSessionState.setAttribute(rundata, SEARCH_RESULTS, results);
61 }
62
63 if (null != results)
64 {
65 context.put(SEARCH_RESULTS, results);
66 }
67
68 String searchString = (String)rundata.getParameters().getString(SEARCH_STRING);
69 if (searchString == null || searchString.trim().length() == 0)
70 {
71 searchString = (String)PortletSessionState.getAttribute(rundata, SEARCH_STRING);
72 }
73 else
74 {
75 PortletSessionState.setAttribute(rundata, SEARCH_STRING, searchString);
76 }
77
78 context.put(SEARCH_STRING, searchString);
79
80 if (results != null)
81 {
82
83 context.put(SEARCH_RESULTSIZE, new Integer(results.size()));
84 }
85 }
86
87 public void doSearch(RunData rundata, Context context)
88 {
89
90 String searchString = (String)rundata.getParameters().getString(SEARCH_STRING);
91
92 if (searchString == null || searchString.trim().length() == 0)
93 {
94 return;
95 }
96
97
98
99
100 ParsedObject result = null;
101 SearchResults results = Search.search(searchString);
102
103 rundata.getRequest().setAttribute(SEARCH_RESULTS, results.getResults());
104 }
105
106 }
107