KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > creditcardvalidator > ValidateCreditCardTag


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.creditcardvalidator;
17
18 import javax.faces.context.FacesContext;
19 import javax.faces.el.ValueBinding;
20 import javax.faces.validator.Validator;
21 import javax.faces.webapp.UIComponentTag;
22 import javax.faces.webapp.ValidatorTag;
23 import javax.servlet.jsp.JspException JavaDoc;
24
25 /**
26  * @author mwessendorf (latest modification by $Author: matze $)
27  * @version $Revision: 1.4 $ $Date: 2004/10/13 11:50:57 $
28  * $Log: ValidateCreditCardTag.java,v $
29  * Revision 1.4 2004/10/13 11:50:57 matze
30  * renamed packages to org.apache
31  *
32  * Revision 1.3 2004/09/15 07:58:59 mwessendorf
33  * Custom Validators now work in OC4J - thanks to Daniel Kamakura for supporting this
34  *
35  * Revision 1.2 2004/07/01 21:53:08 mwessendorf
36  * ASF switch
37  *
38  * Revision 1.1 2004/05/27 14:09:00 manolito
39  * creditcard and email validator refactored
40  *
41  */

42 public class ValidateCreditCardTag extends ValidatorTag {
43     //Cardtypes, that are supported by Commons-Validator.
44
private String JavaDoc _amex = null;
45     private String JavaDoc _discover = null;
46     private String JavaDoc _mastercard = null;
47     private String JavaDoc _visa = null;
48     private String JavaDoc _none = null;
49     
50     public ValidateCreditCardTag()
51     {
52     }
53
54     /**
55      * @param string
56      */

57     public void setAmex(String JavaDoc string) {
58         _amex = string;
59     }
60
61     /**
62      * @param string
63      */

64     public void setDiscover(String JavaDoc string) {
65         _discover = string;
66     }
67
68     /**
69      * @param string
70      */

71     public void setMastercard(String JavaDoc string) {
72         _mastercard = string;
73     }
74
75     /**
76      * @param string
77      */

78     public void setNone(String JavaDoc string) {
79         _none = string;
80     }
81
82     /**
83      * @param string
84      */

85     public void setVisa(String JavaDoc string) {
86         _visa = string;
87     }
88
89     /* (non-Javadoc)
90      * @see javax.faces.webapp.ValidatorTag#createValidator()
91      */

92     protected Validator createValidator() throws JspException JavaDoc {
93         
94         FacesContext facesContext = FacesContext.getCurrentInstance();
95         setValidatorId(CreditCardValidator.VALIDATOR_ID);
96         CreditCardValidator validator = (CreditCardValidator)super.createValidator();
97         if (_none != null)
98         {
99             if (UIComponentTag.isValueReference(_none))
100             {
101                 ValueBinding vb = facesContext.getApplication().createValueBinding(_none);
102                 validator.setNone(new Boolean JavaDoc(vb.getValue(facesContext).toString()).booleanValue());
103             }
104             else
105             {
106                 validator.setNone(new Boolean JavaDoc(_none).booleanValue());
107             }
108         }
109         if (_visa != null)
110         {
111             if (UIComponentTag.isValueReference(_visa))
112             {
113                 ValueBinding vb = facesContext.getApplication().createValueBinding(_visa);
114                 validator.setVisa(new Boolean JavaDoc(vb.getValue(facesContext).toString()).booleanValue());
115             }
116             else
117             {
118                 validator.setVisa(new Boolean JavaDoc(_visa).booleanValue());
119             }
120         }
121         if (_mastercard != null)
122         {
123             if (UIComponentTag.isValueReference(_mastercard))
124             {
125                 ValueBinding vb = facesContext.getApplication().createValueBinding(_mastercard);
126                 validator.setMastercard(new Boolean JavaDoc(vb.getValue(facesContext).toString()).booleanValue());
127             }
128             else
129             {
130                 validator.setMastercard(new Boolean JavaDoc(_mastercard).booleanValue());
131             }
132         }
133         if (_discover != null)
134         {
135             if (UIComponentTag.isValueReference(_discover))
136             {
137                 ValueBinding vb = facesContext.getApplication().createValueBinding(_discover);
138                 validator.setDiscover(new Boolean JavaDoc(vb.getValue(facesContext).toString()).booleanValue());
139             }
140             else
141             {
142                 validator.setDiscover(new Boolean JavaDoc(_discover).booleanValue());
143             }
144         }
145         if (_amex != null)
146         {
147             if (UIComponentTag.isValueReference(_amex))
148             {
149                 ValueBinding vb = facesContext.getApplication().createValueBinding(_amex);
150                 validator.setAmex(new Boolean JavaDoc(vb.getValue(facesContext).toString()).booleanValue());
151             }
152             else
153             {
154                 validator.setAmex(new Boolean JavaDoc(_amex).booleanValue());
155             }
156         }
157         return validator;
158     }
159     
160     
161
162     /* (non-Javadoc)
163      * @see javax.servlet.jsp.tagext.Tag#release()
164      */

165     public void release() {
166         super.release();
167         _amex = null;
168         _discover = null;
169         _mastercard = null;
170         _visa = null;
171         _none = null;
172    }
173 }
174
Popular Tags