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