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