1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.bookmarks.asset;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
18  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portal.theme.ThemeDisplay;
23  import com.liferay.portal.util.PortletKeys;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.asset.model.BaseAssetRenderer;
26  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
27  import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
28  
29  import javax.portlet.PortletURL;
30  import javax.portlet.RenderRequest;
31  import javax.portlet.RenderResponse;
32  
33  /**
34   * <a href="BookmarksEntryAssetRenderer.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Julio Camarero
37   * @author Juan Fernández
38   */
39  public class BookmarksEntryAssetRenderer extends BaseAssetRenderer {
40  
41      public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
42          _entry = entry;
43      }
44  
45      public long getClassPK() {
46          return _entry.getEntryId();
47      }
48  
49      public long getGroupId() {
50          return _entry.getGroupId();
51      }
52  
53      public String getSummary() {
54          return HtmlUtil.stripHtml(_entry.getComments());
55      }
56  
57      public String getTitle() {
58          return _entry.getName();
59      }
60  
61      public PortletURL getURLEdit(
62          LiferayPortletRequest liferayPortletRequest,
63          LiferayPortletResponse liferayPortletResponse) {
64  
65          PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
66              PortletKeys.BOOKMARKS);
67  
68          editPortletURL.setParameter("struts_action", "/bookmarks/edit_entry");
69          editPortletURL.setParameter(
70              "folderId", String.valueOf(_entry.getFolderId()));
71          editPortletURL.setParameter(
72              "entryId", String.valueOf(_entry.getEntryId()));
73  
74          return editPortletURL;
75      }
76  
77      public String getURLViewInContext(
78          LiferayPortletRequest liferayPortletRequest,
79          LiferayPortletResponse liferayPortletResponse,
80          String noSuchEntryRedirect) {
81  
82          ThemeDisplay themeDisplay =
83              (ThemeDisplay)liferayPortletRequest.getAttribute(
84                  WebKeys.THEME_DISPLAY);
85  
86          return themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" +
87              _entry.getEntryId();
88      }
89  
90      public long getUserId() {
91          return _entry.getUserId();
92      }
93  
94      public boolean hasEditPermission(PermissionChecker permissionChecker) {
95          try {
96              return BookmarksEntryPermission.contains(
97                  permissionChecker, _entry, ActionKeys.UPDATE);
98          }
99          catch (Exception e) {
100         }
101 
102         return false;
103     }
104 
105     public boolean hasViewPermission(PermissionChecker permissionChecker) {
106         try {
107             return BookmarksEntryPermission.contains(
108                 permissionChecker, _entry, ActionKeys.VIEW);
109         }
110         catch (Exception e) {
111         }
112 
113         return true;
114     }
115 
116     public boolean isPrintable() {
117         return true;
118     }
119 
120     public String render(
121             RenderRequest renderRequest, RenderResponse renderResponse,
122             String template)
123         throws Exception {
124 
125         if (template.equals(TEMPLATE_FULL_CONTENT)) {
126             renderRequest.setAttribute(WebKeys.BOOKMARKS_ENTRY, _entry);
127 
128             return "/html/portlet/bookmarks/asset/" + template + ".jsp";
129         }
130         else {
131             return null;
132         }
133     }
134 
135     protected String getIconPath(ThemeDisplay themeDisplay) {
136         return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
137     }
138 
139     private BookmarksEntry _entry;
140 
141 }