001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.util.PortalUtil;
019    import com.liferay.portal.util.PortletKeys;
020    import com.liferay.portlet.PortletURLImpl;
021    
022    import javax.portlet.PortletMode;
023    import javax.portlet.PortletRequest;
024    import javax.portlet.PortletURL;
025    import javax.portlet.WindowState;
026    
027    import javax.servlet.http.HttpServletRequest;
028    import javax.servlet.http.HttpServletResponse;
029    
030    import org.apache.struts.action.Action;
031    import org.apache.struts.action.ActionForm;
032    import org.apache.struts.action.ActionForward;
033    import org.apache.struts.action.ActionMapping;
034    
035    /**
036     * @author Brian Wing Shun Chan
037     */
038    public class FindRecentPostsAction extends Action {
039    
040            public ActionForward execute(
041                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
042                            HttpServletResponse response)
043                    throws Exception {
044    
045                    try {
046                            long plid = ParamUtil.getLong(request, "p_l_id");
047    
048                            PortletURL portletURL = new PortletURLImpl(
049                                    request, PortletKeys.MESSAGE_BOARDS, plid,
050                                    PortletRequest.RENDER_PHASE);
051    
052                            portletURL.setWindowState(WindowState.NORMAL);
053                            portletURL.setPortletMode(PortletMode.VIEW);
054    
055                            portletURL.setParameter("struts_action", "/message_boards/view");
056                            portletURL.setParameter("tabs2", "recent-posts");
057    
058                            response.sendRedirect(portletURL.toString());
059    
060                            return null;
061                    }
062                    catch (Exception e) {
063                            PortalUtil.sendError(e, request, response);
064    
065                            return null;
066                    }
067            }
068    
069    }