| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AnyCharacterPatternConstraint |
|
| 2.25;2.25 |
| 1 | /* | |
| 2 | * Copyright 2005-2008 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.krad.datadictionary.validation.constraint; | |
| 17 | ||
| 18 | import org.apache.commons.lang.StringUtils; | |
| 19 | import org.kuali.rice.krad.uif.UifConstants; | |
| 20 | ||
| 21 | ||
| 22 | /** | |
| 23 | * Pattern for matching any printable character | |
| 24 | * | |
| 25 | * | |
| 26 | */ | |
| 27 | 6 | public class AnyCharacterPatternConstraint extends ValidCharactersPatternConstraint { |
| 28 | 6 | protected boolean allowWhitespace = false; |
| 29 | ||
| 30 | ||
| 31 | /** | |
| 32 | * @return allowWhitespace | |
| 33 | */ | |
| 34 | public boolean getAllowWhitespace() { | |
| 35 | 2 | return allowWhitespace; |
| 36 | } | |
| 37 | ||
| 38 | /** | |
| 39 | * @param allowWhitespace | |
| 40 | */ | |
| 41 | public void setAllowWhitespace(boolean allowWhitespace) { | |
| 42 | 3 | this.allowWhitespace = allowWhitespace; |
| 43 | 3 | } |
| 44 | ||
| 45 | ||
| 46 | /** | |
| 47 | * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString() | |
| 48 | */ | |
| 49 | protected String getRegexString() { | |
| 50 | 3 | StringBuffer regexString = new StringBuffer("["); |
| 51 | ||
| 52 | ||
| 53 | 3 | regexString.append("\\x21-\\x7E"); |
| 54 | 3 | if (allowWhitespace) { |
| 55 | 1 | regexString.append("\\t\\r\\n\\v\\f\\s"); |
| 56 | } | |
| 57 | 3 | regexString.append("]"); |
| 58 | ||
| 59 | 3 | return regexString.toString(); |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * | |
| 64 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
| 65 | */ | |
| 66 | @Override | |
| 67 | public String getLabelKey() { | |
| 68 | 2 | String labelKey = super.getLabelKey(); |
| 69 | 2 | if (StringUtils.isNotEmpty(labelKey)) { |
| 70 | 0 | return labelKey; |
| 71 | } | |
| 72 | 2 | if (getAllowWhitespace()) { |
| 73 | 0 | return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "noWhitespace"; |
| 74 | } | |
| 75 | else{ | |
| 76 | 2 | return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "anyCharacterPattern"; |
| 77 | } | |
| 78 | } | |
| 79 | ||
| 80 | // @Override | |
| 81 | // protected String getValidationErrorMessageKeyOptions() { | |
| 82 | // if (getAllowWhitespace()) { | |
| 83 | // return ".allowWhitespace"; | |
| 84 | // } | |
| 85 | // return KRADConstants.EMPTY_STRING; | |
| 86 | // } | |
| 87 | ||
| 88 | } |