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 public void deleteTrashEntry(long classPK)
042 throws PortalException, SystemException {
043
044 BlogsEntryLocalServiceUtil.deleteEntry(classPK);
045 }
046
047 public String getClassName() {
048 return BlogsEntry.class.getName();
049 }
050
051 @Override
052 public String getRestoreLink(PortletRequest portletRequest, long classPK)
053 throws PortalException, SystemException {
054
055 String portletId = PortletKeys.BLOGS;
056
057 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
058
059 long plid = PortalUtil.getPlidFromPortletId(
060 entry.getGroupId(), PortletKeys.BLOGS);
061
062 if (plid == LayoutConstants.DEFAULT_PLID) {
063 portletId = PortletKeys.BLOGS_ADMIN;
064
065 plid = PortalUtil.getControlPanelPlid(portletRequest);
066 }
067
068 PortletURL portletURL = PortletURLFactoryUtil.create(
069 portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);
070
071 return portletURL.toString();
072 }
073
074 @Override
075 public String getRestoreMessage(
076 PortletRequest portletRequest, long classPK) {
077
078 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
079 WebKeys.THEME_DISPLAY);
080
081 return themeDisplay.translate("blogs");
082 }
083
084 public boolean isInTrash(long classPK)
085 throws PortalException, SystemException {
086
087 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
088
089 return entry.isInTrash();
090 }
091
092 public void restoreTrashEntry(long userId, long classPK)
093 throws PortalException, SystemException {
094
095 BlogsEntryLocalServiceUtil.restoreEntryFromTrash(userId, classPK);
096 }
097
098 @Override
099 protected boolean hasPermission(
100 PermissionChecker permissionChecker, long classPK, String actionId)
101 throws PortalException, SystemException {
102
103 return BlogsEntryPermission.contains(
104 permissionChecker, classPK, actionId);
105 }
106
107 }