KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > sample > PWDValidator


1 /*
2  * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2003 Elmar Grom
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.sample;
23
24 import com.izforge.izpack.panels.*;
25
26 /*---------------------------------------------------------------------------*/
27 /**
28  * This class represents a simple validator for passwords to demonstrate
29  * the implementation of a password validator that cooperates with the
30  * password field in the <code>UserInputPanel</code>
31  *
32  * @version 0.0.1 / 02/19/03
33  * @author Elmar Grom
34  */

35 /*---------------------------------------------------------------------------*/
36 public class PWDValidator implements Validator
37 {
38  /*--------------------------------------------------------------------------*/
39  /**
40   * Validates the contend of multiple password fields. The test
41   *
42   * @param client the client object using the services of this validator.
43   *
44   * @return <code>true</code> if the validation passes, otherwise <code>false</code>.
45   */

46  /*--------------------------------------------------------------------------*/
47   public boolean validate (ProcessingClient client)
48   {
49     int numFields = client.getNumFields ();
50     
51     // ----------------------------------------------------
52
// verify that there is more than one field. If there
53
// is only one field we have to return true.
54
// ----------------------------------------------------
55
if (numFields < 2)
56     {
57       return (true);
58     }
59     
60     boolean match = true;
61     String JavaDoc content = client.getFieldContents (0);
62     
63     for (int i = 1; i < numFields; i++)
64     {
65       if (!content.equals (client.getFieldContents (i)))
66       {
67         match = false;
68       }
69     }
70     
71     return (match);
72   }
73 }
74 /*---------------------------------------------------------------------------*/
75
Popular Tags