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   */
38  public class BookmarksEntryAssetRenderer extends BaseAssetRenderer {
39  
40      public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
41          _entry = entry;
42      }
43  
44      public long getClassPK() {
45          return _entry.getEntryId();
46      }
47  
48      public long getGroupId() {
49          return _entry.getGroupId();
50      }
51  
52      public String getSummary() {
53          return HtmlUtil.stripHtml(_entry.getComments());
54      }
55  
56      public String getTitle() {
57          return _entry.getName();
58      }
59  
60      public PortletURL getURLEdit(
61          LiferayPortletRequest liferayPortletRequest,
62          LiferayPortletResponse liferayPortletResponse) {
63  
64          PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
65              PortletKeys.BOOKMARKS);
66  
67          editPortletURL.setParameter("struts_action", "/bookmarks/edit_entry");
68          editPortletURL.setParameter(
69              "folderId", String.valueOf(_entry.getFolderId()));
70          editPortletURL.setParameter(
71              "entryId", String.valueOf(_entry.getEntryId()));
72  
73          return editPortletURL;
74      }
75  
76      public String getURLViewInContext(
77          LiferayPortletRequest liferayPortletRequest,
78          LiferayPortletResponse liferayPortletResponse,
79          String noSuchEntryRedirect) {
80  
81          ThemeDisplay themeDisplay =
82              (ThemeDisplay)liferayPortletRequest.getAttribute(
83                  WebKeys.THEME_DISPLAY);
84  
85          return themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" +
86              _entry.getEntryId();
87      }
88  
89      public long getUserId() {
90          return _entry.getUserId();
91      }
92  
93      public boolean hasEditPermission(PermissionChecker permissionChecker) {
94          try {
95              return BookmarksEntryPermission.contains(
96                  permissionChecker, _entry, ActionKeys.UPDATE);
97          }
98          catch (Exception e) {
99          }
100 
101         return false;
102     }
103 
104     public boolean hasViewPermission(PermissionChecker permissionChecker) {
105         try {
106             return BookmarksEntryPermission.contains(
107                 permissionChecker, _entry, ActionKeys.VIEW);
108         }
109         catch (Exception e) {
110         }
111 
112         return true;
113     }
114 
115     public boolean isPrintable() {
116         return true;
117     }
118 
119     public String render(
120             RenderRequest renderRequest, RenderResponse renderResponse,
121             String template)
122         throws Exception {
123 
124         if (template.equals(TEMPLATE_FULL_CONTENT)) {
125             renderRequest.setAttribute(WebKeys.BOOKMARKS_ENTRY, _entry);
126 
127             return "/html/portlet/bookmarks/asset/" + template + ".jsp";
128         }
129         else {
130             return null;
131         }
132     }
133 
134     private BookmarksEntry _entry;
135 
136 }