[izpack-devel] RegularExpressionValidator.java

Jeff Gordon jeff.not24 at gmail.com
Thu Jan 24 03:37:05 CET 2008


Here's a patch to allow the password fields to use the regular expression
validator.  It grabs the string to be validated from the password fields if
a PasswordGroup is sent in, and from a call to getText() otherwise to
maintain compatibility with any existing implementations.  If any other
field types are to be used they will need to be added in the "instance of"
evaluation.

- Jeff Gordon


Index: RegularExpressionValidator.java
===================================================================
--- RegularExpressionValidator.java    (revision 1998)
+++ RegularExpressionValidator.java    (working copy)
@@ -19,6 +19,7 @@

 package com.izforge.izpack.util;

+import com.izforge.izpack.panels.PasswordGroup;
 import java.util.Map;
 import java.util.regex.Pattern;

@@ -54,9 +55,25 @@
         {
             patternString = STR_PATTERN_DEFAULT;
         }
-
         Pattern pattern = Pattern.compile(patternString);
-        return pattern.matcher(client.getText()).matches();
+        return pattern.matcher(getString(client)).matches();
     }
+
+    private String getString(ProcessingClient client) {
+      String returnValue = "";
+      if (client instanceof PasswordGroup) {
+        int numFields = client.getNumFields();
+        if (numFields > 0) {
+          returnValue = client.getFieldContents(0);
+        } else {
+          // Should never get here, but might as well try and grab some
text
+          returnValue = client.getText();
+        }
+      } else {
+        // Original way to retrieve text for validation
+        returnValue = client.getText();
+      }
+      return returnValue;
+    }

 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.berlios.de/pipermail/izpack-devel/attachments/20080123/fb13a1bd/attachment.html 


More information about the izpack-devel mailing list