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    import com.liferay.portlet.messageboards.model.MBThread;
022    import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
023    
024    import javax.portlet.PortletMode;
025    import javax.portlet.PortletRequest;
026    import javax.portlet.PortletURL;
027    import javax.portlet.WindowState;
028    
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    
032    import org.apache.struts.action.Action;
033    import org.apache.struts.action.ActionForm;
034    import org.apache.struts.action.ActionForward;
035    import org.apache.struts.action.ActionMapping;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     */
040    public class FindThreadAction extends Action {
041    
042            public ActionForward execute(
043                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
044                            HttpServletResponse response)
045                    throws Exception {
046    
047                    try {
048                            long plid = ParamUtil.getLong(request, "p_l_id");
049                            long threadId = ParamUtil.getLong(request, "threadId");
050    
051                            MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
052    
053                            PortletURL portletURL = new PortletURLImpl(
054                                    request, PortletKeys.MESSAGE_BOARDS, plid,
055                                    PortletRequest.RENDER_PHASE);
056    
057                            portletURL.setWindowState(WindowState.NORMAL);
058                            portletURL.setPortletMode(PortletMode.VIEW);
059    
060                            portletURL.setParameter(
061                                    "struts_action", "/message_boards/view_message");
062                            portletURL.setParameter(
063                                    "messageId", String.valueOf(thread.getRootMessageId()));
064    
065                            response.sendRedirect(portletURL.toString());
066    
067                            return null;
068                    }
069                    catch (Exception e) {
070                            PortalUtil.sendError(e, request, response);
071    
072                            return null;
073                    }
074            }
075    
076    }