1 |
1412a4c4
|
Katja Luther
|
/**
|
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 |
e902c13e
|
Andreas Müller
|
*/
|
9 |
1412a4c4
|
Katja Luther
|
|
10 |
a641fad9
|
ben.clark
|
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 |
a13c5f66
|
Andreas Müller
|
public class NullOrNotEmptyValidator implements ConstraintValidator<NullOrNotEmpty, String> {
|
18 |
a641fad9
|
ben.clark
|
|
19 |
e902c13e
|
Andreas Müller
|
@Override
|
20 |
|
|
public void initialize(NullOrNotEmpty nullOrNotEmpty) { }
|
21 |
a641fad9
|
ben.clark
|
|
22 |
e902c13e
|
Andreas Müller
|
@Override
|
23 |
a641fad9
|
ben.clark
|
public boolean isValid(String string, ConstraintValidatorContext constraintContext) {
|
24 |
f6c0ba78
|
Katja Luther
|
boolean isValid = false;
|
25 |
a641fad9
|
ben.clark
|
if(string == null) {
|
26 |
f6c0ba78
|
Katja Luther
|
isValid = true;
|
27 |
a641fad9
|
ben.clark
|
} else if(string.trim().length() > 0) {
|
28 |
f6c0ba78
|
Katja Luther
|
isValid = true;
|
29 |
a641fad9
|
ben.clark
|
}
|
30 |
e902c13e
|
Andreas Müller
|
|
31 |
f6c0ba78
|
Katja Luther
|
return isValid;
|
32 |
a641fad9
|
ben.clark
|
}
|
33 |
|
|
}
|