1
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.kernel.util.HtmlUtil;
22 import com.liferay.portal.security.permission.ActionKeys;
23 import com.liferay.portal.security.permission.PermissionChecker;
24 import com.liferay.portal.theme.ThemeDisplay;
25 import com.liferay.portal.util.PortletKeys;
26 import com.liferay.portal.util.WebKeys;
27 import com.liferay.portlet.asset.model.BaseAssetRenderer;
28 import com.liferay.portlet.imagegallery.model.IGImage;
29 import com.liferay.portlet.imagegallery.service.permission.IGImagePermission;
30
31 import javax.portlet.PortletURL;
32 import javax.portlet.RenderRequest;
33 import javax.portlet.RenderResponse;
34 import javax.portlet.WindowState;
35
36
42 public class IGImageAssetRenderer extends BaseAssetRenderer {
43
44 public IGImageAssetRenderer(IGImage image) {
45 _image = image;
46 }
47
48 public long getClassPK() {
49 return _image.getImageId();
50 }
51
52 public long getGroupId() {
53 return _image.getGroupId();
54 }
55
56 public String getSummary() {
57 return HtmlUtil.stripHtml(_image.getDescription());
58 }
59
60 public String getTitle() {
61 return _image.getName();
62 }
63
64 public PortletURL getURLEdit(
65 LiferayPortletRequest liferayPortletRequest,
66 LiferayPortletResponse liferayPortletResponse) {
67
68 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
69 PortletKeys.IMAGE_GALLERY);
70
71 editPortletURL.setParameter(
72 "struts_action", "/image_gallery/edit_image");
73 editPortletURL.setParameter(
74 "folderId", String.valueOf(_image.getFolderId()));
75 editPortletURL.setParameter(
76 "imageId", String.valueOf(_image.getImageId()));
77
78 return editPortletURL;
79 }
80
81 public String getURLViewInContext(
82 LiferayPortletRequest liferayPortletRequest,
83 LiferayPortletResponse liferayPortletResponse,
84 String noSuchEntryRedirect)
85 throws Exception {
86
87 PortletURL viewPortletURL = liferayPortletResponse.createRenderURL(
88 PortletKeys.IMAGE_GALLERY);
89
90 viewPortletURL.setWindowState(WindowState.MAXIMIZED);
91
92 viewPortletURL.setParameter("struts_action", "/image_gallery/view");
93 viewPortletURL.setParameter(
94 "groupId", String.valueOf(_image.getGroupId()));
95 viewPortletURL.setParameter(
96 "folderId", String.valueOf(_image.getFolderId()));
97
98 return viewPortletURL.toString();
99 }
100
101 public long getUserId() {
102 return _image.getUserId();
103 }
104
105 public String getViewInContextMessage() {
106 return "view-album";
107 }
108
109 public boolean hasEditPermission(PermissionChecker permissionChecker)
110 throws PortalException, SystemException {
111
112 return IGImagePermission.contains(
113 permissionChecker, _image, ActionKeys.UPDATE);
114 }
115
116 public boolean hasViewPermission(PermissionChecker permissionChecker)
117 throws PortalException, SystemException {
118
119 return IGImagePermission.contains(
120 permissionChecker, _image, ActionKeys.VIEW);
121 }
122
123 public boolean isPrintable() {
124 return true;
125 }
126
127 public String render(
128 RenderRequest renderRequest, RenderResponse renderResponse,
129 String template) {
130
131 if (template.equals(TEMPLATE_ABSTRACT) ||
132 template.equals(TEMPLATE_FULL_CONTENT)) {
133
134 renderRequest.setAttribute(WebKeys.IMAGE_GALLERY_IMAGE, _image);
135
136 return "/html/portlet/image_gallery/asset/" + template + ".jsp";
137 }
138 else {
139 return null;
140 }
141 }
142
143 protected String getIconPath(ThemeDisplay themeDisplay) {
144 return themeDisplay.getPathThemeImages() + "/file_system/small/bmp.png";
145 }
146
147 private IGImage _image;
148
149 }