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.portlet.LiferayPortletRequest;
18  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.theme.ThemeDisplay;
22  import com.liferay.portal.util.PortletKeys;
23  import com.liferay.portal.util.WebKeys;
24  import com.liferay.portlet.asset.model.BaseAssetRenderer;
25  import com.liferay.portlet.messageboards.model.MBMessage;
26  import com.liferay.portlet.messageboards.service.permission.MBPermission;
27  
28  import javax.portlet.PortletURL;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  /**
33   * <a href="MBMessageAssetRenderer.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Julio Camarero
36   */
37  public class MBMessageAssetRenderer extends BaseAssetRenderer {
38  
39      public MBMessageAssetRenderer(MBMessage message) {
40          _message = message;
41      }
42  
43      public long getClassPK() {
44          return _message.getMessageId();
45      }
46  
47      public long getGroupId() {
48          return _message.getGroupId();
49      }
50  
51      public String getSummary() {
52          return HtmlUtil.stripHtml(_message.getBody());
53      }
54  
55      public String getTitle() {
56          return _message.getSubject();
57      }
58  
59      public PortletURL getURLEdit(
60          LiferayPortletRequest liferayPortletRequest,
61          LiferayPortletResponse liferayPortletResponse) {
62  
63          ThemeDisplay themeDisplay =
64              (ThemeDisplay)liferayPortletRequest.getAttribute(
65                  WebKeys.THEME_DISPLAY);
66  
67          PortletURL editPortletURL = null;
68  
69          if (MBPermission.contains(
70                  themeDisplay.getPermissionChecker(),
71                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_MESSAGE)) {
72  
73              editPortletURL = liferayPortletResponse.createRenderURL(
74                  PortletKeys.MESSAGE_BOARDS);
75  
76              editPortletURL.setParameter(
77                  "struts_action", "/message_boards/edit_message");
78              editPortletURL.setParameter(
79                  "messageId", String.valueOf(_message.getMessageId()));
80          }
81  
82          return editPortletURL;
83      }
84      public String getURLViewInContext(
85          LiferayPortletRequest liferayPortletRequest,
86          LiferayPortletResponse liferayPortletResponse,
87          String noSuchEntryRedirect) {
88  
89          ThemeDisplay themeDisplay =
90              (ThemeDisplay)liferayPortletRequest.getAttribute(
91                  WebKeys.THEME_DISPLAY);
92  
93          return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
94              "/message_boards/find_message?messageId=" + _message.getMessageId();
95      }
96  
97      public long getUserId() {
98          return _message.getUserId();
99      }
100 
101     public boolean isPrintable() {
102         return true;
103     }
104 
105     public String render(
106             RenderRequest renderRequest, RenderResponse renderResponse,
107             String template)
108         throws Exception {
109 
110         if (template.equals(TEMPLATE_FULL_CONTENT)) {
111             renderRequest.setAttribute(
112                 WebKeys.MESSAGE_BOARDS_MESSAGE, _message);
113 
114             return "/html/portlet/message_boards/asset/" + template + ".jsp";
115         }
116         else {
117             return null;
118         }
119     }
120 
121     private MBMessage _message;
122 
123 }