javadoc
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / validation / constraint / NullOrNotEmptyValidator.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.validation.constraint;
11
12 import javax.validation.ConstraintValidator;
13 import javax.validation.ConstraintValidatorContext;
14
15 import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
16
17 public class NullOrNotEmptyValidator implements
18 ConstraintValidator<NullOrNotEmpty, String> {
19
20 public void initialize(NullOrNotEmpty nullOrNotEmpty) { }
21
22 public boolean isValid(String string, ConstraintValidatorContext constraintContext) {
23 boolean isValid = false;
24 if(string == null) {
25 isValid = true;
26 } else if(string.trim().length() > 0) {
27 isValid = true;
28 }
29
30 return isValid;
31 }
32 }