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   */
39  public class IGImageAssetRendererFactory extends BaseAssetRendererFactory {
40  
41      public static final String CLASS_NAME = IGImage.class.getName();
42  
43      public static final String TYPE = "image";
44  
45      public AssetRenderer getAssetRenderer(long classPK)
46          throws PortalException, SystemException {
47  
48          IGImage image = IGImageLocalServiceUtil.getImage(classPK);
49  
50          return new IGImageAssetRenderer(image);
51      }
52  
53      public String getClassName() {
54          return CLASS_NAME;
55      }
56  
57      public String getType() {
58          return TYPE;
59      }
60  
61      public PortletURL getURLAdd(
62          LiferayPortletRequest liferayPortletRequest,
63          LiferayPortletResponse liferayPortletResponse) {
64  
65          ThemeDisplay themeDisplay =
66              (ThemeDisplay)liferayPortletRequest.getAttribute(
67                  WebKeys.THEME_DISPLAY);
68  
69          PortletURL addAssetURL = null;
70  
71          if (IGPermission.contains(
72                  themeDisplay.getPermissionChecker(),
73                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_IMAGE)) {
74  
75              addAssetURL = liferayPortletResponse.createRenderURL(
76                  PortletKeys.IMAGE_GALLERY);
77  
78              addAssetURL.setParameter(
79                  "struts_action", "/image_gallery/edit_image");
80              addAssetURL.setParameter(
81                  "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
82              addAssetURL.setParameter(
83                  "folderId",
84                  String.valueOf(
85                      AssetPublisherUtil.getRecentFolderId(
86                          liferayPortletRequest, CLASS_NAME)));
87              addAssetURL.setParameter("uploader", "classic");
88          }
89  
90          return addAssetURL;
91      }
92  
93  }