01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.tp23.antinstaller.input;
17:
18: import org.tp23.antinstaller.InstallerContext;
19: import org.tp23.antinstaller.ValidationException;
20:
21: /**
22: * a second password field that checks to see if a password entered twice matches
23: * @author Paul Hinds
24: * @version $Id$
25: */
26: public class ConfirmPasswordTextInput extends PasswordTextInput {
27: private String origField;
28:
29: /**
30: * Called to validate the user input, if the confirm flag is set
31: * and there is a password field on the same page with the same property name
32: * both passwords must match for validation to pass
33: */
34: public boolean validate(InstallerContext ctx)
35: throws ValidationException {
36: OutputField[] otherFields = ctx.getCurrentPage()
37: .getOutputField();
38: for (int i = 0; i < otherFields.length; i++) {
39: if (otherFields[i] instanceof PasswordTextInput
40: && otherFields[i] != this ) {
41: PasswordTextInput pwd = (PasswordTextInput) otherFields[i];
42: if (pwd.getProperty().equals(getOrigField())) {
43: return this .getInputResult().equals(
44: pwd.getInputResult());
45: }
46: }
47: }
48: throw new ValidationException(
49: "Confirm password requires a PasswordTextInput, on the same page, with property "
50: + getOrigField());
51: }
52:
53: public boolean validateObject() {
54: if (getOrigField() == null) {
55: System.out.println("ConfirmPassword:origField must be set");
56: return false;
57: }
58: // @TODO check the orig field exists
59:
60: // FIX validator from RFE 1685291
61: if (!InputField.optionalBoolean(getTextMask())) {
62: System.out
63: .println("Comment:textMask must be true or false or null:"
64: + getTextMask());
65: return false;
66: }
67: if (getDisplayText() == null) {
68: System.out.println("Password:displayText must be set");
69: return false;
70: }
71: if (getProperty() == null) {
72: System.out.println("Password:property must be set");
73: return false;
74: }
75: if (getDefaultValue() == null) {
76: System.out.println("Password:defaultValue must be set");
77: return false;
78: }
79: return true;
80: }
81:
82: public String getOrigField() {
83: return origField;
84: }
85:
86: public void setOrigField(String origField) {
87: this.origField = origField;
88: }
89:
90: }
|