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