1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }