| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.datadictionary.validation.constraint; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
| 20 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 21 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 22 | |
|
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.List; |
| 25 | |
import java.util.regex.Pattern; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 8 | public class CharsetPatternConstraint extends ValidCharactersPatternConstraint { |
| 33 | |
protected String validChars; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public String getValidChars() { |
| 39 | 0 | return validChars; |
| 40 | |
} |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public void setValidChars(String validChars) { |
| 46 | 8 | if (StringUtils.isEmpty(validChars)) { |
| 47 | 0 | throw new IllegalArgumentException("invalid (empty) validChars"); |
| 48 | |
} |
| 49 | |
|
| 50 | 8 | this.validChars = validChars; |
| 51 | 8 | } |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
protected String getRegexString() { |
| 60 | 4 | if (StringUtils.isEmpty(validChars)) { |
| 61 | 0 | throw new IllegalStateException("validChars is empty"); |
| 62 | |
} |
| 63 | |
|
| 64 | |
|
| 65 | 4 | Pattern filteringChars = Pattern.compile("([\\-\\[\\]\\{\\}\\$\\.\\^\\(\\)\\*\\&\\|])"); |
| 66 | 4 | String filteredChars = filteringChars.matcher(validChars).replaceAll("\\\\$1"); |
| 67 | |
|
| 68 | 4 | StringBuffer regexString = new StringBuffer("["); |
| 69 | 4 | regexString.append(filteredChars); |
| 70 | 4 | if (filteredChars.endsWith("\\")) { |
| 71 | 0 | regexString.append("\\"); |
| 72 | |
} |
| 73 | 4 | regexString.append("]"); |
| 74 | |
|
| 75 | 4 | return regexString.toString(); |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public String getLabelKey() { |
| 84 | 4 | String labelKey = super.getLabelKey(); |
| 85 | 4 | if (StringUtils.isNotEmpty(labelKey)) { |
| 86 | 0 | return labelKey; |
| 87 | |
} |
| 88 | 4 | return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "charsetPattern"); |
| 89 | |
} |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
public List<String> getValidationMessageParams() { |
| 96 | 0 | if(validationMessageParams == null){ |
| 97 | 0 | validationMessageParams = new ArrayList<String>(); |
| 98 | 0 | if (StringUtils.isNotBlank(validChars)) { |
| 99 | 0 | validationMessageParams.add(validChars); |
| 100 | |
} |
| 101 | |
|
| 102 | |
} |
| 103 | 0 | return this.validationMessageParams; |
| 104 | |
} |
| 105 | |
|
| 106 | |
} |