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.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
20  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
21  import com.liferay.portal.security.permission.ActionKeys;
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.AssetRenderer;
26  import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
27  import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
28  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
29  import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
30  import com.liferay.portlet.bookmarks.service.permission.BookmarksPermission;
31  
32  import javax.portlet.PortletURL;
33  
34  /**
35   * <a href="BookmarksEntryAssetRendererFactory.java.html"><b><i>View Source</i>
36   * </b></a>
37   *
38   * @author Julio Camarero
39   * @author Juan Fernández
40   */
41  public class BookmarksEntryAssetRendererFactory
42      extends BaseAssetRendererFactory {
43  
44      public static final String CLASS_NAME =BookmarksEntry.class.getName();
45  
46      public static final String TYPE = "bookmark";
47  
48      public AssetRenderer getAssetRenderer(long classPK)
49          throws PortalException, SystemException {
50  
51          BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
52  
53          return new BookmarksEntryAssetRenderer(entry);
54      }
55  
56      public String getClassName() {
57          return CLASS_NAME;
58      }
59  
60      public String getType() {
61          return TYPE;
62      }
63  
64      public PortletURL getURLAdd(
65          LiferayPortletRequest liferayPortletRequest,
66          LiferayPortletResponse liferayPortletResponse) {
67  
68          ThemeDisplay themeDisplay =
69              (ThemeDisplay)liferayPortletRequest.getAttribute(
70                  WebKeys.THEME_DISPLAY);
71  
72          PortletURL addAssetURL = null;
73  
74          if (BookmarksPermission.contains(
75                  themeDisplay.getPermissionChecker(),
76                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
77  
78              addAssetURL = liferayPortletResponse.createRenderURL(
79                  PortletKeys.BOOKMARKS);
80  
81              addAssetURL.setParameter(
82                  "struts_action", "/bookmarks/edit_entry");
83              addAssetURL.setParameter(
84                  "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
85              addAssetURL.setParameter(
86                  "folderId",
87                  String.valueOf(
88                      AssetPublisherUtil.getRecentFolderId(
89                          liferayPortletRequest, CLASS_NAME)));
90          }
91  
92          return addAssetURL;
93      }
94  
95      protected String getIconPath(ThemeDisplay themeDisplay) {
96          return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
97      }
98  
99  }