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