1
14
15 package com.liferay.portlet.messageboards.asset;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
20 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
21 import com.liferay.portal.kernel.util.HtmlUtil;
22 import com.liferay.portal.security.permission.ActionKeys;
23 import com.liferay.portal.security.permission.PermissionChecker;
24 import com.liferay.portal.theme.ThemeDisplay;
25 import com.liferay.portal.util.PortletKeys;
26 import com.liferay.portal.util.WebKeys;
27 import com.liferay.portlet.asset.model.BaseAssetRenderer;
28 import com.liferay.portlet.messageboards.model.MBMessage;
29 import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
30
31 import javax.portlet.PortletURL;
32 import javax.portlet.RenderRequest;
33 import javax.portlet.RenderResponse;
34
35
40 public class MBMessageAssetRenderer extends BaseAssetRenderer {
41
42 public MBMessageAssetRenderer(MBMessage message) {
43 _message = message;
44 }
45
46 public long getClassPK() {
47 return _message.getMessageId();
48 }
49
50 public long getGroupId() {
51 return _message.getGroupId();
52 }
53
54 public String getSummary() {
55 return HtmlUtil.stripHtml(_message.getBody());
56 }
57
58 public String getTitle() {
59 return _message.getSubject();
60 }
61
62 public PortletURL getURLEdit(
63 LiferayPortletRequest liferayPortletRequest,
64 LiferayPortletResponse liferayPortletResponse) {
65
66 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
67 PortletKeys.MESSAGE_BOARDS);
68
69 editPortletURL.setParameter(
70 "struts_action", "/message_boards/edit_message");
71 editPortletURL.setParameter(
72 "messageId", String.valueOf(_message.getMessageId()));
73
74 return editPortletURL;
75 }
76 public String getURLViewInContext(
77 LiferayPortletRequest liferayPortletRequest,
78 LiferayPortletResponse liferayPortletResponse,
79 String noSuchEntryRedirect) {
80
81 ThemeDisplay themeDisplay =
82 (ThemeDisplay)liferayPortletRequest.getAttribute(
83 WebKeys.THEME_DISPLAY);
84
85 return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
86 "/message_boards/find_message?messageId=" + _message.getMessageId();
87 }
88
89 public long getUserId() {
90 return _message.getUserId();
91 }
92
93 public boolean hasEditPermission(PermissionChecker permissionChecker)
94 throws PortalException, SystemException {
95
96 return MBMessagePermission.contains(
97 permissionChecker, _message, ActionKeys.UPDATE);
98 }
99
100 public boolean hasViewPermission(PermissionChecker permissionChecker)
101 throws PortalException, SystemException {
102
103 return MBMessagePermission.contains(
104 permissionChecker, _message, ActionKeys.VIEW);
105 }
106
107 public boolean isPrintable() {
108 return true;
109 }
110
111 public String render(
112 RenderRequest renderRequest, RenderResponse renderResponse,
113 String template)
114 throws Exception {
115
116 if (template.equals(TEMPLATE_FULL_CONTENT)) {
117 renderRequest.setAttribute(
118 WebKeys.MESSAGE_BOARDS_MESSAGE, _message);
119
120 return "/html/portlet/message_boards/asset/" + template + ".jsp";
121 }
122 else {
123 return null;
124 }
125 }
126
127 private MBMessage _message;
128
129 }