Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / util / RegularExpressionValidator.java @ 15280

History | View | Annotate | Download (2.29 KB)

1
/*
2
 *  $Id: RegularExpressionValidator.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPack
4
 *  Copyright (C) 2001-2004 Julien Ponge
5
 *
6
 *  File :               RegularExpressionValidator.java
7
 *  Description :        A validator to enforce non-empty fields.
8
 *  Author's email :     mike.cunneen@screwfix.com
9
 *  Author's Website :   N/A
10
 *
11
 *  This program is free software; you can redistribute it and/or
12
 *  modify it under the terms of the GNU General Public License
13
 *  as published by the Free Software Foundation; either version 2
14
 *  of the License, or any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
 */
25
package com.izforge.izpack.util;
26

    
27
import java.util.Map;
28

    
29
import org.apache.regexp.RE;
30

    
31
import com.izforge.izpack.panels.ProcessingClient;
32
import com.izforge.izpack.panels.RuleInputField;
33
import com.izforge.izpack.panels.Validator;
34

    
35
/**
36
 * A validator to enforce non-empty fields.
37
 *
38
 * This validator can be used for rule input fields in the UserInputPanel to make
39
 * sure that the user's entry matches a specified regular expression.
40
 *
41
 * @author Mike Cunneen <mike dot cunneen at screwfix dot com>
42
 */
43
public class RegularExpressionValidator implements Validator
44
{
45

    
46
  public static final String STR_PATTERN_DEFAULT = "[a-zA-Z0-9._-]{3,}@[a-zA-Z0-9._-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z0-9._-]{2,4}";
47

    
48
  private static final String PATTERN_PARAM = "pattern";
49

    
50
  public boolean validate(ProcessingClient client)
51
  {
52

    
53
    String patternString;
54

    
55
    RuleInputField field = (RuleInputField) client;
56
    if (field.hasParams())
57
    {
58
      Map paramMap = field.getValidatorParams();
59
      patternString = (String) paramMap.get(PATTERN_PARAM);
60

    
61
    }
62
    else
63
    {
64
      patternString = STR_PATTERN_DEFAULT;
65
    }
66

    
67
    RE pattern = new RE(patternString);
68
    return pattern.match(((RuleInputField) client).getText());
69
  }
70

    
71
}