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.BlogsEntryServiceUtil;
030 import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
031
032 import javax.portlet.PortletRequest;
033 import javax.portlet.PortletURL;
034
035
040 public class BlogsEntryTrashHandler extends BaseTrashHandler {
041
042 public static final String CLASS_NAME = BlogsEntry.class.getName();
043
044 public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
045 throws PortalException, SystemException {
046
047 for (long classPK : classPKs) {
048 if (checkPermission) {
049 BlogsEntryServiceUtil.deleteEntry(classPK);
050 }
051 else {
052 BlogsEntryLocalServiceUtil.deleteEntry(classPK);
053 }
054 }
055 }
056
057 public String getClassName() {
058 return CLASS_NAME;
059 }
060
061 @Override
062 public String getRestoreLink(PortletRequest portletRequest, long classPK)
063 throws PortalException, SystemException {
064
065 String portletId = PortletKeys.BLOGS;
066
067 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
068
069 long plid = PortalUtil.getPlidFromPortletId(
070 entry.getGroupId(), PortletKeys.BLOGS);
071
072 if (plid == LayoutConstants.DEFAULT_PLID) {
073 plid = PortalUtil.getControlPanelPlid(portletRequest);
074
075 portletId = PortletKeys.BLOGS_ADMIN;
076 }
077
078 PortletURL portletURL = PortletURLFactoryUtil.create(
079 portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);
080
081 return portletURL.toString();
082 }
083
084 @Override
085 public String getRestoreMessage(
086 PortletRequest portletRequest, long classPK) {
087
088 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
089 WebKeys.THEME_DISPLAY);
090
091 return themeDisplay.translate("blogs");
092 }
093
094 public boolean isInTrash(long classPK)
095 throws PortalException, SystemException {
096
097 BlogsEntry entry = BlogsEntryServiceUtil.getEntry(classPK);
098
099 return entry.isInTrash();
100 }
101
102 public void restoreTrashEntries(long[] classPKs)
103 throws PortalException, SystemException {
104
105 for (long classPK : classPKs) {
106 BlogsEntryServiceUtil.restoreEntryFromTrash(classPK);
107 }
108 }
109
110 @Override
111 protected boolean hasPermission(
112 PermissionChecker permissionChecker, long classPK, String actionId)
113 throws PortalException, SystemException {
114
115 return BlogsEntryPermission.contains(
116 permissionChecker, classPK, actionId);
117 }
118
119 }