001
014
015 package com.liferay.portlet.trash.action;
016
017 import com.liferay.portal.kernel.json.JSONFactoryUtil;
018 import com.liferay.portal.kernel.json.JSONObject;
019 import com.liferay.portal.kernel.trash.TrashHandler;
020 import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portlet.trash.DuplicateEntryException;
023 import com.liferay.portlet.trash.TrashEntryConstants;
024 import com.liferay.portlet.trash.model.TrashEntry;
025 import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
026
027 import javax.portlet.ActionRequest;
028
029
032 public class ActionUtil {
033
034 public static JSONObject checkEntry(ActionRequest actionRequest)
035 throws Exception {
036
037 long trashEntryId = ParamUtil.getLong(actionRequest, "trashEntryId");
038
039 String newName = ParamUtil.getString(actionRequest, "newName");
040
041 TrashEntry entry = TrashEntryLocalServiceUtil.getTrashEntry(
042 trashEntryId);
043
044 TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
045 entry.getClassName());
046
047 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
048
049 try {
050 trashHandler.checkDuplicateTrashEntry(
051 entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, newName);
052
053 jsonObject.put("success", true);
054 }
055 catch (DuplicateEntryException dee) {
056 jsonObject.put("duplicateEntryId", dee.getDuplicateEntryId());
057 jsonObject.put("oldName", dee.getOldName());
058 jsonObject.put("success", false);
059 jsonObject.put("trashEntryId", dee.getTrashEntryId());
060 }
061
062 return jsonObject;
063 }
064
065 }