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