001
014
015 package com.liferay.portlet.documentlibrary.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.PropsValues;
027 import com.liferay.portal.util.WebKeys;
028 import com.liferay.portlet.asset.model.BaseAssetRenderer;
029 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
030 import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
031 import com.liferay.portlet.documentlibrary.model.DLFileVersion;
032 import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
033
034 import javax.portlet.PortletURL;
035 import javax.portlet.RenderRequest;
036 import javax.portlet.RenderResponse;
037
038
042 public class DLFileEntryAssetRenderer extends BaseAssetRenderer {
043
044 public DLFileEntryAssetRenderer(
045 DLFileEntry fileEntry, DLFileVersion fileVersion) {
046
047 _fileEntry = fileEntry;
048 _fileVersion = fileVersion;
049 }
050
051 public long getClassPK() {
052 if (!_fileVersion.isApproved() &&
053 (_fileVersion.getVersion() !=
054 DLFileEntryConstants.DEFAULT_VERSION)) {
055
056 return _fileVersion.getFileVersionId();
057 }
058 else {
059 return _fileEntry.getFileEntryId();
060 }
061 }
062
063 public String getDiscussionPath() {
064 if (PropsValues.DL_FILE_ENTRY_COMMENTS_ENABLED) {
065 return "edit_file_entry_discussion";
066 }
067 else {
068 return null;
069 }
070 }
071
072 public long getGroupId() {
073 return _fileEntry.getGroupId();
074 }
075
076 public String getSummary() {
077 return HtmlUtil.stripHtml(_fileEntry.getDescription());
078 }
079
080 public String getTitle() {
081 return _fileEntry.getTitle();
082 }
083
084 public PortletURL getURLEdit(
085 LiferayPortletRequest liferayPortletRequest,
086 LiferayPortletResponse liferayPortletResponse) {
087
088 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
089 PortletKeys.DOCUMENT_LIBRARY);
090
091 editPortletURL.setParameter(
092 "struts_action", "/document_library/edit_file_entry");
093 editPortletURL.setParameter(
094 "groupId", String.valueOf(_fileEntry.getGroupId()));
095 editPortletURL.setParameter(
096 "folderId", String.valueOf(_fileEntry.getFolderId()));
097 editPortletURL.setParameter(
098 "name", String.valueOf(_fileEntry.getName()));
099
100 return editPortletURL;
101 }
102
103 public PortletURL getURLExport(
104 LiferayPortletRequest liferayPortletRequest,
105 LiferayPortletResponse liferayPortletResponse) {
106
107 PortletURL exportPortletURL = liferayPortletResponse.createActionURL();
108
109 exportPortletURL.setParameter(
110 "struts_action", "/asset_publisher/get_file");
111 exportPortletURL.setParameter(
112 "groupId", String.valueOf(_fileEntry.getGroupId()));
113 exportPortletURL.setParameter(
114 "folderId", String.valueOf(_fileEntry.getFolderId()));
115 exportPortletURL.setParameter(
116 "title", String.valueOf(_fileEntry.getTitle()));
117
118 return exportPortletURL;
119 }
120
121 public String getURLViewInContext(
122 LiferayPortletRequest liferayPortletRequest,
123 LiferayPortletResponse liferayPortletResponse,
124 String noSuchEntryRedirect) {
125
126 ThemeDisplay themeDisplay =
127 (ThemeDisplay)liferayPortletRequest.getAttribute(
128 WebKeys.THEME_DISPLAY);
129
130 return themeDisplay.getPathMain() +
131 "/document_library/find_file_entry?p_l_id=" +
132 themeDisplay.getPlid() + "&fileEntryId=" +
133 _fileEntry.getFileEntryId();
134 }
135
136 public long getUserId() {
137 return _fileEntry.getUserId();
138 }
139
140 public String getUuid() {
141 return _fileEntry.getUuid();
142 }
143
144 public boolean hasEditPermission(PermissionChecker permissionChecker)
145 throws PortalException, SystemException {
146
147 return DLFileEntryPermission.contains(
148 permissionChecker, _fileEntry, ActionKeys.UPDATE);
149 }
150
151 public boolean hasViewPermission(PermissionChecker permissionChecker)
152 throws PortalException, SystemException {
153
154 return DLFileEntryPermission.contains(
155 permissionChecker, _fileEntry, ActionKeys.VIEW);
156 }
157
158 public boolean isConvertible() {
159 return true;
160 }
161
162 public boolean isPrintable() {
163 return false;
164 }
165
166 public String render(
167 RenderRequest renderRequest, RenderResponse renderResponse,
168 String template)
169 throws Exception {
170
171 if (template.equals(TEMPLATE_ABSTRACT) ||
172 template.equals(TEMPLATE_FULL_CONTENT)) {
173
174 renderRequest.setAttribute(
175 WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY, _fileEntry);
176 renderRequest.setAttribute(
177 WebKeys.DOCUMENT_LIBRARY_FILE_VERSION, _fileVersion);
178
179 return "/html/portlet/document_library/asset/" + template + ".jsp";
180 }
181 else {
182 return null;
183 }
184 }
185
186 protected String getIconPath(ThemeDisplay themeDisplay) {
187 return themeDisplay.getPathThemeImages() + "/common/clip.png";
188 }
189
190 private DLFileEntry _fileEntry;
191 private DLFileVersion _fileVersion;
192
193 }