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.calendar.asset;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
18  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.security.permission.PermissionChecker;
21  import com.liferay.portal.theme.ThemeDisplay;
22  import com.liferay.portal.util.PortletKeys;
23  import com.liferay.portal.util.PropsValues;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.asset.model.BaseAssetRenderer;
26  import com.liferay.portlet.calendar.model.CalEvent;
27  import com.liferay.portlet.calendar.service.permission.CalEventPermission;
28  
29  import javax.portlet.PortletURL;
30  import javax.portlet.RenderRequest;
31  import javax.portlet.RenderResponse;
32  
33  /**
34   * <a href="CalEventAssetRenderer.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Juan Fernández
37   */
38  public class CalEventAssetRenderer extends BaseAssetRenderer {
39  
40      public CalEventAssetRenderer(CalEvent event){
41          _event = event;
42      }
43  
44      public long getClassPK() {
45          return _event.getEventId();
46      }
47  
48      public String getDiscussionPath() {
49          if (PropsValues.CALENDAR_EVENT_COMMENTS_ENABLED) {
50              return "edit_event_discussion";
51          }
52          else {
53              return null;
54          }
55      }
56  
57      public long getGroupId() {
58          return _event.getGroupId();
59      }
60  
61      public String getSummary() {
62          return _event.getTitle();
63      }
64  
65      public String getTitle() {
66          return _event.getTitle();
67      }
68  
69      public PortletURL getURLEdit(
70          LiferayPortletRequest liferayPortletRequest,
71          LiferayPortletResponse liferayPortletResponse) {
72  
73          PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
74              PortletKeys.CALENDAR);
75  
76          editPortletURL.setParameter(
77              "struts_action", "/calendar/edit_event");
78          editPortletURL.setParameter(
79              "eventId", String.valueOf(_event.getEventId()));
80  
81          return editPortletURL;
82      }
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.getPathMain() +
94              "/calendar/find_event?eventId=" + _event.getEventId();
95      }
96  
97      public long getUserId() {
98          return _event.getUserId();
99      }
100 
101     public boolean hasEditPermission(PermissionChecker permissionChecker) {
102         return CalEventPermission.contains(
103             permissionChecker, _event, ActionKeys.UPDATE);
104     }
105 
106     public boolean hasViewPermission(PermissionChecker permissionChecker) {
107         return CalEventPermission.contains(
108             permissionChecker, _event, ActionKeys.VIEW);
109     }
110 
111     public boolean isPrintable() {
112         return true;
113     }
114 
115     public String render(
116             RenderRequest renderRequest, RenderResponse renderResponse,
117             String template)
118         throws Exception {
119 
120         if (template.equals(TEMPLATE_ABSTRACT) ||
121             template.equals(TEMPLATE_FULL_CONTENT)) {
122 
123             renderRequest.setAttribute(WebKeys.CALENDAR_EVENT, _event);
124 
125             return "/html/portlet/calendar/asset/" + template + ".jsp";
126         }
127         else {
128             return null;
129         }
130     }
131 
132     protected String getIconPath(ThemeDisplay themeDisplay) {
133         return themeDisplay.getPathThemeImages() + "/common/date.png";
134     }
135 
136     private CalEvent _event;
137 
138 }