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