View Javadoc
1   /**
2    * Copyright 2005-2015 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  
21  /**
22   * Pattern for matching alphanumeric characters
23   * 
24   * Also, allows conditionally whitespace, underscore, period, parens, dollar signs, and forward slash.
25   *
26   * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.AlphaNumericPatternConstraint}.
27   */
28  @Deprecated
29  public class AlphaNumericValidationPattern extends CharacterLevelValidationPattern {
30      protected boolean allowWhitespace = false;
31      protected boolean allowUnderscore = false;
32      protected boolean allowPeriod = false;
33  
34      protected boolean allowParenthesis = false;
35      protected boolean allowDollar = false;
36      protected boolean allowForwardSlash = false;
37      protected boolean lowerCase = false;
38      protected boolean allowDash = false;
39      
40      /**
41       * @return allowPeriod
42       */
43      public boolean getAllowPeriod() {
44          return allowPeriod;
45      }
46  
47      /**
48       * @param allowPeriod
49       */
50      public void setAllowPeriod(boolean allowPeriod) {
51          this.allowPeriod = allowPeriod;
52      }    
53      
54      /**
55  	 * @return the allowPeriod
56  	 */
57  	public boolean isAllowPeriod() {
58  		return allowPeriod;
59  	}
60      
61      /**
62  	 * @return the allowParenthesis
63  	 */
64  	public boolean isAllowParenthesis() {
65  		return allowParenthesis;
66  	}
67  
68  	/**
69  	 * @param allowParenthesis the allowParenthesis to set
70  	 */
71  	public void setAllowParenthesis(boolean allowParenthesis) {
72  		this.allowParenthesis = allowParenthesis;
73  	}
74  	
75  	/**
76  	 * @return the allowDollar
77  	 */
78  	public boolean isAllowDollar() {
79  		return allowDollar;
80  	}
81  
82  	/**
83  	 * @param allowDollar the allowDollar to set
84  	 */
85  	public void setAllowDollar(boolean allowDollar) {
86  		this.allowDollar = allowDollar;
87  	}
88  
89  	/**
90  	 * @return the allowforwardSlash
91  	 */
92  	public boolean isAllowForwardSlash() {
93  		return allowForwardSlash;
94  	}
95  
96  	/**
97  	 * @param allowForwardSlash the allowforwardSlash to set
98  	 */
99  	public void setAllowForwardSlash(boolean allowForwardSlash) {
100 		this.allowForwardSlash = allowForwardSlash;
101 	}
102     
103     /**
104      * @return allowWhitespace
105      */
106     public boolean getAllowWhitespace() {
107         return allowWhitespace;
108     }
109 
110     /**
111      * @param allowWhitespace
112      */
113     public void setAllowWhitespace(boolean allowWhitespace) {
114         this.allowWhitespace = allowWhitespace;
115     }
116 
117 
118     /**
119      * @return allowUnderscore
120      */
121     public boolean getAllowUnderscore() {
122         return allowUnderscore;
123     }
124 
125     /**
126      * @param allowUnderscore
127      */
128     public void setAllowUnderscore(boolean allowUnderscore) {
129         this.allowUnderscore = allowUnderscore;
130     }
131    
132     /**
133 	 * @return the lowerCase
134 	 */
135 	public boolean isLowerCase() {
136 		return this.lowerCase;
137 	}
138 
139 	/**
140 	 * @param lowerCase the lowerCase to set
141 	 */
142 	public void setLowerCase(boolean lowerCase) {
143 		this.lowerCase = lowerCase;
144 	}
145 
146     /**
147      * @return allowDash
148      */
149     public boolean getAllowDash() {
150         return allowDash;
151     }
152 
153     /**
154      * @param allowDash
155      */
156     public void setAllowDash(boolean allowDash) {
157         this.allowDash = allowDash;
158     }
159 
160     /**
161      * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
162      */
163     protected String getRegexString() {
164     	StringBuilder regexString = new StringBuilder("[A-Za-z0-9");
165     	
166     	/*
167     	 * This check must be first because we are removing the base 'A-Z' if lowerCase == true
168     	 */
169     	if(lowerCase){
170     		regexString = new StringBuilder("[a-z0-9");
171     	}
172 
173         if (allowWhitespace) {
174             regexString.append("\\s");
175         }
176         if (allowUnderscore) {
177             regexString.append("_");
178         }
179         if (allowPeriod) {
180             regexString.append(".");
181         }
182         if(allowParenthesis) {
183         	regexString.append("(");
184         	regexString.append(")");
185         }
186         if(allowDollar) {
187         	regexString.append("$");
188         }
189         if(allowForwardSlash) {
190         	regexString.append("/");
191         }
192         if (allowDash) {
193             regexString.append("-");
194         }
195         regexString.append("]");
196 
197         return regexString.toString();
198     }
199 
200 
201     /**
202      * @see org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.bo.datadictionary.exporter.ExportMap)
203      */
204     public void extendExportMap(ExportMap exportMap) {
205         exportMap.set("type", "alphaNumeric");
206 
207         if (lowerCase) {
208             exportMap.set("allowUpperCase", "true");
209         }
210         if (allowWhitespace) {
211             exportMap.set("allowWhitespace", "true");
212         }
213         if (allowUnderscore) {
214             exportMap.set("allowUnderscore", "true");
215         }
216         if (allowPeriod) {
217         	exportMap.set("allowPeriod", "true");
218         }
219         if(allowParenthesis) {
220             exportMap.set("allowParenthesis", "true");
221 
222         }
223         if(allowDollar) {
224             exportMap.set("allowDollar", "true");
225 
226         }
227         if(allowForwardSlash) {
228             exportMap.set("allowForwardSlash", "true");
229 
230         }
231         if (allowDash) {
232             exportMap.set("allowDash", "true");
233         }
234     }
235 
236 	@Override
237 	protected String getValidationErrorMessageKeyOptions() {
238 		final StringBuilder opts = new StringBuilder();
239 
240 		if (lowerCase) {
241 			opts.append(".lowerCase");
242 		}
243 		if (allowWhitespace) {
244 			opts.append(".allowWhitespace");
245 		}
246 		if (allowUnderscore) {
247 			opts.append(".allowUnderscore");
248 		}
249 		if (allowPeriod) {
250 			opts.append(".allowPeriod");
251 		}
252 		if(allowParenthesis) {
253 			opts.append(".allowParenthesis");
254 		}
255 		if(allowDollar) {
256 			opts.append(".allowDollar");
257 		}
258 		if(allowForwardSlash) {
259 			opts.append(".allowForwardSlash");
260 		}
261         if (allowDash) {
262             opts.append(".allowDash");
263 		}
264 
265 		return opts.toString();
266 	}
267 }