Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AlphaPatternConstraint |
|
| 2.3333333333333335;2.333 |
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.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 alpha characters | |
24 | * | |
25 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
26 | */ | |
27 | 10 | public class AlphaPatternConstraint extends AllowCharacterConstraint { |
28 | 10 | protected boolean lowerCase = false; |
29 | 10 | protected boolean upperCase = false; |
30 | ||
31 | /** | |
32 | * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString() | |
33 | */ | |
34 | protected String getRegexString() { | |
35 | 5 | StringBuilder regexString = new StringBuilder("[A-Za-z"); |
36 | /* | |
37 | * This check must be first because we are removing the base 'A-Z' if lowerCase == true | |
38 | */ | |
39 | 5 | if (lowerCase) { |
40 | 0 | regexString = new StringBuilder("[a-z"); |
41 | } | |
42 | 5 | else if(upperCase){ |
43 | 0 | regexString = new StringBuilder("[A-Z"); |
44 | } | |
45 | 5 | regexString.append(this.getAllowedCharacterRegex()); |
46 | 5 | regexString.append("]"); |
47 | ||
48 | 5 | return regexString.toString(); |
49 | } | |
50 | ||
51 | /** | |
52 | * A label key is auto generated for this bean if none is set. This generated message can be | |
53 | * overridden through setLabelKey, but the generated message should cover most cases. | |
54 | * | |
55 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
56 | */ | |
57 | @Override | |
58 | public String getLabelKey() { | |
59 | 6 | if (StringUtils.isEmpty(labelKey)) { |
60 | 6 | StringBuilder key = new StringBuilder(""); |
61 | 6 | if (lowerCase) { |
62 | 0 | return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPatternLowerCase"); |
63 | 6 | } else if(upperCase){ |
64 | 0 | return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPatternUpperCase"); |
65 | } | |
66 | else{ | |
67 | 6 | return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPattern"); |
68 | } | |
69 | } | |
70 | 0 | return labelKey; |
71 | } | |
72 | ||
73 | /** | |
74 | * @return the lowerCase | |
75 | */ | |
76 | public boolean isLowerCase() { | |
77 | 0 | return this.lowerCase; |
78 | } | |
79 | ||
80 | /** | |
81 | * Only allow lowerCase characters. DO NOT use with upperCase option, no flags set for case | |
82 | * means both upper and lower case are allowed. | |
83 | * @param lowerCase the lowerCase to set | |
84 | */ | |
85 | public void setLowerCase(boolean lowerCase) { | |
86 | 0 | this.lowerCase = lowerCase; |
87 | 0 | } |
88 | ||
89 | public boolean isUpperCase() { | |
90 | 0 | return upperCase; |
91 | } | |
92 | ||
93 | /** | |
94 | * Only allow upperCase characters. DO NOT use with lowerCase option, no flags set for case | |
95 | * means both upper and lower case are allowed. | |
96 | * @param lowerCase the lowerCase to set | |
97 | */ | |
98 | public void setUpperCase(boolean upperCase) { | |
99 | 0 | this.upperCase = upperCase; |
100 | 0 | } |
101 | ||
102 | } |