1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.library.web.spring;
17
18 import org.springframework.validation.Errors;
19 import org.springframework.validation.Validator;
20
21 /***
22 * @author jmccrindle
23 */
24 public class ImportValidator implements Validator {
25
26
27
28
29 public boolean supports(Class commandClass) {
30 return commandClass.equals(ImportCommand.class);
31 }
32
33 protected boolean isBlank(String value) {
34 if(value == null) return true;
35 value = value.trim();
36 return value.length() == 0;
37 }
38
39
40
41
42 public void validate(Object command, Errors errors) {
43 ImportCommand importCommand = (ImportCommand) command;
44 if(isBlank(importCommand.getSystem())) {
45 errors.rejectValue("system", "errors.required", null, "Value required");
46 }
47 if(importCommand.getFile() == null) {
48 errors.rejectValue("file", "errors.required", null, "Value required");
49 }
50 }
51
52 }