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.documentlibrary.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.documentlibrary.model.DLFileEntry;
29  import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
30  import com.liferay.portlet.documentlibrary.service.permission.DLPermission;
31  
32  import javax.portlet.PortletURL;
33  
34  /**
35   * <a href="DLFileEntryAssetRendererFactory.java.html"><b><i>View Source</i></b>
36   * </a>
37   *
38   * @author Julio Camarero
39   * @author Juan Fernández
40   */
41  public class DLFileEntryAssetRendererFactory extends BaseAssetRendererFactory {
42  
43      public static final String CLASS_NAME = DLFileEntry.class.getName();
44  
45      public static final String TYPE = "document";
46  
47      public AssetRenderer getAssetRenderer(long classPK)
48          throws PortalException, SystemException {
49  
50          DLFileEntry entry = DLFileEntryLocalServiceUtil.getFileEntry(classPK);
51  
52          return new DLFileEntryAssetRenderer(entry);
53      }
54  
55      public String getClassName() {
56          return CLASS_NAME;
57      }
58  
59      public String getType() {
60          return TYPE;
61      }
62  
63      public PortletURL getURLAdd(
64          LiferayPortletRequest liferayPortletRequest,
65          LiferayPortletResponse liferayPortletResponse) {
66  
67          ThemeDisplay themeDisplay =
68              (ThemeDisplay)liferayPortletRequest.getAttribute(
69                  WebKeys.THEME_DISPLAY);
70  
71          PortletURL addAssetURL = null;
72  
73          if (DLPermission.contains(
74                  themeDisplay.getPermissionChecker(),
75                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_DOCUMENT)) {
76  
77              addAssetURL = liferayPortletResponse.createRenderURL(
78                  PortletKeys.DOCUMENT_LIBRARY);
79  
80              addAssetURL.setParameter(
81                  "struts_action", "/document_library/edit_file_entry");
82              addAssetURL.setParameter(
83                  "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
84              addAssetURL.setParameter(
85                  "folderId",
86                  String.valueOf(
87                      AssetPublisherUtil.getRecentFolderId(
88                          liferayPortletRequest, CLASS_NAME)));
89              addAssetURL.setParameter("uploader", "classic");
90          }
91  
92          return addAssetURL;
93      }
94  
95      protected String getIconPath(ThemeDisplay themeDisplay) {
96          return themeDisplay.getPathThemeImages() + "/common/clip.png";
97      }
98  
99  }