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