KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > emailvalidator > EmailValidator


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.emailvalidator;
17
18 import org.apache.myfaces.util.MessageUtils;
19
20 import org.apache.commons.validator.GenericValidator;
21
22 import javax.faces.application.FacesMessage;
23 import javax.faces.component.UIComponent;
24 import javax.faces.context.FacesContext;
25 import javax.faces.validator.Validator;
26 import javax.faces.validator.ValidatorException;
27
28 /**
29  * @author mwessendorf (latest modification by $Author: matzew $)
30  * @version $Revision: 1.6 $ $Date: 2004/11/30 09:37:42 $
31  * $Log: EmailValidator.java,v $
32  * Revision 1.6 2004/11/30 09:37:42 matzew
33  * changes i18n-messages for validation
34  *
35  * Revision 1.5 2004/10/13 11:50:57 matze
36  * renamed packages to org.apache
37  *
38  * Revision 1.4 2004/07/01 21:53:11 mwessendorf
39  * ASF switch
40  *
41  * Revision 1.3 2004/06/16 23:02:19 o_rossmueller
42  * merged confignew_branch
43  *
44  * Revision 1.2.2.1 2004/06/13 15:59:05 o_rossmueller
45  * started integration of new config mechanism:
46  * - factories
47  * - components
48  * - render kits
49  * - managed beans + managed properties (no list/map initialization)
50  *
51  * Revision 1.2 2004/06/05 09:37:43 mwessendorf
52  * new validator for regExpr.
53  * and began with Friendly validator messages
54  *
55  * Revision 1.1 2004/05/27 14:09:01 manolito
56  * creditcard and email validator refactored
57  *
58  */

59 public class EmailValidator implements Validator {
60     
61     /**
62      * <p>The standard converter id for this converter.</p>
63      */

64     public static final String JavaDoc VALIDATOR_ID = "org.apache.myfaces.validator.Email";
65     /**
66      * <p>The message identifier of the {@link FacesMessage} to be created if
67      * the maximum length check fails.</p>
68      */

69     public static final String JavaDoc EMAIL_MESSAGE_ID = "org.apache.myfaces.Email.INVALID";
70     
71     public EmailValidator(){
72     }
73
74     /**
75      * methode that validates an email-address.
76      * it uses the commons-validator
77      */

78     public void validate(
79         FacesContext facesContext,
80         UIComponent uiComponent,
81         Object JavaDoc value)
82         throws ValidatorException {
83     
84     
85             if (facesContext == null) throw new NullPointerException JavaDoc("facesContext");
86             if (uiComponent == null) throw new NullPointerException JavaDoc("uiComponent");
87
88             if (value == null)
89             {
90                 return;
91             }
92             if (!GenericValidator.isEmail(value.toString())) {
93                 Object JavaDoc[] args = {value.toString()};
94                 throw new ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,EMAIL_MESSAGE_ID, args));
95                 
96             }
97
98     }
99
100 }
101
Popular Tags