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.StringUtil;
020    import com.liferay.portal.model.User;
021    import com.liferay.portal.security.auth.EmailAddressValidator;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Jorge Ferrer
026     */
027    public class UserEmailAddressException extends PortalException {
028    
029            /**
030             * @deprecated As of 7.0.0, replaced by the inner classes
031             */
032            @Deprecated
033            public UserEmailAddressException() {
034            }
035    
036            /**
037             * @deprecated As of 7.0.0, replaced by the inner classes
038             */
039            @Deprecated
040            public UserEmailAddressException(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 UserEmailAddressException(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 UserEmailAddressException(Throwable cause) {
057                    super(cause);
058            }
059    
060            public static class MustBeEqual extends UserEmailAddressException {
061    
062                    public MustBeEqual(
063                            User user, String emailAddress1, String emailAddress2) {
064    
065                            super(
066                                    String.format(
067                                            "Email address 1 %s and email address 2 %s for user %s " +
068                                                    "must be equal",
069                                            emailAddress1, emailAddress2, user.getUserId()));
070    
071                            this.user = user;
072                            this.emailAddress1 = emailAddress1;
073                            this.emailAddress2 = emailAddress2;
074                    }
075    
076                    public final String emailAddress1;
077                    public final String emailAddress2;
078                    public final User user;
079    
080            }
081    
082            public static class MustNotBeDuplicate extends UserEmailAddressException {
083    
084                    public MustNotBeDuplicate(long userId, String emailAddress) {
085                            super(
086                                    String.format(
087                                            "Email address %s must not be duplicate but is already " +
088                                                    "used by user %s",
089                                            emailAddress, userId));
090    
091                            this.userId = userId;
092                            this.emailAddress = emailAddress;
093                    }
094    
095                    public String emailAddress;
096                    public final long userId;
097    
098            }
099    
100            public static class MustNotBeNull extends UserEmailAddressException {
101    
102                    public MustNotBeNull() {
103                            super("Email address must not be null");
104                    }
105    
106                    public MustNotBeNull(String fullName) {
107                            super(
108                                    String.format(
109                                            "Email address must not be null for the full name %s",
110                                            fullName));
111                    }
112    
113            }
114    
115            public static class MustNotBePOP3User extends UserEmailAddressException {
116    
117                    public MustNotBePOP3User(String emailAddress) {
118                            super(
119                                    String.format(
120                                            "Email address %s must not be the one used to connect to " +
121                                                    "the POP3 server",
122                                            emailAddress));
123    
124                            this.emailAddress = emailAddress;
125                    }
126    
127                    public final String emailAddress;
128    
129            }
130    
131            public static class MustNotBeReserved extends UserEmailAddressException {
132    
133                    public MustNotBeReserved(
134                            String emailAddress, String[] reservedEmailAddresses) {
135    
136                            super(
137                                    String.format(
138                                            "Email address %s must not be a reserved one such as: %s",
139                                            emailAddress, StringUtil.merge(reservedEmailAddresses)));
140    
141                            this.emailAddress = emailAddress;
142                            this.reservedEmailAddresses = reservedEmailAddresses;
143                    }
144    
145                    public final String emailAddress;
146                    public final String[] reservedEmailAddresses;
147    
148            }
149    
150            public static class MustNotUseCompanyMx extends UserEmailAddressException {
151    
152                    public MustNotUseCompanyMx(String emailAddress) {
153                            super(
154                                    String.format(
155                                            "Email address %s must not use the MX of the company or " +
156                                                    "one of the associated mail host names",
157                                            emailAddress));
158    
159                            this.emailAddress = emailAddress;
160                    }
161    
162                    public final String emailAddress;
163    
164            }
165    
166            public static class MustValidate extends UserEmailAddressException {
167    
168                    public MustValidate(
169                            String emailAddress, EmailAddressValidator emailAddressValidator) {
170    
171                            super(
172                                    String.format(
173                                            "Email name address %s must validate with %s", emailAddress,
174                                            ClassUtil.getClassName(emailAddressValidator)));
175    
176                            this.emailAddress = emailAddress;
177                            this.emailAddressValidator = emailAddressValidator;
178                    }
179    
180                    public String emailAddress;
181                    public final EmailAddressValidator emailAddressValidator;
182    
183            }
184    
185    }