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.portal.exception;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.ClassUtil;
019    import com.liferay.portal.kernel.util.LocaleUtil;
020    import com.liferay.portal.kernel.util.PropsKeys;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.model.Group;
023    import com.liferay.portal.security.auth.ScreenNameValidator;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class UserScreenNameException extends PortalException {
029    
030            /**
031             * @deprecated As of 7.0.0, replaced by the inner classes
032             */
033            @Deprecated
034            public UserScreenNameException() {
035            }
036    
037            /**
038             * @deprecated As of 7.0.0, replaced by the inner classes
039             */
040            @Deprecated
041            public UserScreenNameException(String msg) {
042                    super(msg);
043            }
044    
045            /**
046             * @deprecated As of 7.0.0, replaced by the inner classes
047             */
048            @Deprecated
049            public UserScreenNameException(String msg, Throwable cause) {
050                    super(msg, cause);
051            }
052    
053            /**
054             * @deprecated As of 7.0.0, replaced by the inner classes
055             */
056            @Deprecated
057            public UserScreenNameException(Throwable cause) {
058                    super(cause);
059            }
060    
061            public static class MustNotBeDuplicate extends UserScreenNameException {
062    
063                    public MustNotBeDuplicate(long userId, String screenName) {
064                            super(
065                                    String.format(
066                                            "Screen name %s must not be duplicate but is already " +
067                                                    "used by user %s",
068                                            screenName, userId));
069    
070                            this.userId = userId;
071                            this.screenName = screenName;
072                    }
073    
074                    public final String screenName;
075                    public final long userId;
076    
077            }
078    
079            public static class MustNotBeNull extends UserScreenNameException {
080    
081                    public MustNotBeNull() {
082                            super("Screen name must not be null");
083                    }
084    
085                    public MustNotBeNull(long userId) {
086                            super(
087                                    String.format(
088                                            "Screen name must not be null for user %s", userId));
089                    }
090    
091                    public MustNotBeNull(String fullName) {
092                            super(
093                                    String.format(
094                                            "Screen name must not be null for the full name %s",
095                                            fullName));
096                    }
097    
098            }
099    
100            public static class MustNotBeNumeric extends UserScreenNameException {
101    
102                    public MustNotBeNumeric(long userId, String screenName) {
103                            super(
104                                    String.format(
105                                            "Screen name %s for user %s must not be numeric because " +
106                                                    "the portal property \"%s\" is disabled",
107                                            screenName, userId,
108                                            PropsKeys.USERS_SCREEN_NAME_ALLOW_NUMERIC));
109    
110                            this.userId = userId;
111                            this.screenName = screenName;
112                    }
113    
114                    public final String screenName;
115                    public final long userId;
116    
117            }
118    
119            public static class MustNotBeReserved extends UserScreenNameException {
120    
121                    public MustNotBeReserved(
122                            long userId, String screenName, String[] reservedScreenNames) {
123    
124                            super(
125                                    String.format(
126                                            "Screen name %s for user %s must not be a reserved name " +
127                                                    "such as: %s",
128                                            screenName, userId, StringUtil.merge(reservedScreenNames)));
129    
130                            this.userId = userId;
131                            this.screenName = screenName;
132                            this.reservedScreenNames = reservedScreenNames;
133                    }
134    
135                    public final String[] reservedScreenNames;
136                    public final String screenName;
137                    public final long userId;
138    
139            }
140    
141            public static class MustNotBeReservedForAnonymous
142                    extends UserScreenNameException {
143    
144                    public MustNotBeReservedForAnonymous(
145                            long userId, String screenName, String[] reservedScreenNames) {
146    
147                            super(
148                                    String.format(
149                                            "Screen name %s for user %s must not be a reserved name " +
150                                                    "for anonymous users such as: %s",
151                                            screenName, userId, StringUtil.merge(reservedScreenNames)));
152    
153                            this.userId = userId;
154                            this.screenName = screenName;
155                            this.reservedScreenNames = reservedScreenNames;
156                    }
157    
158                    public final String[] reservedScreenNames;
159                    public final String screenName;
160                    public final long userId;
161    
162            }
163    
164            public static class MustNotBeUsedByGroup extends UserScreenNameException {
165    
166                    public MustNotBeUsedByGroup(
167                            long userId, String screenName, Group group) {
168    
169                            super(
170                                    String.format(
171                                            "Screen name %s for user %s must not be used by group %s",
172                                            screenName, userId, group.getGroupId()));
173    
174                            this.userId = userId;
175                            this.screenName = screenName;
176                            this.group = group;
177                    }
178    
179                    public final Group group;
180                    public final String screenName;
181                    public final long userId;
182    
183            }
184    
185            public static class MustProduceValidFriendlyURL
186                    extends UserScreenNameException {
187    
188                    public MustProduceValidFriendlyURL(
189                            long userId, String screenName, int exceptionType) {
190    
191                            super(
192                                    String.format(
193                                            "Screen name %s for user %s must produce a valid " +
194                                                    "friendly URL",
195                                            screenName, userId),
196                                    new GroupFriendlyURLException(exceptionType));
197    
198                            this.userId = userId;
199                            this.screenName = screenName;
200                            this.exceptionType = exceptionType;
201                    }
202    
203                    public final int exceptionType;
204                    public final String screenName;
205                    public final long userId;
206    
207            }
208    
209            public static class MustValidate extends UserScreenNameException {
210    
211                    public MustValidate(
212                            long userId, String screenName,
213                            ScreenNameValidator screenNameValidator) {
214    
215                            super(
216                                    String.format(
217                                            "Screen name %s for user %s must validate with %s: %s",
218                                            screenName, userId,
219                                            ClassUtil.getClassName(screenNameValidator),
220                                            screenNameValidator.getDescription(
221                                                    LocaleUtil.getDefault())));
222    
223                            this.userId = userId;
224                            this.screenName = screenName;
225                            this.screenNameValidator = screenNameValidator;
226                    }
227    
228                    public final String screenName;
229                    public final ScreenNameValidator screenNameValidator;
230                    public final long userId;
231    
232            }
233    
234    }