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