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.kernel.exception;
016    
017    import com.liferay.portal.kernel.model.Group;
018    import com.liferay.portal.kernel.security.auth.ScreenNameValidator;
019    import com.liferay.portal.kernel.util.ClassUtil;
020    import com.liferay.portal.kernel.util.LocaleUtil;
021    import com.liferay.portal.kernel.util.PropsKeys;
022    import com.liferay.portal.kernel.util.StringUtil;
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 MustNotBeDuplicate extends UserScreenNameException {
061    
062                    public MustNotBeDuplicate(long userId, String screenName) {
063                            super(
064                                    String.format(
065                                            "Screen name %s must not be duplicate but is already " +
066                                                    "used by user %s",
067                                            screenName, userId));
068    
069                            this.userId = userId;
070                            this.screenName = screenName;
071                    }
072    
073                    public final String screenName;
074                    public final long userId;
075    
076            }
077    
078            public static class MustNotBeNull extends UserScreenNameException {
079    
080                    public MustNotBeNull() {
081                            super("Screen name must not be null");
082                    }
083    
084                    public MustNotBeNull(long userId) {
085                            super(
086                                    String.format(
087                                            "Screen name must not be null for user %s", userId));
088                    }
089    
090                    public MustNotBeNull(String fullName) {
091                            super(
092                                    String.format(
093                                            "Screen name must not be null for the full name %s",
094                                            fullName));
095                    }
096    
097            }
098    
099            public static class MustNotBeNumeric extends UserScreenNameException {
100    
101                    public MustNotBeNumeric(long userId, String screenName) {
102                            super(
103                                    String.format(
104                                            "Screen name %s for user %s must not be numeric because " +
105                                                    "the portal property \"%s\" is disabled",
106                                            screenName, userId,
107                                            PropsKeys.USERS_SCREEN_NAME_ALLOW_NUMERIC));
108    
109                            this.userId = userId;
110                            this.screenName = screenName;
111                    }
112    
113                    public final String screenName;
114                    public final long userId;
115    
116            }
117    
118            public static class MustNotBeReserved extends UserScreenNameException {
119    
120                    public MustNotBeReserved(
121                            long userId, String screenName, String[] reservedScreenNames) {
122    
123                            super(
124                                    String.format(
125                                            "Screen name %s for user %s must not be a reserved name " +
126                                                    "such as: %s",
127                                            screenName, userId, StringUtil.merge(reservedScreenNames)));
128    
129                            this.userId = userId;
130                            this.screenName = screenName;
131                            this.reservedScreenNames = reservedScreenNames;
132                    }
133    
134                    public final String[] reservedScreenNames;
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: %s",
217                                            screenName, userId,
218                                            ClassUtil.getClassName(screenNameValidator),
219                                            screenNameValidator.getDescription(
220                                                    LocaleUtil.getDefault())));
221    
222                            this.userId = userId;
223                            this.screenName = screenName;
224                            this.screenNameValidator = screenNameValidator;
225                    }
226    
227                    public final String screenName;
228                    public final ScreenNameValidator screenNameValidator;
229                    public final long userId;
230    
231            }
232    
233    }