001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
038     * @author Juan Fernández
039     * @author Raymond Augé
040     * @author Sergio González
041     */
042    public class CalEventAssetRendererFactory extends BaseAssetRendererFactory {
043    
044            public static final String CLASS_NAME = CalEvent.class.getName();
045    
046            public static final String TYPE = "event";
047    
048            public AssetRenderer getAssetRenderer(long classPK, int type)
049                    throws PortalException, SystemException {
050    
051                    CalEvent event = CalEventLocalServiceUtil.getEvent(classPK);
052    
053                    return new CalEventAssetRenderer(event);
054            }
055    
056            public String getClassName() {
057                    return CLASS_NAME;
058            }
059    
060            public String getType() {
061                    return TYPE;
062            }
063    
064            @Override
065            public PortletURL getURLAdd(
066                            LiferayPortletRequest liferayPortletRequest,
067                            LiferayPortletResponse liferayPortletResponse)
068                    throws PortalException, SystemException {
069    
070                    ThemeDisplay themeDisplay =
071                            (ThemeDisplay)liferayPortletRequest.getAttribute(
072                                    WebKeys.THEME_DISPLAY);
073    
074                    if (!CalendarPermission.contains(
075                                    themeDisplay.getPermissionChecker(),
076                                    themeDisplay.getScopeGroupId(), ActionKeys.ADD_EVENT)) {
077    
078                            return null;
079                    }
080    
081                    PortletURL portletURL = PortletURLFactoryUtil.create(
082                            liferayPortletRequest, PortletKeys.CALENDAR,
083                            getControlPanelPlid(themeDisplay), PortletRequest.RENDER_PHASE);
084    
085                    portletURL.setParameter("struts_action", "/calendar/edit_event");
086    
087                    return portletURL;
088            }
089    
090            @Override
091            public boolean hasPermission(
092                            PermissionChecker permissionChecker, long classPK, String actionId)
093                    throws Exception {
094    
095                    return CalEventPermission.contains(
096                            permissionChecker, classPK, actionId);
097            }
098    
099            @Override
100            public boolean isLinkable() {
101                    return _LINKABLE;
102            }
103    
104            @Override
105            protected String getIconPath(ThemeDisplay themeDisplay) {
106                    return themeDisplay.getPathThemeImages() + "/common/date.png";
107            }
108    
109            private static final boolean _LINKABLE = true;
110    
111    }