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