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.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortletKeys;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.asset.model.AssetRenderer;
026    import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
027    import com.liferay.portlet.calendar.model.CalEvent;
028    import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
029    import com.liferay.portlet.calendar.service.permission.CalendarPermission;
030    
031    import javax.portlet.PortletURL;
032    
033    /**
034     * @author Juan Fernández
035     */
036    public class CalEventAssetRendererFactory extends BaseAssetRendererFactory {
037    
038            public static final String CLASS_NAME = CalEvent.class.getName();
039    
040            public static final String TYPE = "event";
041    
042            public AssetRenderer getAssetRenderer(long classPK, int type)
043                    throws PortalException, SystemException {
044    
045                    CalEvent event = CalEventLocalServiceUtil.getEvent(classPK);
046    
047                    return new CalEventAssetRenderer(event);
048            }
049    
050            public String getClassName() {
051                    return CLASS_NAME;
052            }
053    
054            public String getType() {
055                    return TYPE;
056            }
057    
058            public PortletURL getURLAdd(
059                    LiferayPortletRequest liferayPortletRequest,
060                    LiferayPortletResponse liferayPortletResponse) {
061    
062                    ThemeDisplay themeDisplay =
063                            (ThemeDisplay)liferayPortletRequest.getAttribute(
064                                    WebKeys.THEME_DISPLAY);
065    
066                    PortletURL addAssetURL = null;
067    
068                    if (CalendarPermission.contains(
069                                    themeDisplay.getPermissionChecker(),
070                                    themeDisplay.getScopeGroupId(), ActionKeys.ADD_EVENT)) {
071    
072                            addAssetURL = liferayPortletResponse.createRenderURL(
073                                    PortletKeys.CALENDAR);
074    
075                            addAssetURL.setParameter("struts_action", "/calendar/edit_event");
076                    }
077    
078                    return addAssetURL;
079            }
080    
081            protected String getIconPath(ThemeDisplay themeDisplay) {
082                    return themeDisplay.getPathThemeImages() + "/common/date.png";
083            }
084    
085    }