1 package org.kuali.common.util.validate;
2
3 import java.lang.reflect.Field;
4
5 import org.apache.commons.lang3.StringUtils;
6 import org.kuali.common.util.ReflectionUtils;
7
8 import com.google.common.base.Optional;
9
10 public class NoBlankStringsValidator extends AbstractFieldsValidator<NoBlankStrings, Object> {
11
12 @Override
13 protected Optional<String> validate(Field field, Object instance) {
14
15
16 if (!ReflectionUtils.isString(field)) {
17 return Optional.absent();
18 }
19
20
21 Optional<?> fieldValue = ReflectionUtils.get(field, instance);
22
23
24 String string = (String) fieldValue.orNull();
25
26
27 if (string == null) {
28 return Optional.absent();
29 }
30
31
32 if (StringUtils.isBlank(string)) {
33 return Validation.errorMessage(field, "blank strings not allowed");
34 } else {
35 return Optional.absent();
36 }
37 }
38
39 }