1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.messageboards.action;
16  
17  import com.liferay.portal.kernel.util.ParamUtil;
18  import com.liferay.portal.util.PortalUtil;
19  import com.liferay.portal.util.PortletKeys;
20  import com.liferay.portlet.PortletURLImpl;
21  
22  import javax.portlet.PortletMode;
23  import javax.portlet.PortletRequest;
24  import javax.portlet.PortletURL;
25  import javax.portlet.WindowState;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.apache.struts.action.Action;
31  import org.apache.struts.action.ActionForm;
32  import org.apache.struts.action.ActionForward;
33  import org.apache.struts.action.ActionMapping;
34  
35  /**
36   * <a href="FindRecentPostsAction.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   */
40  public class FindRecentPostsAction extends Action {
41  
42      public ActionForward execute(
43              ActionMapping mapping, ActionForm form, HttpServletRequest request,
44              HttpServletResponse response)
45          throws Exception {
46  
47          try {
48              long plid = ParamUtil.getLong(request, "p_l_id");
49  
50              PortletURL portletURL = new PortletURLImpl(
51                  request, PortletKeys.MESSAGE_BOARDS, plid,
52                  PortletRequest.RENDER_PHASE);
53  
54              portletURL.setWindowState(WindowState.NORMAL);
55              portletURL.setPortletMode(PortletMode.VIEW);
56  
57              portletURL.setParameter("struts_action", "/message_boards/view");
58              portletURL.setParameter("tabs2", "recent-posts");
59  
60              response.sendRedirect(portletURL.toString());
61  
62              return null;
63          }
64          catch (Exception e) {
65              PortalUtil.sendError(e, request, response);
66  
67              return null;
68          }
69      }
70  
71  }