1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary.validation.charlevel;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
21 import org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern;
22
23
24
25
26
27
28
29
30 @Deprecated
31 public class RegexValidationPattern extends CharacterLevelValidationPattern {
32
33 private static final long serialVersionUID = -5642894236634278352L;
34 private static final Logger LOG=Logger.getLogger(RegexValidationPattern.class);
35
36
37
38 private String pattern;
39
40 private String validationErrorMessageKey;
41
42
43
44
45
46 @Override
47 public void extendExportMap(ExportMap exportMap) {
48 if (LOG.isTraceEnabled()) {
49 String message=String.format("ENTRY %s",
50 (exportMap==null)?"null":exportMap.toString());
51 LOG.trace(message);
52 }
53
54
55 exportMap.set("type", "regex");
56
57 exportMap.set("pattern", getPattern());
58
59 if (LOG.isTraceEnabled()) {
60 String message=String.format("EXIT %s",
61 (exportMap==null)?"null":exportMap.toString());
62 LOG.trace(message);
63 }
64
65 }
66
67
68
69
70
71
72 public String getPatternXml() {
73 if (LOG.isTraceEnabled()) {
74 String message=String.format("ENTRY");
75 LOG.trace(message);
76 }
77
78 StringBuffer xml = new StringBuffer("<regex ");
79 xml.append(pattern);
80 xml.append("/>");
81
82 if (LOG.isTraceEnabled()) {
83 String message=String.format("EXIT %s", xml.toString());
84 LOG.trace(message);
85 }
86
87 return xml.toString();
88 }
89
90
91
92
93
94
95
96 @Override
97 protected String getRegexString() {
98 if (LOG.isTraceEnabled()) {
99 String message=String.format("ENTRY %s",
100 (pattern==null)?"null":pattern.toString());
101 LOG.trace(message);
102 }
103
104 if (StringUtils.isEmpty(pattern)) {
105 throw new IllegalStateException(this.getClass().getName()+".pattern is empty");
106 }
107
108 if (LOG.isTraceEnabled()) {
109 String message=String.format("EXIT");
110 LOG.trace(message);
111 }
112
113 return pattern;
114 }
115
116
117
118
119 public final String getPattern() {
120 return this.pattern;
121 }
122
123
124
125
126 public final void setPattern(String pattern) {
127 this.pattern = pattern;
128 }
129
130
131
132
133 @Override
134 public String getValidationErrorMessageKey() {
135 return this.validationErrorMessageKey;
136 }
137
138
139
140
141
142 public void setValidationErrorMessageKey(String validationErrorMessageKey) {
143 this.validationErrorMessageKey = validationErrorMessageKey;
144 }
145
146
147
148
149 @Override
150 public void completeValidation() {
151 super.completeValidation();
152 if (StringUtils.isBlank(validationErrorMessageKey)) {
153 throw new ValidationPatternException("Regex Validation Patterns must have a validation error message key defined");
154 }
155 }
156 }