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.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.security.permission.ActionKeys;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portal.util.PortletKeys;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.asset.model.AssetRenderer;
26  import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
27  import com.liferay.portlet.calendar.model.CalEvent;
28  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
29  import com.liferay.portlet.calendar.service.permission.CalendarPermission;
30  
31  import javax.portlet.PortletURL;
32  
33  /**
34   * <a href="CalEventAssetRendererFactory.java.html"><b><i>View Source</i></b>
35   * </a>
36   *
37   * @author Juan Fernández
38   */
39  public class CalEventAssetRendererFactory extends BaseAssetRendererFactory {
40  
41      public static final String CLASS_NAME = CalEvent.class.getName();
42  
43      public static final String TYPE = "event";
44  
45      public AssetRenderer getAssetRenderer(long classPK)
46          throws PortalException, SystemException {
47  
48          CalEvent event = CalEventLocalServiceUtil.getEvent(classPK);
49  
50          return new CalEventAssetRenderer(event);
51      }
52  
53      public String getClassName() {
54          return CLASS_NAME;
55      }
56  
57      public String getType() {
58          return TYPE;
59      }
60  
61      public PortletURL getURLAdd(
62          LiferayPortletRequest liferayPortletRequest,
63          LiferayPortletResponse liferayPortletResponse) {
64  
65          ThemeDisplay themeDisplay =
66              (ThemeDisplay)liferayPortletRequest.getAttribute(
67                  WebKeys.THEME_DISPLAY);
68  
69          PortletURL addAssetURL = null;
70  
71          if (CalendarPermission.contains(
72                  themeDisplay.getPermissionChecker(),
73                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_EVENT)) {
74  
75              addAssetURL = liferayPortletResponse.createRenderURL(
76                  PortletKeys.CALENDAR);
77  
78              addAssetURL.setParameter("struts_action", "/calendar/edit_event");
79          }
80  
81          return addAssetURL;
82      }
83  
84      protected String getIconPath(ThemeDisplay themeDisplay) {
85          return themeDisplay.getPathThemeImages() + "/common/date.png";
86      }
87  
88  }