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