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