001    /**
002     * Copyright (c) 2000-2013 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 java.util.Locale;
030    
031    import javax.portlet.PortletRequest;
032    import javax.portlet.PortletURL;
033    import javax.portlet.RenderRequest;
034    import javax.portlet.RenderResponse;
035    
036    /**
037     * @author Julio Camarero
038     * @author Juan Fern??ndez
039     * @author Sergio Gonz??lez
040     */
041    public class BookmarksEntryAssetRenderer extends BaseAssetRenderer {
042    
043            public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
044                    _entry = entry;
045            }
046    
047            @Override
048            public long getClassPK() {
049                    return _entry.getEntryId();
050            }
051    
052            @Override
053            public long getGroupId() {
054                    return _entry.getGroupId();
055            }
056    
057            @Override
058            public String getSummary(Locale locale) {
059                    return HtmlUtil.stripHtml(_entry.getDescription());
060            }
061    
062            @Override
063            public String getTitle(Locale locale) {
064                    return _entry.getName();
065            }
066    
067            @Override
068            public PortletURL getURLEdit(
069                            LiferayPortletRequest liferayPortletRequest,
070                            LiferayPortletResponse liferayPortletResponse)
071                    throws Exception {
072    
073                    PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
074                            getControlPanelPlid(liferayPortletRequest), PortletKeys.BOOKMARKS,
075                            PortletRequest.RENDER_PHASE);
076    
077                    portletURL.setParameter("struts_action", "/bookmarks/edit_entry");
078                    portletURL.setParameter(
079                            "folderId", String.valueOf(_entry.getFolderId()));
080                    portletURL.setParameter("entryId", String.valueOf(_entry.getEntryId()));
081    
082                    return portletURL;
083            }
084    
085            @Override
086            public String getURLViewInContext(
087                    LiferayPortletRequest liferayPortletRequest,
088                    LiferayPortletResponse liferayPortletResponse,
089                    String noSuchEntryRedirect) {
090    
091                    return getURLViewInContext(
092                            liferayPortletRequest, noSuchEntryRedirect, "/bookmarks/find_entry",
093                            "entryId", _entry.getEntryId());
094            }
095    
096            @Override
097            public long getUserId() {
098                    return _entry.getUserId();
099            }
100    
101            @Override
102            public String getUserName() {
103                    return _entry.getUserName();
104            }
105    
106            @Override
107            public String getUuid() {
108                    return _entry.getUuid();
109            }
110    
111            @Override
112            public boolean hasEditPermission(PermissionChecker permissionChecker) {
113                    try {
114                            return BookmarksEntryPermission.contains(
115                                    permissionChecker, _entry, ActionKeys.UPDATE);
116                    }
117                    catch (Exception e) {
118                    }
119    
120                    return false;
121            }
122    
123            @Override
124            public boolean hasViewPermission(PermissionChecker permissionChecker) {
125                    try {
126                            return BookmarksEntryPermission.contains(
127                                    permissionChecker, _entry, ActionKeys.VIEW);
128                    }
129                    catch (Exception e) {
130                    }
131    
132                    return true;
133            }
134    
135            @Override
136            public boolean isPrintable() {
137                    return true;
138            }
139    
140            @Override
141            public String render(
142                            RenderRequest renderRequest, RenderResponse renderResponse,
143                            String template)
144                    throws Exception {
145    
146                    if (template.equals(TEMPLATE_FULL_CONTENT)) {
147                            renderRequest.setAttribute(WebKeys.BOOKMARKS_ENTRY, _entry);
148    
149                            return "/html/portlet/bookmarks/asset/" + template + ".jsp";
150                    }
151                    else {
152                            return null;
153                    }
154            }
155    
156            @Override
157            protected String getIconPath(ThemeDisplay themeDisplay) {
158                    return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
159            }
160    
161            private BookmarksEntry _entry;
162    
163    }