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.PortletURLFactoryUtil;
027 import com.liferay.portlet.asset.model.AssetRenderer;
028 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
029 import com.liferay.portlet.calendar.model.CalEvent;
030 import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
031 import com.liferay.portlet.calendar.service.permission.CalEventPermission;
032 import com.liferay.portlet.calendar.service.permission.CalendarPermission;
033
034 import javax.portlet.PortletRequest;
035 import javax.portlet.PortletURL;
036
037
042 public class CalEventAssetRendererFactory extends BaseAssetRendererFactory {
043
044 public static final String TYPE = "event";
045
046 public AssetRenderer getAssetRenderer(long classPK, int type)
047 throws PortalException, SystemException {
048
049 CalEvent event = CalEventLocalServiceUtil.getEvent(classPK);
050
051 CalEventAssetRenderer calEventAssetRenderer = new CalEventAssetRenderer(
052 event);
053
054 calEventAssetRenderer.setAssetRendererType(type);
055
056 return calEventAssetRenderer;
057 }
058
059 public String getClassName() {
060 return CalEvent.class.getName();
061 }
062
063 public String getType() {
064 return TYPE;
065 }
066
067 @Override
068 public PortletURL getURLAdd(
069 LiferayPortletRequest liferayPortletRequest,
070 LiferayPortletResponse liferayPortletResponse)
071 throws PortalException, SystemException {
072
073 ThemeDisplay themeDisplay =
074 (ThemeDisplay)liferayPortletRequest.getAttribute(
075 WebKeys.THEME_DISPLAY);
076
077 if (!CalendarPermission.contains(
078 themeDisplay.getPermissionChecker(),
079 themeDisplay.getScopeGroupId(), ActionKeys.ADD_EVENT)) {
080
081 return null;
082 }
083
084 PortletURL portletURL = PortletURLFactoryUtil.create(
085 liferayPortletRequest, PortletKeys.CALENDAR,
086 getControlPanelPlid(themeDisplay), PortletRequest.RENDER_PHASE);
087
088 portletURL.setParameter("struts_action", "/calendar/edit_event");
089
090 return portletURL;
091 }
092
093 @Override
094 public boolean hasPermission(
095 PermissionChecker permissionChecker, long classPK, String actionId)
096 throws Exception {
097
098 return CalEventPermission.contains(
099 permissionChecker, classPK, actionId);
100 }
101
102 @Override
103 public boolean isLinkable() {
104 return _LINKABLE;
105 }
106
107 @Override
108 protected String getIconPath(ThemeDisplay themeDisplay) {
109 return themeDisplay.getPathThemeImages() + "/common/date.png";
110 }
111
112 private static final boolean _LINKABLE = true;
113
114 }