[izpack-changes] r2001 - izpack-src/trunk/src/lib/com/izforge/izpack/util
noreply at berlios.de
noreply at berlios.de
Thu Jan 24 20:14:34 CET 2008
Author: jgordon
Date: 2008-01-24 20:14:29 +0100 (Thu, 24 Jan 2008)
New Revision: 2001
Added:
izpack-src/trunk/src/lib/com/izforge/izpack/util/PasswordEqualityValidator.java
Log:
Implementation of sample validator for use in any installer. Shows how to get at validator parameters as well.
Added: izpack-src/trunk/src/lib/com/izforge/izpack/util/PasswordEqualityValidator.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/util/PasswordEqualityValidator.java 2008-01-24 19:11:16 UTC (rev 2000)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/util/PasswordEqualityValidator.java 2008-01-24 19:14:29 UTC (rev 2001)
@@ -0,0 +1,98 @@
+/*
+ * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
+ *
+ * https://izpack.github.io/
+ * http://developer.berlios.de/projects/izpack/
+ *
+ * Copyright 2003 Elmar Grom
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.izforge.izpack.util;
+
+import com.izforge.izpack.panels.PasswordGroup;
+import com.izforge.izpack.panels.ProcessingClient;
+import com.izforge.izpack.panels.Validator;
+import java.util.Map;
+
+
+/**
+ * This class represents a simple validator for passwords to test equality. It is
+ * based on the example implementation of a password validator that cooperates with the
+ * password field in the <code>UserInputPanel</code>. Additional validation may
+ * be done by utilizing the params added to the password field.
+ *
+ * @author Elmar Grom
+ * @author Jeff Gordon
+ */
+public class PasswordEqualityValidator implements Validator {
+
+ /**PasswordEqualityValidator
+ * Validates the contend of multiple password fields. The test
+ *
+ * @param client the client object using the services of this validator.
+ *
+ * @return <code>true</code> if the validation passes, otherwise <code>false</code>.
+ */
+ public boolean validate(ProcessingClient client) {
+ boolean returnValue = false;
+ Map params = getParams(client);
+ try {
+ returnValue = fieldsMatch(client);
+ if (returnValue) {
+ // Additional checking if params passed...
+ if (params!=null) {
+ System.out.println("Additional "+params.size()+" params not evaluated");
+ }
+ }
+ } catch (Exception e) {
+ System.out.println("validate() Failed: "+e);
+ }
+ return (returnValue);
+ }
+
+ private Map getParams(ProcessingClient client) {
+ PasswordGroup group = null;
+ Map params = null;
+ try {
+ group = (PasswordGroup)client;
+ if (group.hasParams()) {
+ params = group.getValidatorParams();
+ }
+ } catch (Exception e) {
+ System.out.println("getParams() Failed: "+e);
+ }
+ return (params);
+ }
+
+ private boolean fieldsMatch(ProcessingClient client) {
+ boolean returnValue = true;
+ int numFields = client.getNumFields();
+ // ----------------------------------------------------
+ // verify that there is more than one field. If there
+ // is only one field we have to return true.
+ // ----------------------------------------------------
+ if (numFields < 2) {
+ returnValue = true;
+ } else {
+ String content = client.getFieldContents(0);
+ for (int i = 1; i < numFields; i++) {
+ if (!content.equals(client.getFieldContents(i))) {
+ returnValue = false;
+ }
+ }
+ }
+ return returnValue;
+ }
+
+}
More information about the izpack-changes
mailing list