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.model.User;
020    import com.liferay.portal.security.auth.EmailAddressValidator;
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            public UserEmailAddressException(Throwable cause) {
052                    super(cause);
053            }
054    
055            public static class MustBeEqual extends UserEmailAddressException {
056    
057                    public MustBeEqual(
058                            User user, String emailAddress1, String emailAddress2) {
059    
060                            super(
061                                    String.format(
062                                            "Email address 1 %s and email address %2 for user %s " +
063                                                    "must be equal",
064                                            emailAddress1, emailAddress2, user.getUserId()));
065    
066                            this.user = user;
067                            this.emailAddress1 = emailAddress1;
068                            this.emailAddress2 = emailAddress2;
069                    }
070    
071                    public final String emailAddress1;
072                    public final String emailAddress2;
073                    public final User user;
074    
075            }
076    
077            public static class MustNotBeDuplicate extends UserEmailAddressException {
078    
079                    public MustNotBeDuplicate(long userId, String emailAddress) {
080                            super(
081                                    String.format(
082                                            "Email address %s must not be duplicate but is already " +
083                                                    "used by user %s",
084                                            emailAddress, userId));
085    
086                            this.userId = userId;
087                            this.emailAddress = emailAddress;
088                    }
089    
090                    public String emailAddress;
091                    public final long userId;
092    
093            }
094    
095            public static class MustNotBeNull extends UserEmailAddressException {
096    
097                    public MustNotBeNull() {
098                            super("Email address must not be null");
099                    }
100    
101                    public MustNotBeNull(String fullName) {
102                            super(
103                                    String.format(
104                                            "Email address must not be null for the full name %s",
105                                            fullName));
106                    }
107    
108            }
109    
110            public static class MustValidate extends UserEmailAddressException {
111    
112                    public MustValidate(
113                            String emailAddress, EmailAddressValidator emailAddressValidator) {
114    
115                            super(
116                                    String.format(
117                                            "Email name address %s must validate with %s", emailAddress,
118                                            ClassUtil.getClassName(emailAddressValidator)));
119    
120                            this.emailAddress = emailAddress;
121                            this.emailAddressValidator = emailAddressValidator;
122                    }
123    
124                    public String emailAddress;
125                    public final EmailAddressValidator emailAddressValidator;
126    
127            }
128    
129    }