01: /*
02: * Copyright 2003 The Apache Software Foundation.
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:
17: package velosurf.validation;
18:
19: import java.util.Locale;
20:
21: /**
22: * <p>A "not empty" constraint. Syntax is:</p>
23: * <pre>
24: * <<i>column</i> not-empty="true"/>
25: * </pre>
26: *<p>Or:</p>
27: * <pre> <<i>column</i>>
28: * <not-empty [message="<i>error-message</i>"]/>
29: * </<i>column</i>></pre>
30: * <p>Note: this constraint is not meant to replace an internal SQL clause in the database,
31: * since it cannot be made sure that complex updates will respect this constraint.</p>
32: *
33: * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
34: */
35: public class NotEmpty extends FieldConstraint {
36:
37: /**
38: * Default constructor.
39: */
40: public NotEmpty() {
41: setMessage("field {0} cannot be empty");
42: }
43:
44: /**
45: * Validate datea against this constraint.
46: * @param data the data to be validated
47: * @return true if data is not null and not empty
48: */
49: public boolean validate(Object data) {
50: return data != null && data.toString().length() > 0;
51: }
52:
53: /**
54: * return a string representation for this constraint.
55: * @return string
56: */
57: public String toString() {
58: return "not-empty";
59: }
60: }
|