001
014
015 package com.liferay.portlet.blogs.trash;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.trash.BaseTrashHandler;
020 import com.liferay.portal.model.LayoutConstants;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portal.util.PortalUtil;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.PortletURLFactoryUtil;
027 import com.liferay.portlet.blogs.model.BlogsEntry;
028 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
029 import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
030
031 import javax.portlet.PortletRequest;
032 import javax.portlet.PortletURL;
033
034
039 public class BlogsEntryTrashHandler extends BaseTrashHandler {
040
041 @Override
042 public void deleteTrashEntry(long classPK)
043 throws PortalException, SystemException {
044
045 BlogsEntryLocalServiceUtil.deleteEntry(classPK);
046 }
047
048 @Override
049 public String getClassName() {
050 return BlogsEntry.class.getName();
051 }
052
053 @Override
054 public String getRestoreLink(PortletRequest portletRequest, long classPK)
055 throws PortalException, SystemException {
056
057 String portletId = PortletKeys.BLOGS;
058
059 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
060
061 long plid = PortalUtil.getPlidFromPortletId(
062 entry.getGroupId(), PortletKeys.BLOGS);
063
064 if (plid == LayoutConstants.DEFAULT_PLID) {
065 portletId = PortletKeys.BLOGS_ADMIN;
066
067 plid = PortalUtil.getControlPanelPlid(portletRequest);
068 }
069
070 PortletURL portletURL = PortletURLFactoryUtil.create(
071 portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);
072
073 return portletURL.toString();
074 }
075
076 @Override
077 public String getRestoreMessage(
078 PortletRequest portletRequest, long classPK) {
079
080 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
081 WebKeys.THEME_DISPLAY);
082
083 return themeDisplay.translate("blogs");
084 }
085
086 @Override
087 public boolean isInTrash(long classPK)
088 throws PortalException, SystemException {
089
090 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
091
092 return entry.isInTrash();
093 }
094
095 @Override
096 public void restoreTrashEntry(long userId, long classPK)
097 throws PortalException, SystemException {
098
099 BlogsEntryLocalServiceUtil.restoreEntryFromTrash(userId, classPK);
100 }
101
102 @Override
103 protected boolean hasPermission(
104 PermissionChecker permissionChecker, long classPK, String actionId)
105 throws PortalException, SystemException {
106
107 return BlogsEntryPermission.contains(
108 permissionChecker, classPK, actionId);
109 }
110
111 }