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            public UserEmailAddressException() {
032                    super();
033            }
034    
035            /**
036             * @deprecated As of 7.0.0, replaced by the inner classes
037             */
038            public UserEmailAddressException(String msg) {
039                    super(msg);
040            }
041    
042            /**
043             * @deprecated As of 7.0.0, replaced by the inner classes
044             */
045            public UserEmailAddressException(String msg, Throwable cause) {
046                    super(msg, cause);
047            }
048    
049            public UserEmailAddressException(Throwable cause) {
050                    super(cause);
051            }
052    
053            public static class MustBeEqual extends UserEmailAddressException {
054    
055                    public MustBeEqual(
056                            User user, String emailAddress1, String emailAddress2) {
057    
058                            super(
059                                    String.format(
060                                            "Email address 1 %s and email address %2 for user %s " +
061                                                    "must be equal",
062                                            emailAddress1, emailAddress2, user.getUserId()));
063    
064                            _user = user;
065                            _emailAddress1 = emailAddress1;
066                            _emailAddress2 = emailAddress2;
067                    }
068    
069                    public String getEmailAddress1() {
070                            return _emailAddress1;
071                    }
072    
073                    public String getEmailAddress2() {
074                            return _emailAddress2;
075                    }
076    
077                    public User getUser() {
078                            return _user;
079                    }
080    
081                    private final String _emailAddress1;
082                    private final String _emailAddress2;
083                    private final User _user;
084    
085            }
086    
087            public static class MustNotBeDuplicate extends UserEmailAddressException {
088    
089                    public MustNotBeDuplicate(long userId, String emailAddress) {
090                            super(
091                                    String.format(
092                                            "Email address %s must not be duplicate but is already " +
093                                                    "used by user %s",
094                                            emailAddress, userId));
095    
096                            _userId = userId;
097                            _emailAddress = emailAddress;
098                    }
099    
100                    public String getEmailAddress() {
101                            return _emailAddress;
102                    }
103    
104                    public long getUserId() {
105                            return _userId;
106                    }
107    
108                    private String _emailAddress;
109                    private final long _userId;
110    
111            }
112    
113            public static class MustNotBeNull extends UserEmailAddressException {
114    
115                    public MustNotBeNull() {
116                            super("Email address must not be null");
117                    }
118    
119                    public MustNotBeNull(String fullName) {
120                            super(
121                                    String.format(
122                                            "Email address must not be null for the full name %s",
123                                            fullName));
124                    }
125    
126            }
127    
128            public static class MustValidate extends UserEmailAddressException {
129    
130                    public MustValidate(
131                            String emailAddress, EmailAddressValidator emailAddressValidator) {
132    
133                            super(
134                                    String.format(
135                                            "Email name address %s must validate with %s", emailAddress,
136                                            ClassUtil.getClassName(emailAddressValidator)));
137    
138                            _emailAddress = emailAddress;
139                            _emailAddressValidator = emailAddressValidator;
140                    }
141    
142                    public String getEmailAddress() {
143                            return _emailAddress;
144                    }
145    
146                    public EmailAddressValidator getEmailAddressValidator() {
147                            return _emailAddressValidator;
148                    }
149    
150                    private String _emailAddress;
151                    private final EmailAddressValidator _emailAddressValidator;
152    
153            }
154    
155    }