1
14
15 package com.liferay.portlet.messageboards.action;
16
17 import com.liferay.portal.kernel.servlet.SessionErrors;
18 import com.liferay.portal.kernel.util.ArrayUtil;
19 import com.liferay.portal.kernel.util.ParamUtil;
20 import com.liferay.portal.kernel.util.Validator;
21 import com.liferay.portal.kernel.workflow.StatusConstants;
22 import com.liferay.portal.security.auth.PrincipalException;
23 import com.liferay.portal.struts.PortletAction;
24 import com.liferay.portal.util.PortletKeys;
25 import com.liferay.portal.util.PropsValues;
26 import com.liferay.portal.util.WebKeys;
27 import com.liferay.portlet.PortalPreferences;
28 import com.liferay.portlet.PortletPreferencesFactoryUtil;
29 import com.liferay.portlet.messageboards.NoSuchMessageException;
30 import com.liferay.portlet.messageboards.model.MBMessageDisplay;
31 import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
32
33 import javax.portlet.PortletConfig;
34 import javax.portlet.RenderRequest;
35 import javax.portlet.RenderResponse;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40
41
46 public class ViewMessageAction extends PortletAction {
47
48 public ActionForward render(
49 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
50 RenderRequest renderRequest, RenderResponse renderResponse)
51 throws Exception {
52
53 try {
54 long messageId = ParamUtil.getLong(renderRequest, "messageId");
55
56 PortalPreferences preferences =
57 PortletPreferencesFactoryUtil.getPortalPreferences(
58 renderRequest);
59
60 String threadView = ParamUtil.getString(
61 renderRequest, "threadView");
62
63 if (Validator.isNotNull(threadView)) {
64 preferences.setValue(
65 PortletKeys.MESSAGE_BOARDS, "thread-view", threadView);
66 }
67 else {
68 threadView = preferences.getValue(
69 PortletKeys.MESSAGE_BOARDS, "thread-view",
70 PropsValues.MESSAGE_BOARDS_THREAD_VIEWS_DEFAULT);
71 }
72
73 if (!ArrayUtil.contains(
74 PropsValues.MESSAGE_BOARDS_THREAD_VIEWS, threadView)) {
75
76 threadView = PropsValues.MESSAGE_BOARDS_THREAD_VIEWS_DEFAULT;
77
78 preferences.setValue(
79 PortletKeys.MESSAGE_BOARDS, "thread-view", threadView);
80 }
81
82 MBMessageDisplay messageDisplay =
83 MBMessageServiceUtil.getMessageDisplay(
84 messageId, StatusConstants.APPROVED, threadView);
85
86 renderRequest.setAttribute(
87 WebKeys.MESSAGE_BOARDS_MESSAGE, messageDisplay);
88
89 return mapping.findForward("portlet.message_boards.view_message");
90 }
91 catch (Exception e) {
92 if (e instanceof NoSuchMessageException ||
93 e instanceof PrincipalException) {
94
95 SessionErrors.add(renderRequest, e.getClass().getName());
96
97 return mapping.findForward("portlet.message_boards.error");
98 }
99 else {
100 throw e;
101 }
102 }
103 }
104
105 }