1 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 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 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 56 } 57 else 58 { 59 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 context.put(SEARCH_RESULTSIZE, new Integer (results.size())); 84 } 85 } 86 87 public void doSearch(RunData rundata, Context context) 88 { 89 String searchString = (String )rundata.getParameters().getString(SEARCH_STRING); 91 92 if (searchString == null || searchString.trim().length() == 0) 93 { 94 return; 95 } 96 97 ParsedObject result = null; 101 SearchResults results = Search.search(searchString); 102 rundata.getRequest().setAttribute(SEARCH_RESULTS, results.getResults()); 104 } 105 106 } 107 108 | Popular Tags |