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;
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    /**
029     * @author Brian Wing Shun Chan
030     * @author Hugo Huijser
031     */
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    }