001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
006 * 
007 * Copyright 2003 Elmar Grom
008 * 
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *     http://www.apache.org/licenses/LICENSE-2.0
014 *     
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 */
021
022package   com.izforge.izpack.sample;
023
024import com.izforge.izpack.panels.ProcessingClient;
025import com.izforge.izpack.panels.Validator;
026
027/*---------------------------------------------------------------------------*/
028/**
029 * This class represents a simple validator for passwords to demonstrate
030 * the implementation of a password validator that cooperates with the
031 * password field in the <code>UserInputPanel</code>
032 *
033 * @version  0.0.1 / 02/19/03
034 * @author   Elmar Grom
035 */
036/*---------------------------------------------------------------------------*/
037public class PWDValidator implements Validator
038{
039 /*--------------------------------------------------------------------------*/
040 /**
041  * Validates the contend of multiple password fields. The test 
042  *
043  * @param     client   the client object using the services of this validator.
044  *
045  * @return    <code>true</code> if the validation passes, otherwise <code>false</code>.
046  */
047 /*--------------------------------------------------------------------------*/
048  public boolean validate (ProcessingClient client)
049  {
050    int numFields = client.getNumFields ();
051    
052    // ----------------------------------------------------
053    // verify that there is more than one field. If there
054    // is only one field we have to return true.
055    // ----------------------------------------------------
056    if (numFields < 2)
057    {
058      return (true);
059    }
060    
061    boolean match   = true;
062    String  content = client.getFieldContents (0);
063    
064    for (int i = 1; i < numFields; i++)
065    {
066      if (!content.equals (client.getFieldContents (i)))
067      {
068        match = false;
069      }      
070    }
071    
072    return (match);
073  }
074}
075/*---------------------------------------------------------------------------*/