| 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 java.util.ArrayList; |
| 19 | |
import java.util.List; |
| 20 | |
|
| 21 | |
import org.apache.commons.lang.StringUtils; |
| 22 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
| 23 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
| 24 | |
import org.kuali.rice.krad.uif.UifConstants; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 10 | public class AlphaPatternConstraint extends ValidCharactersPatternConstraint { |
| 33 | 10 | protected boolean allowWhitespace = false; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public boolean getAllowWhitespace() { |
| 40 | 0 | return allowWhitespace; |
| 41 | |
} |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public void setAllowWhitespace(boolean allowWhitespace) { |
| 47 | 5 | this.allowWhitespace = allowWhitespace; |
| 48 | 5 | } |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
protected String getRegexString() { |
| 55 | 5 | StringBuffer regexString = new StringBuffer("[A-Za-z"); |
| 56 | |
|
| 57 | 5 | if (allowWhitespace) { |
| 58 | 3 | regexString.append("\\s"); |
| 59 | |
} |
| 60 | 5 | regexString.append("]"); |
| 61 | |
|
| 62 | 5 | return regexString.toString(); |
| 63 | |
} |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public String getLabelKey() { |
| 71 | 6 | String labelKey = super.getLabelKey(); |
| 72 | 6 | if (StringUtils.isNotEmpty(labelKey)) { |
| 73 | 0 | return labelKey; |
| 74 | |
} |
| 75 | |
|
| 76 | 6 | return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPattern"; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public List<String> getValidationMessageParams() { |
| 84 | 0 | if(validationMessageParams == null){ |
| 85 | 0 | validationMessageParams = new ArrayList<String>(); |
| 86 | 0 | ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService(); |
| 87 | 0 | StringBuilder paramString = new StringBuilder(""); |
| 88 | 0 | if (getAllowWhitespace()) { |
| 89 | 0 | paramString.append(", " + configService |
| 90 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "whitespace")); |
| 91 | |
} |
| 92 | 0 | validationMessageParams.add(paramString.toString()); |
| 93 | |
} |
| 94 | 0 | return this.validationMessageParams; |
| 95 | |
} |
| 96 | |
|
| 97 | |
} |