001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.exception;
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.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    import com.liferay.portal.kernel.repository.model.Folder;
024    import com.liferay.portal.kernel.util.StringPool;
025    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
026    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
027    
028    import java.util.Locale;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Hugo Huijser
033     */
034    @ProviderType
035    public class InvalidFolderException extends PortalException {
036    
037            public static final int CANNOT_MOVE_INTO_CHILD_FOLDER = 1;
038    
039            public static final int CANNOT_MOVE_INTO_ITSELF = 2;
040    
041            public InvalidFolderException(int type, long folderId) {
042                    _type = type;
043                    _folderId = folderId;
044            }
045    
046            public long getFolderId() {
047                    return _folderId;
048            }
049    
050            public String getMessageArgument(Locale locale) {
051                    try {
052                            if (_folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
053                                    return LanguageUtil.get(locale, "home");
054                            }
055    
056                            Folder folder = DLAppLocalServiceUtil.getFolder(_folderId);
057    
058                            return folder.getName();
059                    }
060                    catch (PortalException pe) {
061                            if (_log.isWarnEnabled()) {
062                                    _log.warn(pe, pe);
063                            }
064    
065                            return StringPool.BLANK;
066                    }
067            }
068    
069            public String getMessageKey() {
070                    if (_type == CANNOT_MOVE_INTO_CHILD_FOLDER) {
071                            return "unable-to-move-folder-x-into-one-of-its-children";
072                    }
073                    else if (_type == CANNOT_MOVE_INTO_ITSELF) {
074                            return "unable-to-move-folder-x-into-itself";
075                    }
076    
077                    return null;
078            }
079    
080            private static final Log _log = LogFactoryUtil.getLog(
081                    InvalidFolderException.class);
082    
083            private final long _folderId;
084            private final int _type;
085    
086    }