001
014
015 package com.liferay.portal.kernel.trash;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.model.ContainerModel;
023 import com.liferay.portal.security.permission.ActionKeys;
024 import com.liferay.portal.security.permission.PermissionChecker;
025 import com.liferay.portal.service.ServiceContext;
026 import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
027 import com.liferay.portlet.asset.model.AssetRenderer;
028 import com.liferay.portlet.asset.model.AssetRendererFactory;
029 import com.liferay.portlet.trash.model.TrashEntry;
030
031 import java.util.Collections;
032 import java.util.List;
033
034 import javax.portlet.PortletRequest;
035
036
043 public abstract class BaseTrashHandler implements TrashHandler {
044
045
062 public void checkDuplicateTrashEntry(
063 TrashEntry trashEntry, long containerModelId, String newName)
064 throws PortalException, SystemException {
065 }
066
067 public void deleteTrashEntries(long[] classPKs)
068 throws PortalException, SystemException {
069
070 deleteTrashEntries(classPKs, true);
071 }
072
073 public void deleteTrashEntry(long classPK)
074 throws PortalException, SystemException {
075
076 deleteTrashEntries(new long[] {classPK});
077 }
078
079 public void deleteTrashEntry(long classPK, boolean checkPermission)
080 throws PortalException, SystemException {
081
082 deleteTrashEntries(new long[] {classPK}, checkPermission);
083 }
084
085
094 public ContainerModel getContainerModel(long containerModelId)
095 throws PortalException, SystemException {
096
097 return null;
098 }
099
100 public String getContainerModelClassName() {
101 return StringPool.BLANK;
102 }
103
104 public String getContainerModelName() {
105 return StringPool.BLANK;
106 }
107
108
139 public List<ContainerModel> getContainerModels(
140 long classPK, long containerModelId, int start, int end)
141 throws PortalException, SystemException {
142
143 return Collections.emptyList();
144 }
145
146
164 public int getContainerModelsCount(long classPK, long containerModelId)
165 throws PortalException, SystemException {
166
167 return 0;
168 }
169
170 public String getDeleteMessage() {
171 return "deleted-in-x";
172 }
173
174
178 public ContainerModel getParentContainerModel(long classPK)
179 throws PortalException, SystemException {
180
181 return null;
182 }
183
184
188 public List<ContainerModel> getParentContainerModels(long classPK)
189 throws PortalException, SystemException {
190
191 return Collections.emptyList();
192 }
193
194
204 public String getRestoreLink(PortletRequest portletRequest, long classPK)
205 throws PortalException, SystemException {
206
207 return StringPool.BLANK;
208 }
209
210
221 public String getRestoreMessage(PortletRequest portletRequest, long classPK)
222 throws PortalException, SystemException {
223
224 return StringPool.BLANK;
225 }
226
227 public String getRootContainerModelName() {
228 return StringPool.BLANK;
229 }
230
231 public String getSubcontainerModelName() {
232 return StringPool.BLANK;
233 }
234
235 public String getTrashContainedModelName() {
236 return StringPool.BLANK;
237 }
238
239
243 public int getTrashContainedModelsCount(long classPK)
244 throws PortalException, SystemException {
245
246 return 0;
247 }
248
249
253 public List<TrashRenderer> getTrashContainedModelTrashRenderers(
254 long classPK, int start, int end)
255 throws PortalException, SystemException {
256
257 return Collections.emptyList();
258 }
259
260 public String getTrashContainerModelName() {
261 return StringPool.BLANK;
262 }
263
264
268 public int getTrashContainerModelsCount(long classPK)
269 throws PortalException, SystemException {
270
271 return 0;
272 }
273
274
278 public List<TrashRenderer> getTrashContainerModelTrashRenderers(
279 long classPK, int start, int end)
280 throws PortalException, SystemException {
281
282 return Collections.emptyList();
283 }
284
285 public TrashRenderer getTrashRenderer(long classPK)
286 throws PortalException, SystemException {
287
288 AssetRendererFactory assetRendererFactory = getAssetRendererFactory();
289
290 if (assetRendererFactory != null) {
291 AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(
292 classPK);
293
294 if (assetRenderer instanceof TrashRenderer) {
295 return (TrashRenderer)assetRenderer;
296 }
297 }
298
299 return null;
300 }
301
302 public boolean hasTrashPermission(
303 PermissionChecker permissionChecker, long groupId, long classPK,
304 String trashActionId)
305 throws PortalException, SystemException {
306
307 String actionId = trashActionId;
308
309 if (trashActionId.equals(ActionKeys.DELETE)) {
310 actionId = ActionKeys.DELETE;
311 }
312 else if (trashActionId.equals(TrashActionKeys.OVERWRITE)) {
313 actionId = ActionKeys.DELETE;
314 }
315 else if (trashActionId.equals(TrashActionKeys.MOVE)) {
316 return false;
317 }
318 else if (trashActionId.equals(TrashActionKeys.RENAME)) {
319 actionId = ActionKeys.UPDATE;
320 }
321 else if (trashActionId.equals(TrashActionKeys.RESTORE)) {
322 actionId = ActionKeys.DELETE;
323 }
324
325 return hasPermission(permissionChecker, classPK, actionId);
326 }
327
328 public boolean isContainerModel() {
329 return false;
330 }
331
332
336 public boolean isInTrashContainer(long classPK)
337 throws PortalException, SystemException {
338
339 return false;
340 }
341
342 public boolean isMovable() {
343 return false;
344 }
345
346
363 public boolean isRestorable(long classPK)
364 throws PortalException, SystemException {
365
366 return true;
367 }
368
369
373 public void moveEntry(
374 long classPK, long containerModelId, ServiceContext serviceContext)
375 throws PortalException, SystemException {
376 }
377
378 public void moveTrashEntry(
379 long classPK, long containerModelId, ServiceContext serviceContext)
380 throws PortalException, SystemException {
381
382 if (isRestorable(classPK)) {
383 restoreTrashEntry(classPK);
384 }
385
386 _log.error("moveTrashEntry() is not implemented in " +
387 getClass().getName());
388
389 throw new SystemException();
390 }
391
392 public void restoreTrashEntry(long classPK)
393 throws PortalException, SystemException {
394
395 restoreTrashEntries(new long[] {classPK});
396 }
397
398
409 public void updateTitle(long classPK, String title)
410 throws PortalException, SystemException {
411 }
412
413 protected AssetRendererFactory getAssetRendererFactory() {
414 return AssetRendererFactoryRegistryUtil.
415 getAssetRendererFactoryByClassName(getClassName());
416 }
417
418 protected abstract boolean hasPermission(
419 PermissionChecker permissionChecker, long classPK, String actionId)
420 throws PortalException, SystemException;
421
422 private static Log _log = LogFactoryUtil.getLog(BaseTrashHandler.class);
423
424 }