001    /**
002     * Copyright (c) 2000-2010 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.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    /**
036     * @author Juan Fernández
037     * @author Raymond Augé
038     */
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    }