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