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  import com.liferay.portlet.messageboards.model.MBThread;
22  import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
23  
24  import javax.portlet.PortletMode;
25  import javax.portlet.PortletRequest;
26  import javax.portlet.PortletURL;
27  import javax.portlet.WindowState;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  import org.apache.struts.action.Action;
33  import org.apache.struts.action.ActionForm;
34  import org.apache.struts.action.ActionForward;
35  import org.apache.struts.action.ActionMapping;
36  
37  /**
38   * <a href="FindThreadAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class FindThreadAction extends Action {
43  
44      public ActionForward execute(
45              ActionMapping mapping, ActionForm form, HttpServletRequest request,
46              HttpServletResponse response)
47          throws Exception {
48  
49          try {
50              long plid = ParamUtil.getLong(request, "p_l_id");
51              long threadId = ParamUtil.getLong(request, "threadId");
52  
53              MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
54  
55              PortletURL portletURL = new PortletURLImpl(
56                  request, PortletKeys.MESSAGE_BOARDS, plid,
57                  PortletRequest.RENDER_PHASE);
58  
59              portletURL.setWindowState(WindowState.NORMAL);
60              portletURL.setPortletMode(PortletMode.VIEW);
61  
62              portletURL.setParameter(
63                  "struts_action", "/message_boards/view_message");
64              portletURL.setParameter(
65                  "messageId", String.valueOf(thread.getRootMessageId()));
66  
67              response.sendRedirect(portletURL.toString());
68  
69              return null;
70          }
71          catch (Exception e) {
72              PortalUtil.sendError(e, request, response);
73  
74              return null;
75          }
76      }
77  
78  }