01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.x.form.validators;
14:
15: import com.eviware.x.form.ValidationMessage;
16: import com.eviware.x.form.XFormField;
17: import com.eviware.x.form.XFormFieldValidator;
18:
19: public class RequiredValidator implements XFormFieldValidator {
20: private boolean trim;
21: private String message;
22:
23: public RequiredValidator() {
24: this .message = "Field requires a value";
25: }
26:
27: public RequiredValidator(String message) {
28: this .message = message;
29: }
30:
31: public ValidationMessage[] validateField(XFormField formField) {
32: String value = formField.getValue();
33: if (value == null || value.length() == 0
34: || (trim && value.trim().length() == 0)) {
35: return new ValidationMessage[] { new ValidationMessage(
36: message, formField) };
37: }
38:
39: return null;
40: }
41:
42: public boolean isTrim() {
43: return trim;
44: }
45:
46: public void setTrim(boolean trim) {
47: this.trim = trim;
48: }
49:
50: }
|