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