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.theme.ThemeDisplay;
22  import com.liferay.portal.util.PortletKeys;
23  import com.liferay.portal.util.WebKeys;
24  import com.liferay.portlet.asset.model.BaseAssetRenderer;
25  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
26  import com.liferay.portlet.bookmarks.service.permission.BookmarksPermission;
27  
28  import javax.portlet.PortletURL;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  /**
33   * <a href="BookmarksEntryAssetRenderer.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Julio Camarero
36   */
37  public class BookmarksEntryAssetRenderer extends BaseAssetRenderer {
38  
39      public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
40          _entry = entry;
41      }
42  
43      public long getClassPK() {
44          return _entry.getEntryId();
45      }
46  
47      public long getGroupId() {
48          return _entry.getGroupId();
49      }
50  
51      public String getSummary() {
52          return HtmlUtil.stripHtml(_entry.getComments());
53      }
54  
55      public String getTitle() {
56          return _entry.getName();
57      }
58  
59      public PortletURL getURLEdit(
60          LiferayPortletRequest liferayPortletRequest,
61          LiferayPortletResponse liferayPortletResponse) {
62  
63          ThemeDisplay themeDisplay =
64              (ThemeDisplay)liferayPortletRequest.getAttribute(
65                  WebKeys.THEME_DISPLAY);
66  
67          PortletURL editPortletURL = null;
68  
69          if (BookmarksPermission.contains(
70                  themeDisplay.getPermissionChecker(),
71                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
72  
73              editPortletURL = liferayPortletResponse.createRenderURL(
74                  PortletKeys.BOOKMARKS);
75  
76              editPortletURL.setParameter(
77                  "struts_action", "/bookmarks/edit_entry");
78              editPortletURL.setParameter(
79                  "folderId", String.valueOf(_entry.getFolderId()));
80              editPortletURL.setParameter(
81                  "entryId", String.valueOf(_entry.getEntryId()));
82          }
83  
84          return editPortletURL;
85      }
86  
87      public String getURLViewInContext(
88          LiferayPortletRequest liferayPortletRequest,
89          LiferayPortletResponse liferayPortletResponse,
90          String noSuchEntryRedirect) {
91  
92          ThemeDisplay themeDisplay =
93              (ThemeDisplay)liferayPortletRequest.getAttribute(
94                  WebKeys.THEME_DISPLAY);
95  
96          return themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" +
97              _entry.getEntryId();
98      }
99  
100     public long getUserId() {
101         return _entry.getUserId();
102     }
103 
104     public boolean isPrintable() {
105         return true;
106     }
107 
108     public String render(
109             RenderRequest renderRequest, RenderResponse renderResponse,
110             String template)
111         throws Exception {
112 
113         if (template.equals(TEMPLATE_FULL_CONTENT)) {
114             renderRequest.setAttribute(WebKeys.BOOKMARKS_ENTRY, _entry);
115 
116             return "/html/portlet/bookmarks/asset/" + template + ".jsp";
117         }
118         else {
119             return null;
120         }
121     }
122 
123     private BookmarksEntry _entry;
124 
125 }