1
14
15 package com.liferay.portlet.messageboards.action;
16
17 import com.liferay.portal.NoSuchLayoutException;
18 import com.liferay.portal.kernel.util.ParamUtil;
19 import com.liferay.portal.model.Layout;
20 import com.liferay.portal.model.LayoutConstants;
21 import com.liferay.portal.model.LayoutTypePortlet;
22 import com.liferay.portal.service.LayoutLocalServiceUtil;
23 import com.liferay.portal.util.PortalUtil;
24 import com.liferay.portal.util.PortletKeys;
25 import com.liferay.portlet.PortletURLImpl;
26 import com.liferay.portlet.messageboards.model.MBMessage;
27 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
28
29 import javax.portlet.PortletMode;
30 import javax.portlet.PortletRequest;
31 import javax.portlet.PortletURL;
32 import javax.portlet.WindowState;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36
37 import org.apache.struts.action.Action;
38 import org.apache.struts.action.ActionForm;
39 import org.apache.struts.action.ActionForward;
40 import org.apache.struts.action.ActionMapping;
41
42
47 public class FindMessageAction extends Action {
48
49 public ActionForward execute(
50 ActionMapping mapping, ActionForm form, HttpServletRequest request,
51 HttpServletResponse response)
52 throws Exception {
53
54 try {
55 long plid = ParamUtil.getLong(request, "p_l_id");
56 long messageId = ParamUtil.getLong(request, "messageId");
57
58 plid = getPlid(plid, messageId);
59
60 PortletURL portletURL = new PortletURLImpl(
61 request, PortletKeys.MESSAGE_BOARDS, plid,
62 PortletRequest.RENDER_PHASE);
63
64 portletURL.setWindowState(WindowState.NORMAL);
65 portletURL.setPortletMode(PortletMode.VIEW);
66
67 portletURL.setParameter(
68 "struts_action", "/message_boards/view_message");
69 portletURL.setParameter("messageId", String.valueOf(messageId));
70
71 response.sendRedirect(portletURL.toString());
72
73 return null;
74 }
75 catch (Exception e) {
76 PortalUtil.sendError(e, request, response);
77
78 return null;
79 }
80 }
81
82 protected long getPlid(long plid, long messageId) throws Exception {
83 if (plid != LayoutConstants.DEFAULT_PLID) {
84 try {
85 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
86
87 LayoutTypePortlet layoutTypePortlet =
88 (LayoutTypePortlet)layout.getLayoutType();
89
90 if (layoutTypePortlet.hasPortletId(
91 PortletKeys.MESSAGE_BOARDS)) {
92
93 return plid;
94 }
95 }
96 catch (NoSuchLayoutException nsle) {
97 }
98 }
99
100 MBMessage message = MBMessageLocalServiceUtil.getMessage(messageId);
101
102 plid = PortalUtil.getPlidFromPortletId(
103 message.getGroupId(), PortletKeys.MESSAGE_BOARDS);
104
105 if (plid != LayoutConstants.DEFAULT_PLID) {
106 return plid;
107 }
108 else {
109 throw new NoSuchLayoutException(
110 "No page was found with the Message Boards portlet.");
111 }
112 }
113
114 }