001    /**
002     * Copyright (c) 2000-2013 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            @Override
041            public ActionForward execute(
042                            ActionMapping actionMapping, ActionForm actionForm,
043                            HttpServletRequest request, HttpServletResponse response)
044                    throws Exception {
045    
046                    try {
047                            long plid = ParamUtil.getLong(request, "p_l_id");
048    
049                            PortletURL portletURL = new PortletURLImpl(
050                                    request, PortletKeys.MESSAGE_BOARDS, plid,
051                                    PortletRequest.RENDER_PHASE);
052    
053                            portletURL.setParameter("struts_action", "/message_boards/view");
054                            portletURL.setParameter("tabs2", "recent-posts");
055                            portletURL.setPortletMode(PortletMode.VIEW);
056                            portletURL.setWindowState(WindowState.NORMAL);
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    }