001
014
015 package com.liferay.portlet.calendar.asset;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021 import com.liferay.portal.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.asset.model.AssetRenderer;
027 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
028 import com.liferay.portlet.calendar.model.CalEvent;
029 import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
030 import com.liferay.portlet.calendar.service.permission.CalEventPermission;
031 import com.liferay.portlet.calendar.service.permission.CalendarPermission;
032
033 import javax.portlet.PortletURL;
034
035
039 public class CalEventAssetRendererFactory extends BaseAssetRendererFactory {
040
041 public static final String CLASS_NAME = CalEvent.class.getName();
042
043 public static final String TYPE = "event";
044
045 public AssetRenderer getAssetRenderer(long classPK, int type)
046 throws PortalException, SystemException {
047
048 CalEvent event = CalEventLocalServiceUtil.getEvent(classPK);
049
050 return new CalEventAssetRenderer(event);
051 }
052
053 public String getClassName() {
054 return CLASS_NAME;
055 }
056
057 public String getType() {
058 return TYPE;
059 }
060
061 public PortletURL getURLAdd(
062 LiferayPortletRequest liferayPortletRequest,
063 LiferayPortletResponse liferayPortletResponse) {
064
065 ThemeDisplay themeDisplay =
066 (ThemeDisplay)liferayPortletRequest.getAttribute(
067 WebKeys.THEME_DISPLAY);
068
069 PortletURL addAssetURL = null;
070
071 if (CalendarPermission.contains(
072 themeDisplay.getPermissionChecker(),
073 themeDisplay.getScopeGroupId(), ActionKeys.ADD_EVENT)) {
074
075 addAssetURL = liferayPortletResponse.createRenderURL(
076 PortletKeys.CALENDAR);
077
078 addAssetURL.setParameter("struts_action", "/calendar/edit_event");
079 }
080
081 return addAssetURL;
082 }
083
084 public boolean hasPermission(
085 PermissionChecker permissionChecker, long classPK, String actionId)
086 throws Exception {
087
088 return CalEventPermission.contains(
089 permissionChecker, classPK, actionId);
090 }
091
092 protected String getIconPath(ThemeDisplay themeDisplay) {
093 return themeDisplay.getPathThemeImages() + "/common/date.png";
094 }
095
096 }