View Javadoc

1   /**
2    * Copyright (c) 2009 Techmatrix GmbH, All rights reserved.
3    *
4    */
5   
6   package de.iqser.portlets;
7   
8   import java.io.IOException;
9   import java.util.ArrayList;
10  import java.util.List;
11  import java.util.Set;
12  
13  import javax.portlet.ActionRequest;
14  import javax.portlet.ActionResponse;
15  import javax.portlet.PortletContext;
16  import javax.portlet.PortletException;
17  import javax.portlet.PortletRequestDispatcher;
18  import javax.portlet.RenderRequest;
19  import javax.portlet.RenderResponse;
20  import javax.portlet.WindowState;
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpSession;
23  
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portal.kernel.util.WebKeys;
28  import com.liferay.portal.theme.ThemeDisplay;
29  import com.liferay.portal.util.PortalUtil;
30  
31  import de.iqser.beans.BreadcrumbBean;
32  import de.iqser.beans.ContentBean;
33  import de.iqser.portlets.IqserBasePortlet;
34  
35  public class SearchPortlet extends IqserBasePortlet {
36  	
37  	private static Log _ilog = LogFactoryUtil.getLog(SearchPortlet.class);
38  
39  	public final static String ACTION_SEARCH= "ACTION_SEARCH";
40  	public final static String PARAM_SEARCH_INPUT= "PARAM_SEARCH_INPUT";
41  	
42  	public final static String PREF_MAX_LENGTH= "maxlength";
43  	public final static String PREF_SIZE= "size";
44  	public final static String PREF_DEFAULT_VALUE= "defaultvalue";
45  	
46  	// Portlet init-Params
47  	public void init() throws PortletException {
48  		viewJSP = getInitParameter("view-jsp");
49  		editJSP = getInitParameter("edit-jsp");
50  		// helpJSP = getInitParameter("help-jsp");
51  	}
52  
53  	public void doView(RenderRequest req, RenderResponse res)
54  			throws IOException, PortletException {
55  
56  
57  		res.setContentType("text/html");
58  
59  		PortletContext portletContext = getPortletContext();
60  
61  		String action = ParamUtil.getString(req, PARAM_ACTION);
62  
63  		PortletRequestDispatcher reqDispatcher = null;
64  		if( action != null && action.startsWith(ACTION_SEARCH)) {		// found a " at end, therefore startsWith
65  
66  		
67  		} else {
68  			reqDispatcher = portletContext.getRequestDispatcher(viewJSP);
69  			ThemeDisplay themeDisplay = (ThemeDisplay) req
70  					.getAttribute(WebKeys.THEME_DISPLAY);
71  			themeDisplay.setStateExclusive(false);
72  			themeDisplay.setStateMaximized(false);
73  		}
74  
75  		reqDispatcher.include(req, res);
76  
77  	}
78  
79  	// processAction is located in BasePortlet
80  	// If more is needed, this can override this method
81  	// the helper methods processActionUpdatePrefs and processActionInsertPref
82  	public void processAction(ActionRequest actionRequest,
83  			ActionResponse actionResponse) throws PortletException, IOException {
84  
85  		super.processAction(actionRequest, actionResponse);
86  		
87  		actionResponse.setWindowState(WindowState.NORMAL);
88  		
89  		String action= actionRequest.getParameter(PARAM_ACTION);
90  		if( action == null || !action.equals(ACTION_SEARCH) )  {
91  			return;	// probably a preferences action handled by base portlet
92  		}
93  		
94  		// remove old cached data, if any to force a reload in the display portlet
95  		HttpServletRequest servletRequest= PortalUtil.getHttpServletRequest( actionRequest);
96  		HttpSession servletSession= servletRequest.getSession();
97  		List<ContentBean> contentList= (List<ContentBean>) servletSession.getAttribute(DEIQSER_CACHED_DATA);
98  		if( contentList != null) {
99  			servletSession.removeAttribute(DEIQSER_CACHED_DATA);
100 		}
101 		List<BreadcrumbBean> relatedList= (List<BreadcrumbBean>) servletSession.getAttribute(DEIQSER_RELATED_LIST);
102 		if( relatedList != null) {
103 			servletSession.removeAttribute(DEIQSER_RELATED_LIST);
104 		}
105 		Set<String> selectedTypes= (Set<String>) servletSession.getAttribute(DisplayPortlet.DEIQSER_SELECTED_TYPES);
106 		if( selectedTypes != null) {
107 			servletSession.removeAttribute(DEIQSER_SELECTED_TYPES);
108 		}
109 		
110 		String searchInput= actionRequest.getParameter(PARAM_SEARCH_INPUT);
111 		if( searchInput != null) {
112 			searchInput= searchInput.trim();
113 			actionResponse.setRenderParameter(PUBLIC_RENDER_PARAM_SEARCH_INPUT, searchInput);
114 			// create a new list for breadcrumb
115 			BreadcrumbBean bcBean= new BreadcrumbBean();
116 			bcBean.setId(searchInput);
117 			bcBean.setDisplayName(searchInput);
118 			relatedList= new ArrayList<BreadcrumbBean>();
119 			relatedList.add(bcBean);
120 			servletSession.setAttribute(DEIQSER_RELATED_LIST, relatedList);
121 		}
122 		
123 	}
124 }