| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AlphaNumericPatternConstraint |
|
| 1.8888888888888888;1.889 |
| 1 | /* | |
| 2 | * Copyright 2011 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 1.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.kns.datadictionary.validation.constraint; | |
| 17 | ||
| 18 | import org.apache.commons.lang.StringUtils; | |
| 19 | ||
| 20 | /** | |
| 21 | * A ValidCharactersConstraint based on AlphaNumericValidationPattern. | |
| 22 | * | |
| 23 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 24 | */ | |
| 25 | 0 | public class AlphaNumericPatternConstraint extends ValidCharactersPatternConstraint{ |
| 26 | 0 | protected boolean allowWhitespace = false; |
| 27 | 0 | protected boolean allowUnderscore = false; |
| 28 | 0 | protected boolean allowPeriod = false; |
| 29 | 0 | protected boolean allowParenthesis = false; |
| 30 | 0 | protected boolean allowDollar = false; |
| 31 | 0 | protected boolean allowForwardSlash = false; |
| 32 | 0 | protected boolean lowerCase = false; |
| 33 | ||
| 34 | /** | |
| 35 | * A label key is auto generated for this bean if none is set. This generated message can be overridden | |
| 36 | * through setLabelKey, but the generated message should cover most cases. | |
| 37 | * | |
| 38 | * @see org.kuali.rice.kns.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
| 39 | */ | |
| 40 | @Override | |
| 41 | public String getLabelKey() { | |
| 42 | 0 | if(StringUtils.isEmpty(labelKey)){ |
| 43 | 0 | StringBuilder key = new StringBuilder(""); |
| 44 | 0 | if(lowerCase){ |
| 45 | 0 | key.append("alphanumericPatternLowerCase,"); |
| 46 | } | |
| 47 | else{ | |
| 48 | 0 | key.append("alphanumericPattern,"); |
| 49 | } | |
| 50 | 0 | if (allowWhitespace) { |
| 51 | 0 | key.append("whitespace,"); |
| 52 | } | |
| 53 | 0 | if (allowUnderscore) { |
| 54 | 0 | key.append("underscore,"); |
| 55 | } | |
| 56 | 0 | if (allowPeriod) { |
| 57 | 0 | key.append("period,"); |
| 58 | } | |
| 59 | 0 | if(allowParenthesis) { |
| 60 | 0 | key.append("parenthesis,"); |
| 61 | } | |
| 62 | 0 | if(allowDollar) { |
| 63 | 0 | key.append("dollar,"); |
| 64 | } | |
| 65 | 0 | if(allowForwardSlash) { |
| 66 | 0 | key.append("forwardSlash"); |
| 67 | } | |
| 68 | ||
| 69 | 0 | return key.toString(); |
| 70 | } | |
| 71 | 0 | return labelKey; |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * The labelKey should only be set if the auto generated message by this class needs to be overridden | |
| 76 | * @see org.kuali.rice.kns.datadictionary.validation.constraint.BaseConstraint#setLabelKey(java.lang.String) | |
| 77 | */ | |
| 78 | @Override | |
| 79 | public void setLabelKey(String labelKey) { | |
| 80 | 0 | super.setLabelKey(labelKey); |
| 81 | 0 | } |
| 82 | ||
| 83 | /** | |
| 84 | * @see org.kuali.rice.kns.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString() | |
| 85 | */ | |
| 86 | @Override | |
| 87 | protected String getRegexString() { | |
| 88 | //Exact same logic is used here as old KS AlphaNumericValidationPattern for server side value | |
| 89 | 0 | StringBuilder regexString = new StringBuilder("[A-Za-z0-9"); |
| 90 | /* | |
| 91 | * This check must be first because we are removing the base 'A-Z' if lowerCase == true | |
| 92 | */ | |
| 93 | 0 | if(lowerCase){ |
| 94 | 0 | regexString = new StringBuilder("[a-z0-9"); |
| 95 | } | |
| 96 | ||
| 97 | 0 | if (allowWhitespace) { |
| 98 | 0 | regexString.append("\\s"); |
| 99 | } | |
| 100 | 0 | if (allowUnderscore) { |
| 101 | 0 | regexString.append("_"); |
| 102 | } | |
| 103 | 0 | if (allowPeriod) { |
| 104 | 0 | regexString.append("."); |
| 105 | } | |
| 106 | 0 | if(allowParenthesis) { |
| 107 | 0 | regexString.append("("); |
| 108 | 0 | regexString.append(")"); |
| 109 | } | |
| 110 | 0 | if(allowDollar) { |
| 111 | 0 | regexString.append("$"); |
| 112 | } | |
| 113 | 0 | if(allowForwardSlash) { |
| 114 | 0 | regexString.append("/"); |
| 115 | } | |
| 116 | 0 | regexString.append("]"); |
| 117 | ||
| 118 | 0 | return regexString.toString(); |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * @see org.kuali.rice.kns.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getJsRegexString() | |
| 123 | */ | |
| 124 | @Override | |
| 125 | protected String getJsRegexString() { | |
| 126 | //regex is the same in js for this one | |
| 127 | 0 | return getRegexString(); |
| 128 | } | |
| 129 | ||
| 130 | /** | |
| 131 | * @return the allowWhitespace | |
| 132 | */ | |
| 133 | public boolean isAllowWhitespace() { | |
| 134 | 0 | return this.allowWhitespace; |
| 135 | } | |
| 136 | /** | |
| 137 | * @param allowWhitespace the allowWhitespace to set | |
| 138 | */ | |
| 139 | public void setAllowWhitespace(boolean allowWhitespace) { | |
| 140 | 0 | this.allowWhitespace = allowWhitespace; |
| 141 | 0 | } |
| 142 | /** | |
| 143 | * @return the allowUnderscore | |
| 144 | */ | |
| 145 | public boolean isAllowUnderscore() { | |
| 146 | 0 | return this.allowUnderscore; |
| 147 | } | |
| 148 | /** | |
| 149 | * @param allowUnderscore the allowUnderscore to set | |
| 150 | */ | |
| 151 | public void setAllowUnderscore(boolean allowUnderscore) { | |
| 152 | 0 | this.allowUnderscore = allowUnderscore; |
| 153 | 0 | } |
| 154 | /** | |
| 155 | * @return the allowPeriod | |
| 156 | */ | |
| 157 | public boolean isAllowPeriod() { | |
| 158 | 0 | return this.allowPeriod; |
| 159 | } | |
| 160 | /** | |
| 161 | * @param allowPeriod the allowPeriod to set | |
| 162 | */ | |
| 163 | public void setAllowPeriod(boolean allowPeriod) { | |
| 164 | 0 | this.allowPeriod = allowPeriod; |
| 165 | 0 | } |
| 166 | /** | |
| 167 | * @return the allowParenthesis | |
| 168 | */ | |
| 169 | public boolean isAllowParenthesis() { | |
| 170 | 0 | return this.allowParenthesis; |
| 171 | } | |
| 172 | /** | |
| 173 | * @param allowParenthesis the allowParenthesis to set | |
| 174 | */ | |
| 175 | public void setAllowParenthesis(boolean allowParenthesis) { | |
| 176 | 0 | this.allowParenthesis = allowParenthesis; |
| 177 | 0 | } |
| 178 | /** | |
| 179 | * @return the allowDollar | |
| 180 | */ | |
| 181 | public boolean isAllowDollar() { | |
| 182 | 0 | return this.allowDollar; |
| 183 | } | |
| 184 | /** | |
| 185 | * @param allowDollar the allowDollar to set | |
| 186 | */ | |
| 187 | public void setAllowDollar(boolean allowDollar) { | |
| 188 | 0 | this.allowDollar = allowDollar; |
| 189 | 0 | } |
| 190 | /** | |
| 191 | * @return the allowForwardSlash | |
| 192 | */ | |
| 193 | public boolean isAllowForwardSlash() { | |
| 194 | 0 | return this.allowForwardSlash; |
| 195 | } | |
| 196 | /** | |
| 197 | * @param allowForwardSlash the allowForwardSlash to set | |
| 198 | */ | |
| 199 | public void setAllowForwardSlash(boolean allowForwardSlash) { | |
| 200 | 0 | this.allowForwardSlash = allowForwardSlash; |
| 201 | 0 | } |
| 202 | /** | |
| 203 | * @return the lowerCase | |
| 204 | */ | |
| 205 | public boolean isLowerCase() { | |
| 206 | 0 | return this.lowerCase; |
| 207 | } | |
| 208 | /** | |
| 209 | * @param lowerCase the lowerCase to set | |
| 210 | */ | |
| 211 | public void setLowerCase(boolean lowerCase) { | |
| 212 | 0 | this.lowerCase = lowerCase; |
| 213 | 0 | } |
| 214 | ||
| 215 | ||
| 216 | ||
| 217 | } |