001    /**
002     * Copyright (c) 2000-2013 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.exception.SystemException;
021    import com.liferay.portal.kernel.language.LanguageUtil;
022    import com.liferay.portal.kernel.repository.model.Folder;
023    import com.liferay.portal.kernel.util.StringPool;
024    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
025    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
026    
027    import java.util.Locale;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Hugo Huijser
032     */
033    @ProviderType
034    public class InvalidFolderException extends PortalException {
035    
036            public static final int CANNOT_MOVE_INTO_CHILD_FOLDER = 1;
037    
038            public static final int CANNOT_MOVE_INTO_ITSELF = 2;
039    
040            /**
041             * @deprecated As of 7.0.0, replaced by {@link #InvalidFolderException(int,
042             *             long)}
043             */
044            @Deprecated
045            public InvalidFolderException() {
046                    super();
047            }
048    
049            public InvalidFolderException(int type, long folderId) {
050                    _type = type;
051                    _folderId = folderId;
052            }
053    
054            /**
055             * @deprecated As of 7.0.0, replaced by {@link #InvalidFolderException(int,
056             *             long)}
057             */
058            @Deprecated
059            public InvalidFolderException(String msg) {
060                    super(msg);
061            }
062    
063            /**
064             * @deprecated As of 7.0.0, replaced by {@link #InvalidFolderException(int,
065             *             long)}
066             */
067            @Deprecated
068            public InvalidFolderException(String msg, Throwable cause) {
069                    super(msg, cause);
070            }
071    
072            /**
073             * @deprecated As of 7.0.0, replaced by {@link #InvalidFolderException(int,
074             *             long)}
075             */
076            @Deprecated
077            public InvalidFolderException(Throwable cause) {
078                    super(cause);
079            }
080    
081            public long getFolderId() {
082                    return _folderId;
083            }
084    
085            public String getMessageArgument(Locale locale) throws SystemException {
086                    try {
087                            if (_folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
088                                    return LanguageUtil.get(locale, "home");
089                            }
090    
091                            Folder folder = DLAppLocalServiceUtil.getFolder(_folderId);
092    
093                            return folder.getName();
094                    }
095                    catch (PortalException pe) {
096                            return StringPool.BLANK;
097                    }
098            }
099    
100            public String getMessageKey() {
101                    if (_type == CANNOT_MOVE_INTO_CHILD_FOLDER) {
102                            return "unable-to-move-folder-x-into-one-of-its-children";
103                    }
104                    else if (_type == CANNOT_MOVE_INTO_ITSELF) {
105                            return "unable-to-move-folder-x-into-itself";
106                    }
107    
108                    return null;
109            }
110    
111            private long _folderId;
112            private int _type;
113    
114    }