1 package com.github.mygreen.supercsv.cellprocessor;
2
3 import org.supercsv.cellprocessor.CellProcessorAdaptor;
4 import org.supercsv.cellprocessor.ift.CellProcessor;
5 import org.supercsv.util.CsvContext;
6
7 import com.github.mygreen.supercsv.exception.SuperCsvValidationException;
8 import com.github.mygreen.supercsv.util.Utils;
9
10
11
12
13
14
15
16
17 public abstract class ValidationCellProcessor extends CellProcessorAdaptor {
18
19
20
21
22 protected String validationMessage;
23
24
25
26
27 protected ValidationCellProcessor() {
28 super();
29 }
30
31
32
33
34
35
36
37 protected ValidationCellProcessor(final CellProcessor next) {
38 super(next);
39 }
40
41
42
43
44
45 public String getValidationMessage() {
46 return validationMessage;
47 }
48
49
50
51
52
53 public void setValidationMessage(String validationMessage) {
54 this.validationMessage = validationMessage;
55 }
56
57
58
59
60
61 public String getDefaultValidationMessage() {
62 return String.format("{%s.violated}", getClass().getName());
63 }
64
65
66
67
68
69
70
71 public SuperCsvValidationException.Builder createValidationException(final CsvContext context) {
72
73 String message = getValidationMessage();
74 if(Utils.isEmpty(message)) {
75 message = getDefaultValidationMessage();
76 }
77
78 return new SuperCsvValidationException.Builder(context, this)
79 .validationMessage(message);
80 }
81
82 }