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