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.portlet.LiferayPortletRequest;
018    import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortletKeys;
023    import com.liferay.portal.util.PropsValues;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.asset.model.BaseAssetRenderer;
026    import com.liferay.portlet.calendar.model.CalEvent;
027    import com.liferay.portlet.calendar.service.permission.CalEventPermission;
028    
029    import javax.portlet.PortletURL;
030    import javax.portlet.RenderRequest;
031    import javax.portlet.RenderResponse;
032    
033    /**
034     * @author Juan Fernández
035     */
036    public class CalEventAssetRenderer extends BaseAssetRenderer {
037    
038            public CalEventAssetRenderer(CalEvent event){
039                    _event = event;
040            }
041    
042            public long getClassPK() {
043                    return _event.getEventId();
044            }
045    
046            public String getDiscussionPath() {
047                    if (PropsValues.CALENDAR_EVENT_COMMENTS_ENABLED) {
048                            return "edit_event_discussion";
049                    }
050                    else {
051                            return null;
052                    }
053            }
054    
055            public long getGroupId() {
056                    return _event.getGroupId();
057            }
058    
059            public String getSummary() {
060                    return _event.getTitle();
061            }
062    
063            public String getTitle() {
064                    return _event.getTitle();
065            }
066    
067            public PortletURL getURLEdit(
068                    LiferayPortletRequest liferayPortletRequest,
069                    LiferayPortletResponse liferayPortletResponse) {
070    
071                    PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
072                            PortletKeys.CALENDAR);
073    
074                    editPortletURL.setParameter(
075                            "struts_action", "/calendar/edit_event");
076                    editPortletURL.setParameter(
077                            "eventId", String.valueOf(_event.getEventId()));
078    
079                    return editPortletURL;
080            }
081    
082            public String getURLViewInContext(
083                    LiferayPortletRequest liferayPortletRequest,
084                    LiferayPortletResponse liferayPortletResponse,
085                    String noSuchEntryRedirect) {
086    
087                    ThemeDisplay themeDisplay =
088                            (ThemeDisplay)liferayPortletRequest.getAttribute(
089                                    WebKeys.THEME_DISPLAY);
090    
091                    return themeDisplay.getPathMain() +
092                            "/calendar/find_event?eventId=" + _event.getEventId();
093            }
094    
095            public long getUserId() {
096                    return _event.getUserId();
097            }
098    
099            public String getUuid() {
100                    return _event.getUuid();
101            }
102    
103            public boolean hasEditPermission(PermissionChecker permissionChecker) {
104                    return CalEventPermission.contains(
105                            permissionChecker, _event, ActionKeys.UPDATE);
106            }
107    
108            public boolean hasViewPermission(PermissionChecker permissionChecker) {
109                    return CalEventPermission.contains(
110                            permissionChecker, _event, ActionKeys.VIEW);
111            }
112    
113            public boolean isPrintable() {
114                    return true;
115            }
116    
117            public String render(
118                            RenderRequest renderRequest, RenderResponse renderResponse,
119                            String template)
120                    throws Exception {
121    
122                    if (template.equals(TEMPLATE_ABSTRACT) ||
123                            template.equals(TEMPLATE_FULL_CONTENT)) {
124    
125                            renderRequest.setAttribute(WebKeys.CALENDAR_EVENT, _event);
126    
127                            return "/html/portlet/calendar/asset/" + template + ".jsp";
128                    }
129                    else {
130                            return null;
131                    }
132            }
133    
134            protected String getIconPath(ThemeDisplay themeDisplay) {
135                    return themeDisplay.getPathThemeImages() + "/common/date.png";
136            }
137    
138            private CalEvent _event;
139    
140    }