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