001
014
015 package com.liferay.portlet.documentlibrary;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.exception.PortalException;
020 import com.liferay.portal.kernel.language.LanguageUtil;
021 import com.liferay.portal.kernel.repository.model.Folder;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
024 import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
025
026 import java.util.Locale;
027
028
032 @ProviderType
033 public class InvalidFolderException extends PortalException {
034
035 public static final int CANNOT_MOVE_INTO_CHILD_FOLDER = 1;
036
037 public static final int CANNOT_MOVE_INTO_ITSELF = 2;
038
039 public InvalidFolderException(int type, long folderId) {
040 _type = type;
041 _folderId = folderId;
042 }
043
044 public long getFolderId() {
045 return _folderId;
046 }
047
048 public String getMessageArgument(Locale locale) {
049 try {
050 if (_folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
051 return LanguageUtil.get(locale, "home");
052 }
053
054 Folder folder = DLAppLocalServiceUtil.getFolder(_folderId);
055
056 return folder.getName();
057 }
058 catch (PortalException pe) {
059 return StringPool.BLANK;
060 }
061 }
062
063 public String getMessageKey() {
064 if (_type == CANNOT_MOVE_INTO_CHILD_FOLDER) {
065 return "unable-to-move-folder-x-into-one-of-its-children";
066 }
067 else if (_type == CANNOT_MOVE_INTO_ITSELF) {
068 return "unable-to-move-folder-x-into-itself";
069 }
070
071 return null;
072 }
073
074 private final long _folderId;
075 private final int _type;
076
077 }