001
014
015 package com.liferay.portlet.blogs.trash;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.trash.BaseTrashHandler;
019 import com.liferay.portal.model.LayoutConstants;
020 import com.liferay.portal.security.permission.PermissionChecker;
021 import com.liferay.portal.theme.ThemeDisplay;
022 import com.liferay.portal.util.PortalUtil;
023 import com.liferay.portal.util.PortletKeys;
024 import com.liferay.portal.util.WebKeys;
025 import com.liferay.portlet.PortletURLFactoryUtil;
026 import com.liferay.portlet.blogs.model.BlogsEntry;
027 import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
028 import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
029
030 import javax.portlet.PortletRequest;
031 import javax.portlet.PortletURL;
032
033
038 public class BlogsEntryTrashHandler extends BaseTrashHandler {
039
040 @Override
041 public void deleteTrashEntry(long classPK) throws PortalException {
042 BlogsEntryLocalServiceUtil.deleteEntry(classPK);
043 }
044
045 @Override
046 public String getClassName() {
047 return BlogsEntry.class.getName();
048 }
049
050 @Override
051 public String getRestoreContainedModelLink(
052 PortletRequest portletRequest, long classPK)
053 throws PortalException {
054
055 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
056
057 PortletURL portletURL = getRestoreURL(portletRequest, classPK, false);
058
059 portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()));
060 portletURL.setParameter("urlTitle", entry.getUrlTitle());
061
062 return portletURL.toString();
063 }
064
065 @Override
066 public String getRestoreContainerModelLink(
067 PortletRequest portletRequest, long classPK)
068 throws PortalException {
069
070 PortletURL portletURL = getRestoreURL(portletRequest, classPK, true);
071
072 return portletURL.toString();
073 }
074
075 @Override
076 public String getRestoreMessage(
077 PortletRequest portletRequest, long classPK) {
078
079 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
080 WebKeys.THEME_DISPLAY);
081
082 return themeDisplay.translate("blogs");
083 }
084
085 @Override
086 public boolean isInTrash(long classPK) throws PortalException {
087 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
088
089 return entry.isInTrash();
090 }
091
092 @Override
093 public void restoreTrashEntry(long userId, long classPK)
094 throws PortalException {
095
096 BlogsEntryLocalServiceUtil.restoreEntryFromTrash(userId, classPK);
097 }
098
099 protected PortletURL getRestoreURL(
100 PortletRequest portletRequest, long classPK,
101 boolean isContainerModel)
102 throws PortalException {
103
104 String portletId = PortletKeys.BLOGS;
105
106 BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(classPK);
107
108 long plid = PortalUtil.getPlidFromPortletId(
109 entry.getGroupId(), PortletKeys.BLOGS);
110
111 if (plid == LayoutConstants.DEFAULT_PLID) {
112 portletId = PortletKeys.BLOGS_ADMIN;
113
114 plid = PortalUtil.getControlPanelPlid(portletRequest);
115 }
116
117 PortletURL portletURL = PortletURLFactoryUtil.create(
118 portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);
119
120 if (!isContainerModel) {
121 if (portletId.equals(PortletKeys.BLOGS)) {
122 portletURL.setParameter("struts_action", "/blogs/view_entry");
123 }
124 else {
125 portletURL.setParameter(
126 "struts_action", "/blogs_admin/view_entry");
127 }
128 }
129
130 return portletURL;
131 }
132
133 @Override
134 protected boolean hasPermission(
135 PermissionChecker permissionChecker, long classPK, String actionId)
136 throws PortalException {
137
138 return BlogsEntryPermission.contains(
139 permissionChecker, classPK, actionId);
140 }
141
142 }