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 @SuppressWarnings("unused")
046 public void checkDuplicateTrashEntry(
047 TrashEntry trashEntry, long containerModelId, String newName)
048 throws PortalException, SystemException {
049 }
050
051 public void deleteTrashEntries(long[] classPKs)
052 throws PortalException, SystemException {
053
054 deleteTrashEntries(classPKs, true);
055 }
056
057 public void deleteTrashEntry(long classPK)
058 throws PortalException, SystemException {
059
060 deleteTrashEntries(new long[] {classPK});
061 }
062
063 public void deleteTrashEntry(long classPK, boolean checkPermission)
064 throws PortalException, SystemException {
065
066 deleteTrashEntries(new long[] {classPK}, checkPermission);
067 }
068
069 @SuppressWarnings("unused")
070 public ContainerModel getContainerModel(long containerModelId)
071 throws PortalException, SystemException {
072
073 return null;
074 }
075
076 public String getContainerModelClassName() {
077 return StringPool.BLANK;
078 }
079
080 public String getContainerModelName() {
081 return StringPool.BLANK;
082 }
083
084 @SuppressWarnings("unused")
085 public List<ContainerModel> getContainerModels(
086 long classPK, long containerModelId, int start, int end)
087 throws PortalException, SystemException {
088
089 return Collections.emptyList();
090 }
091
092 @SuppressWarnings("unused")
093 public int getContainerModelsCount(long classPK, long containerModelId)
094 throws PortalException, SystemException {
095
096 return 0;
097 }
098
099 public String getDeleteMessage() {
100 return "deleted-in-x";
101 }
102
103 @SuppressWarnings("unused")
104 public ContainerModel getParentContainerModel(long classPK)
105 throws PortalException, SystemException {
106
107 return null;
108 }
109
110 @SuppressWarnings("unused")
111 public List<ContainerModel> getParentContainerModels(long classPK)
112 throws PortalException, SystemException {
113
114 return Collections.emptyList();
115 }
116
117 @SuppressWarnings("unused")
118 public String getRestoreLink(PortletRequest portletRequest, long classPK)
119 throws PortalException, SystemException {
120
121 return StringPool.BLANK;
122 }
123
124 @SuppressWarnings("unused")
125 public String getRestoreMessage(PortletRequest portletRequest, long classPK)
126 throws PortalException, SystemException {
127
128 return StringPool.BLANK;
129 }
130
131 public String getRootContainerModelName() {
132 return StringPool.BLANK;
133 }
134
135 public String getSubcontainerModelName() {
136 return StringPool.BLANK;
137 }
138
139 public String getTrashContainedModelName() {
140 return StringPool.BLANK;
141 }
142
143 @SuppressWarnings("unused")
144 public int getTrashContainedModelsCount(long classPK)
145 throws PortalException, SystemException {
146
147 return 0;
148 }
149
150 @SuppressWarnings("unused")
151 public List<TrashRenderer> getTrashContainedModelTrashRenderers(
152 long classPK, int start, int end)
153 throws PortalException, SystemException {
154
155 return Collections.emptyList();
156 }
157
158 public String getTrashContainerModelName() {
159 return StringPool.BLANK;
160 }
161
162 @SuppressWarnings("unused")
163 public int getTrashContainerModelsCount(long classPK)
164 throws PortalException, SystemException {
165
166 return 0;
167 }
168
169 @SuppressWarnings("unused")
170 public List<TrashRenderer> getTrashContainerModelTrashRenderers(
171 long classPK, int start, int end)
172 throws PortalException, SystemException {
173
174 return Collections.emptyList();
175 }
176
177 public TrashRenderer getTrashRenderer(long classPK)
178 throws PortalException, SystemException {
179
180 AssetRendererFactory assetRendererFactory = getAssetRendererFactory();
181
182 if (assetRendererFactory != null) {
183 AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(
184 classPK);
185
186 if (assetRenderer instanceof TrashRenderer) {
187 return (TrashRenderer)assetRenderer;
188 }
189 }
190
191 return null;
192 }
193
194 public boolean hasTrashPermission(
195 PermissionChecker permissionChecker, long groupId, long classPK,
196 String trashActionId)
197 throws PortalException, SystemException {
198
199 String actionId = trashActionId;
200
201 if (trashActionId.equals(ActionKeys.DELETE)) {
202 actionId = ActionKeys.DELETE;
203 }
204 else if (trashActionId.equals(TrashActionKeys.OVERWRITE)) {
205 actionId = ActionKeys.DELETE;
206 }
207 else if (trashActionId.equals(TrashActionKeys.MOVE)) {
208 return false;
209 }
210 else if (trashActionId.equals(TrashActionKeys.RENAME)) {
211 actionId = ActionKeys.UPDATE;
212 }
213 else if (trashActionId.equals(TrashActionKeys.RESTORE)) {
214 actionId = ActionKeys.DELETE;
215 }
216
217 return hasPermission(permissionChecker, classPK, actionId);
218 }
219
220 public boolean isContainerModel() {
221 return false;
222 }
223
224 public boolean isDeletable() {
225 return true;
226 }
227
228 @SuppressWarnings("unused")
229 public boolean isInTrashContainer(long classPK)
230 throws PortalException, SystemException {
231
232 return false;
233 }
234
235 public boolean isMovable() {
236 return false;
237 }
238
239 @SuppressWarnings("unused")
240 public boolean isRestorable(long classPK)
241 throws PortalException, SystemException {
242
243 return true;
244 }
245
246 @SuppressWarnings("unused")
247 public void moveEntry(
248 long classPK, long containerModelId, ServiceContext serviceContext)
249 throws PortalException, SystemException {
250 }
251
252 public void moveTrashEntry(
253 long classPK, long containerModelId, ServiceContext serviceContext)
254 throws PortalException, SystemException {
255
256 if (isRestorable(classPK)) {
257 restoreTrashEntry(classPK);
258 }
259
260 _log.error(
261 "moveTrashEntry() is not implemented in " + getClass().getName());
262
263 throw new SystemException();
264 }
265
266 @SuppressWarnings("unused")
267 public void restoreRelatedTrashEntry(String className, long classPK)
268 throws PortalException, SystemException {
269 }
270
271 public void restoreTrashEntry(long classPK)
272 throws PortalException, SystemException {
273
274 restoreTrashEntries(new long[] {classPK});
275 }
276
277 @SuppressWarnings("unused")
278 public void updateTitle(long classPK, String title)
279 throws PortalException, SystemException {
280 }
281
282 protected AssetRendererFactory getAssetRendererFactory() {
283 return AssetRendererFactoryRegistryUtil.
284 getAssetRendererFactoryByClassName(getClassName());
285 }
286
287 protected abstract boolean hasPermission(
288 PermissionChecker permissionChecker, long classPK, String actionId)
289 throws PortalException, SystemException;
290
291 private static Log _log = LogFactoryUtil.getLog(BaseTrashHandler.class);
292
293 }