1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
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  /**
36   * <a href="MBMessageAssetRenderer.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Julio Camarero
39   * @author Juan Fernández
40   */
41  public class MBMessageAssetRenderer extends BaseAssetRenderer {
42  
43      public MBMessageAssetRenderer(MBMessage message) {
44          _message = message;
45      }
46  
47      public long getClassPK() {
48          return _message.getMessageId();
49      }
50  
51      public long getGroupId() {
52          return _message.getGroupId();
53      }
54  
55      public String getSummary() {
56          return HtmlUtil.stripHtml(_message.getBody());
57      }
58  
59      public String getTitle() {
60          return _message.getSubject();
61      }
62  
63      public PortletURL getURLEdit(
64          LiferayPortletRequest liferayPortletRequest,
65          LiferayPortletResponse liferayPortletResponse) {
66  
67          PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
68              PortletKeys.MESSAGE_BOARDS);
69  
70          editPortletURL.setParameter(
71              "struts_action", "/message_boards/edit_message");
72          editPortletURL.setParameter(
73              "messageId", String.valueOf(_message.getMessageId()));
74  
75          return editPortletURL;
76      }
77      public String getURLViewInContext(
78          LiferayPortletRequest liferayPortletRequest,
79          LiferayPortletResponse liferayPortletResponse,
80          String noSuchEntryRedirect) {
81  
82          ThemeDisplay themeDisplay =
83              (ThemeDisplay)liferayPortletRequest.getAttribute(
84                  WebKeys.THEME_DISPLAY);
85  
86          return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
87              "/message_boards/find_message?messageId=" + _message.getMessageId();
88      }
89  
90      public long getUserId() {
91          return _message.getUserId();
92      }
93  
94      public boolean hasEditPermission(PermissionChecker permissionChecker)
95          throws PortalException, SystemException {
96  
97          return MBMessagePermission.contains(
98              permissionChecker, _message, ActionKeys.UPDATE);
99      }
100 
101     public boolean hasViewPermission(PermissionChecker permissionChecker)
102         throws PortalException, SystemException {
103 
104         return MBMessagePermission.contains(
105             permissionChecker, _message, ActionKeys.VIEW);
106     }
107 
108     public boolean isPrintable() {
109         return true;
110     }
111 
112     public String render(
113             RenderRequest renderRequest, RenderResponse renderResponse,
114             String template)
115         throws Exception {
116 
117         if (template.equals(TEMPLATE_ABSTRACT) ||
118             template.equals(TEMPLATE_FULL_CONTENT)) {
119 
120             renderRequest.setAttribute(
121                 WebKeys.MESSAGE_BOARDS_MESSAGE, _message);
122 
123             return "/html/portlet/message_boards/asset/" + template + ".jsp";
124         }
125         else {
126             return null;
127         }
128     }
129 
130     protected String getIconPath(ThemeDisplay themeDisplay) {
131         return themeDisplay.getPathThemeImages() + "/common/conversation.png";
132     }
133 
134     private MBMessage _message;
135 
136 }