001
014
015 package com.liferay.portlet.imagegallery.asset;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021 import com.liferay.portal.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.asset.model.AssetRenderer;
027 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
028 import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
029 import com.liferay.portlet.imagegallery.model.IGImage;
030 import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
031 import com.liferay.portlet.imagegallery.service.permission.IGImagePermission;
032 import com.liferay.portlet.imagegallery.service.permission.IGPermission;
033
034 import javax.portlet.PortletURL;
035
036
041 public class IGImageAssetRendererFactory extends BaseAssetRendererFactory {
042
043 public static final String CLASS_NAME = IGImage.class.getName();
044
045 public static final String TYPE = "image";
046
047 public AssetRenderer getAssetRenderer(long classPK, int type)
048 throws PortalException, SystemException {
049
050 IGImage image = IGImageLocalServiceUtil.getImage(classPK);
051
052 return new IGImageAssetRenderer(image);
053 }
054
055 public String getClassName() {
056 return CLASS_NAME;
057 }
058
059 public String getType() {
060 return TYPE;
061 }
062
063 public PortletURL getURLAdd(
064 LiferayPortletRequest liferayPortletRequest,
065 LiferayPortletResponse liferayPortletResponse) {
066
067 ThemeDisplay themeDisplay =
068 (ThemeDisplay)liferayPortletRequest.getAttribute(
069 WebKeys.THEME_DISPLAY);
070
071 PortletURL addAssetURL = null;
072
073 if (IGPermission.contains(
074 themeDisplay.getPermissionChecker(),
075 themeDisplay.getScopeGroupId(), ActionKeys.ADD_IMAGE)) {
076
077 addAssetURL = liferayPortletResponse.createRenderURL(
078 PortletKeys.IMAGE_GALLERY);
079
080 addAssetURL.setParameter(
081 "struts_action", "/image_gallery/edit_image");
082 addAssetURL.setParameter(
083 "groupId", String.valueOf(themeDisplay.getScopeGroupId()));
084 addAssetURL.setParameter(
085 "folderId",
086 String.valueOf(
087 AssetPublisherUtil.getRecentFolderId(
088 liferayPortletRequest, CLASS_NAME)));
089 addAssetURL.setParameter("uploader", "classic");
090 }
091
092 return addAssetURL;
093 }
094
095 public boolean hasPermission(
096 PermissionChecker permissionChecker, long classPK, String actionId)
097 throws Exception {
098
099 return IGImagePermission.contains(
100 permissionChecker, classPK, actionId);
101 }
102
103 protected String getIconPath(ThemeDisplay themeDisplay) {
104 return themeDisplay.getPathThemeImages() + "/file_system/small/bmp.png";
105 }
106
107 }