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.kernel.util.HtmlUtil;
022 import com.liferay.portal.security.permission.ActionKeys;
023 import com.liferay.portal.security.permission.PermissionChecker;
024 import com.liferay.portal.theme.ThemeDisplay;
025 import com.liferay.portal.util.PortletKeys;
026 import com.liferay.portal.util.WebKeys;
027 import com.liferay.portlet.asset.model.BaseAssetRenderer;
028 import com.liferay.portlet.imagegallery.model.IGImage;
029 import com.liferay.portlet.imagegallery.service.permission.IGImagePermission;
030
031 import javax.portlet.PortletURL;
032 import javax.portlet.RenderRequest;
033 import javax.portlet.RenderResponse;
034 import javax.portlet.WindowState;
035
036
040 public class IGImageAssetRenderer extends BaseAssetRenderer {
041
042 public IGImageAssetRenderer(IGImage image) {
043 _image = image;
044 }
045
046 public long getClassPK() {
047 return _image.getImageId();
048 }
049
050 public long getGroupId() {
051 return _image.getGroupId();
052 }
053
054 public String getSummary() {
055 return HtmlUtil.stripHtml(_image.getDescription());
056 }
057
058 public String getTitle() {
059 return _image.getName();
060 }
061
062 public PortletURL getURLEdit(
063 LiferayPortletRequest liferayPortletRequest,
064 LiferayPortletResponse liferayPortletResponse) {
065
066 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
067 PortletKeys.IMAGE_GALLERY);
068
069 editPortletURL.setParameter(
070 "struts_action", "/image_gallery/edit_image");
071 editPortletURL.setParameter(
072 "folderId", String.valueOf(_image.getFolderId()));
073 editPortletURL.setParameter(
074 "imageId", String.valueOf(_image.getImageId()));
075
076 return editPortletURL;
077 }
078
079 public String getURLViewInContext(
080 LiferayPortletRequest liferayPortletRequest,
081 LiferayPortletResponse liferayPortletResponse,
082 String noSuchEntryRedirect)
083 throws Exception {
084
085 PortletURL viewPortletURL = liferayPortletResponse.createRenderURL(
086 PortletKeys.IMAGE_GALLERY);
087
088 viewPortletURL.setWindowState(WindowState.MAXIMIZED);
089
090 viewPortletURL.setParameter("struts_action", "/image_gallery/view");
091 viewPortletURL.setParameter(
092 "groupId", String.valueOf(_image.getGroupId()));
093 viewPortletURL.setParameter(
094 "folderId", String.valueOf(_image.getFolderId()));
095
096 return viewPortletURL.toString();
097 }
098
099 public long getUserId() {
100 return _image.getUserId();
101 }
102
103 public String getUuid() {
104 return _image.getUuid();
105 }
106
107 public String getViewInContextMessage() {
108 return "view-album";
109 }
110
111 public boolean hasEditPermission(PermissionChecker permissionChecker)
112 throws PortalException, SystemException {
113
114 return IGImagePermission.contains(
115 permissionChecker, _image, ActionKeys.UPDATE);
116 }
117
118 public boolean hasViewPermission(PermissionChecker permissionChecker)
119 throws PortalException, SystemException {
120
121 return IGImagePermission.contains(
122 permissionChecker, _image, ActionKeys.VIEW);
123 }
124
125 public boolean isPrintable() {
126 return true;
127 }
128
129 public String render(
130 RenderRequest renderRequest, RenderResponse renderResponse,
131 String template) {
132
133 if (template.equals(TEMPLATE_ABSTRACT) ||
134 template.equals(TEMPLATE_FULL_CONTENT)) {
135
136 renderRequest.setAttribute(WebKeys.IMAGE_GALLERY_IMAGE, _image);
137
138 return "/html/portlet/image_gallery/asset/" + template + ".jsp";
139 }
140 else {
141 return null;
142 }
143 }
144
145 protected String getIconPath(ThemeDisplay themeDisplay) {
146 return themeDisplay.getPathThemeImages() + "/file_system/small/bmp.png";
147 }
148
149 private IGImage _image;
150
151 }