| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AlphaValidationPattern |
|
| 1.8;1.8 |
| 1 | /** | |
| 2 | * Copyright 2005-2011 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.kns.datadictionary.validation.charlevel; | |
| 17 | ||
| 18 | import org.kuali.rice.krad.datadictionary.exporter.ExportMap; | |
| 19 | import org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern; | |
| 20 | import org.kuali.rice.krad.util.KRADConstants; | |
| 21 | ||
| 22 | /** | |
| 23 | * Pattern for matching alpha characters | |
| 24 | * | |
| 25 | * | |
| 26 | */ | |
| 27 | 0 | public class AlphaValidationPattern extends CharacterLevelValidationPattern { |
| 28 | 0 | protected boolean allowWhitespace = false; |
| 29 | ||
| 30 | ||
| 31 | /** | |
| 32 | * @return allowWhitespace | |
| 33 | */ | |
| 34 | public boolean getAllowWhitespace() { | |
| 35 | 0 | return allowWhitespace; |
| 36 | } | |
| 37 | ||
| 38 | /** | |
| 39 | * @param allowWhitespace | |
| 40 | */ | |
| 41 | public void setAllowWhitespace(boolean allowWhitespace) { | |
| 42 | 0 | this.allowWhitespace = allowWhitespace; |
| 43 | 0 | } |
| 44 | ||
| 45 | ||
| 46 | /** | |
| 47 | * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString() | |
| 48 | */ | |
| 49 | protected String getRegexString() { | |
| 50 | 0 | StringBuffer regexString = new StringBuffer("[A-Za-z"); |
| 51 | ||
| 52 | 0 | if (allowWhitespace) { |
| 53 | 0 | regexString.append("\\s"); |
| 54 | } | |
| 55 | 0 | regexString.append("]"); |
| 56 | ||
| 57 | 0 | return regexString.toString(); |
| 58 | } | |
| 59 | ||
| 60 | ||
| 61 | /** | |
| 62 | * @see org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.bo.datadictionary.exporter.ExportMap) | |
| 63 | */ | |
| 64 | public void extendExportMap(ExportMap exportMap) { | |
| 65 | 0 | exportMap.set("type", "alpha"); |
| 66 | ||
| 67 | 0 | if (allowWhitespace) { |
| 68 | 0 | exportMap.set("allowWhitespace", "true"); |
| 69 | } | |
| 70 | 0 | } |
| 71 | ||
| 72 | @Override | |
| 73 | protected String getValidationErrorMessageKeyOptions() { | |
| 74 | 0 | if (getAllowWhitespace()) { |
| 75 | 0 | return ".allowWhitespace"; |
| 76 | } | |
| 77 | 0 | return KRADConstants.EMPTY_STRING; |
| 78 | } | |
| 79 | } |