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