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 entryId = ParamUtil.getLong(actionRequest, "entryId");
038
039 String newName = ParamUtil.getString(actionRequest, "newName");
040
041 TrashEntry entry = TrashEntryLocalServiceUtil.getTrashEntry(entryId);
042
043 TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
044 entry.getClassName());
045
046 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
047
048 try {
049 trashHandler.checkDuplicateTrashEntry(
050 entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, newName);
051
052 jsonObject.put("success", true);
053 }
054 catch (DuplicateEntryException dee) {
055 jsonObject.put("duplicateEntryId", dee.getDuplicateEntryId());
056 jsonObject.put("oldName", dee.getOldName());
057 jsonObject.put("success", false);
058 jsonObject.put("trashEntryId", dee.getTrashEntryId());
059 }
060
061 return jsonObject;
062 }
063
064 }