001
014
015 package com.liferay.taglib.util;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.trash.TrashHandler;
021 import com.liferay.portal.kernel.trash.TrashHandlerRegistryUtil;
022 import com.liferay.portal.kernel.util.ParamUtil;
023 import com.liferay.portlet.trash.exception.RestoreEntryException;
024 import com.liferay.portlet.trash.model.TrashEntry;
025 import com.liferay.portlet.trash.model.TrashEntryConstants;
026 import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
027
028 import javax.portlet.PortletRequest;
029
030
033 public class RestoreEntryUtil {
034
035 public static JSONObject checkEntry(PortletRequest portletRequest)
036 throws PortalException {
037
038 long trashEntryId = ParamUtil.getLong(portletRequest, "trashEntryId");
039
040 String newName = ParamUtil.getString(portletRequest, "newName");
041
042 TrashEntry entry = TrashEntryLocalServiceUtil.fetchTrashEntry(
043 trashEntryId);
044
045 TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(
046 entry.getClassName());
047
048 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
049
050 try {
051 trashHandler.checkRestorableEntry(
052 entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, newName);
053
054 jsonObject.put("success", true);
055 }
056 catch (RestoreEntryException ree) {
057 jsonObject.put("duplicateEntryId", ree.getDuplicateEntryId());
058 jsonObject.put("errorMessage", ree.getErrorMessage());
059 jsonObject.put("oldName", ree.getOldName());
060 jsonObject.put("overridable", ree.isOverridable());
061 jsonObject.put("success", false);
062 jsonObject.put("trashEntryId", ree.getTrashEntryId());
063 }
064
065 return jsonObject;
066 }
067
068 }