| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ValidDataPatternConstraint |
|
| 1.3333333333333333;1.333 |
| 1 | /* | |
| 2 | * Copyright 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/ecl1.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 | ||
| 20 | /** | |
| 21 | * Class used to | |
| 22 | * | |
| 23 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 24 | */ | |
| 25 | 0 | public abstract class ValidDataPatternConstraint extends ValidCharactersConstraint { |
| 26 | ||
| 27 | /** | |
| 28 | * the key used to identify the validation pattern | |
| 29 | */ | |
| 30 | protected String patternTypeKey; | |
| 31 | ||
| 32 | /** | |
| 33 | * Warning: This value should NOT be set on this class as the value is built dynamically from the | |
| 34 | * flags set on the constraint - if this value IS set it will override any automatic generation and only | |
| 35 | * use that which was set through this method for server side validation | |
| 36 | * | |
| 37 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint#setValue(java.lang.String) | |
| 38 | */ | |
| 39 | @Override | |
| 40 | public void setValue(String value) { | |
| 41 | 0 | super.setValue(value); |
| 42 | 0 | } |
| 43 | ||
| 44 | /** | |
| 45 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint#getValue() | |
| 46 | */ | |
| 47 | @Override | |
| 48 | public String getValue() { | |
| 49 | 0 | if(StringUtils.isEmpty(value)){ |
| 50 | 0 | return "^" + getRegexString() + "$"; |
| 51 | } | |
| 52 | 0 | return value; |
| 53 | ||
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * This overridden method ... | |
| 58 | * | |
| 59 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
| 60 | */ | |
| 61 | @Override | |
| 62 | public String getLabelKey() { | |
| 63 | 0 | StringBuilder buf = new StringBuilder(); |
| 64 | 0 | buf.append("validation.format.").append(getPatternTypeKey()); |
| 65 | 0 | return buf.toString(); |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * This method returns a string representing a regex with characters to match, this string should not | |
| 70 | * include the start(^) and end($) symbols | |
| 71 | */ | |
| 72 | abstract protected String getRegexString(); | |
| 73 | ||
| 74 | /** | |
| 75 | * the key used to identify the validation pattern | |
| 76 | * | |
| 77 | * @return the patternTypeKey | |
| 78 | */ | |
| 79 | public String getPatternTypeKey() { | |
| 80 | 0 | return this.patternTypeKey; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * the key used to identify the validation pattern | |
| 85 | * | |
| 86 | * @param patternTypeKey the patternTypeKey to set | |
| 87 | */ | |
| 88 | public void setPatternTypeKey(String patternTypeKey) { | |
| 89 | 0 | this.patternTypeKey = patternTypeKey; |
| 90 | 0 | } |
| 91 | ||
| 92 | ||
| 93 | } |