forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BookmarksEntryAssetRenderer.java
156 lines (126 loc) · 4.09 KB
/
BookmarksEntryAssetRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet.bookmarks.asset;
import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.security.permission.ActionKeys;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortletKeys;
import com.liferay.portal.util.WebKeys;
import com.liferay.portlet.asset.model.BaseAssetRenderer;
import com.liferay.portlet.bookmarks.model.BookmarksEntry;
import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
import java.util.Locale;
import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
/**
* @author Julio Camarero
* @author Juan Fernández
* @author Sergio González
*/
public class BookmarksEntryAssetRenderer extends BaseAssetRenderer {
public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
_entry = entry;
}
@Override
public String getAssetRendererFactoryClassName() {
return BookmarksEntryAssetRendererFactory.CLASS_NAME;
}
public long getClassPK() {
return _entry.getEntryId();
}
public long getGroupId() {
return _entry.getGroupId();
}
public String getSummary(Locale locale) {
return HtmlUtil.stripHtml(_entry.getDescription());
}
public String getTitle(Locale locale) {
return _entry.getName();
}
@Override
public PortletURL getURLEdit(
LiferayPortletRequest liferayPortletRequest,
LiferayPortletResponse liferayPortletResponse)
throws Exception {
PortletURL portletURL = liferayPortletResponse.createLiferayPortletURL(
getControlPanelPlid(liferayPortletRequest), PortletKeys.BOOKMARKS,
PortletRequest.RENDER_PHASE);
portletURL.setParameter("struts_action", "/bookmarks/edit_entry");
portletURL.setParameter(
"folderId", String.valueOf(_entry.getFolderId()));
portletURL.setParameter("entryId", String.valueOf(_entry.getEntryId()));
return portletURL;
}
@Override
public String getURLViewInContext(
LiferayPortletRequest liferayPortletRequest,
LiferayPortletResponse liferayPortletResponse,
String noSuchEntryRedirect) {
return getURLViewInContext(
liferayPortletRequest, noSuchEntryRedirect, "/bookmarks/find_entry",
"entryId", _entry.getEntryId());
}
public long getUserId() {
return _entry.getUserId();
}
public String getUuid() {
return _entry.getUuid();
}
@Override
public boolean hasEditPermission(PermissionChecker permissionChecker) {
try {
return BookmarksEntryPermission.contains(
permissionChecker, _entry, ActionKeys.UPDATE);
}
catch (Exception e) {
}
return false;
}
@Override
public boolean hasViewPermission(PermissionChecker permissionChecker) {
try {
return BookmarksEntryPermission.contains(
permissionChecker, _entry, ActionKeys.VIEW);
}
catch (Exception e) {
}
return true;
}
@Override
public boolean isPrintable() {
return true;
}
public String render(
RenderRequest renderRequest, RenderResponse renderResponse,
String template)
throws Exception {
if (template.equals(TEMPLATE_FULL_CONTENT)) {
renderRequest.setAttribute(WebKeys.BOOKMARKS_ENTRY, _entry);
return "/html/portlet/bookmarks/asset/" + template + ".jsp";
}
else {
return null;
}
}
@Override
protected String getIconPath(ThemeDisplay themeDisplay) {
return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
}
private BookmarksEntry _entry;
}