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;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.ClassUtil;
019    import com.liferay.portal.kernel.util.PropsKeys;
020    import com.liferay.portal.kernel.util.StringUtil;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.security.auth.ScreenNameValidator;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class UserScreenNameException extends PortalException {
028    
029            /**
030             * @deprecated As of 7.0.0, replaced by the inner classes
031             */
032            @Deprecated
033            public UserScreenNameException() {
034                    super();
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 MustBeAlphaNumeric extends UserScreenNameException {
062    
063                    public MustBeAlphaNumeric(
064                            long userId, String screenName, char ... validSpecialChars) {
065    
066                            super(
067                                    String.format(
068                                            "Screen name %s for user %s must be alphanumeric or one " +
069                                                    "of the following special characters: %s",
070                                            screenName, userId, new String(validSpecialChars)));
071    
072                            _userId = userId;
073                            _screenName = screenName;
074                            _validSpecialChars = validSpecialChars;
075                    }
076    
077                    public String getScreenName() {
078                            return _screenName;
079                    }
080    
081                    public long getUserId() {
082                            return _userId;
083                    }
084    
085                    public char[] getValidSpecialChars() {
086                            return _validSpecialChars;
087                    }
088    
089                    private String _screenName;
090                    private long _userId;
091                    private final char[] _validSpecialChars;
092    
093            }
094    
095            public static class MustNotBeDuplicate extends UserScreenNameException {
096    
097                    public MustNotBeDuplicate(long userId, String screenName) {
098                            super(
099                                    String.format(
100                                            "Screen name %s must not be duplicate but is already " +
101                                                    "used by user %s",
102                                            screenName, userId));
103    
104                            _userId = userId;
105                            _screenName = screenName;
106                    }
107    
108                    public String getScreenName() {
109                            return _screenName;
110                    }
111    
112                    public long getUserId() {
113                            return _userId;
114                    }
115    
116                    private String _screenName;
117                    private long _userId;
118    
119            }
120    
121            public static class MustNotBeNull extends UserScreenNameException {
122    
123                    public MustNotBeNull() {
124                            super("Screen name must not be null");
125                    }
126    
127                    public MustNotBeNull(long userId) {
128                            super(
129                                    String.format(
130                                            "Screen name must not be null for user %s", userId));
131                    }
132    
133                    public MustNotBeNull(String fullName) {
134                            super(
135                                    String.format(
136                                            "Screen name must not be null for the full name %s",
137                                            fullName));
138                    }
139    
140            }
141    
142            public static class MustNotBeNumeric extends UserScreenNameException {
143    
144                    public MustNotBeNumeric(long userId, String screenName) {
145                            super(
146                                    String.format(
147                                            "Screen name %s for user %s must not be numeric because " +
148                                                    "the portal property \"%s\" is disabled",
149                                            screenName, userId,
150                                            PropsKeys.USERS_SCREEN_NAME_ALLOW_NUMERIC));
151    
152                            _userId = userId;
153                            _screenName = screenName;
154                    }
155    
156                    public String getScreenName() {
157                            return _screenName;
158                    }
159    
160                    public long getUserId() {
161                            return _userId;
162                    }
163    
164                    private String _screenName;
165                    private long _userId;
166    
167            }
168    
169            public static class MustNotBeReservedForAnonymous
170                    extends UserScreenNameException {
171    
172                    public MustNotBeReservedForAnonymous(
173                            long userId, String screenName, String[] reservedScreenNames) {
174    
175                            super(
176                                    String.format(
177                                            "Screen name %s for user %s must not be a reserved name " +
178                                                    "for anonymous users such as: %s",
179                                            screenName, userId, StringUtil.merge(reservedScreenNames)));
180    
181                            _userId = userId;
182                            _screenName = screenName;
183                            _reservedScreenNames = reservedScreenNames;
184                    }
185    
186                    public String[] getReservedScreenNames() {
187                            return _reservedScreenNames;
188                    }
189    
190                    public String getScreenName() {
191                            return _screenName;
192                    }
193    
194                    public long getUserId() {
195                            return _userId;
196                    }
197    
198                    private final String[] _reservedScreenNames;
199                    private String _screenName;
200                    private long _userId;
201    
202            }
203    
204            public static class MustNotBeUsedByGroup extends UserScreenNameException {
205    
206                    public MustNotBeUsedByGroup(
207                            long userId, String screenName, Group group) {
208    
209                            super(
210                                    String.format(
211                                            "Screen name %s for user %s must not be used by group %s",
212                                            screenName, userId, group.getGroupId()));
213    
214                            _userId = userId;
215                            _screenName = screenName;
216                            _group = group;
217                    }
218    
219                    public Group getGroup() {
220                            return _group;
221                    }
222    
223                    public String getScreenName() {
224                            return _screenName;
225                    }
226    
227                    public long getUserId() {
228                            return _userId;
229                    }
230    
231                    private final Group _group;
232                    private String _screenName;
233                    private long _userId;
234    
235            }
236    
237            public static class MustProduceValidFriendlyURL
238                    extends UserScreenNameException {
239    
240                    public MustProduceValidFriendlyURL(
241                            long userId, String screenName, int exceptionType) {
242    
243                            super(
244                                    String.format(
245                                            "Screen name %s for user %s must produce a valid " +
246                                                    "friendly URL",
247                                            screenName, userId),
248                                    new GroupFriendlyURLException(exceptionType));
249    
250                            _userId = userId;
251                            _screenName = screenName;
252                            _exceptionType = exceptionType;
253                    }
254    
255                    public int getExceptionType() {
256                            return _exceptionType;
257                    }
258    
259                    public String getScreenName() {
260                            return _screenName;
261                    }
262    
263                    public long getUserId() {
264                            return _userId;
265                    }
266    
267                    private final int _exceptionType;
268                    private String _screenName;
269                    private long _userId;
270    
271            }
272    
273            public static class MustValidate extends UserScreenNameException {
274    
275                    public MustValidate(
276                            long userId, String screenName,
277                            ScreenNameValidator screenNameValidator) {
278    
279                            super(
280                                    String.format(
281                                            "Screen name %s for user %s must validate with %s",
282                                            screenName, userId,
283                                            ClassUtil.getClassName(screenNameValidator)));
284    
285                            _userId = userId;
286                            _screenName = screenName;
287                            _screenNameValidator = screenNameValidator;
288                    }
289    
290                    public String getScreenName() {
291                            return _screenName;
292                    }
293    
294                    public ScreenNameValidator getScreenNameValidator() {
295                            return _screenNameValidator;
296                    }
297    
298                    public long getUserId() {
299                            return _userId;
300                    }
301    
302                    private String _screenName;
303                    private final ScreenNameValidator _screenNameValidator;
304                    private long _userId;
305    
306            }
307    
308    }