001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.datadictionary.validation.charlevel;
017
018import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
019import org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern;
020
021/**
022 * Pattern for matching alphanumeric characters
023 * 
024 * Also, allows conditionally whitespace, underscore, period, parens, dollar signs, and forward slash.
025 *
026 * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.AlphaNumericPatternConstraint}.
027 */
028@Deprecated
029public class AlphaNumericValidationPattern extends CharacterLevelValidationPattern {
030    protected boolean allowWhitespace = false;
031    protected boolean allowUnderscore = false;
032    protected boolean allowPeriod = false;
033
034    protected boolean allowParenthesis = false;
035    protected boolean allowDollar = false;
036    protected boolean allowForwardSlash = false;
037    protected boolean lowerCase = false;
038    protected boolean allowDash = false;
039    
040    /**
041     * @return allowPeriod
042     */
043    public boolean getAllowPeriod() {
044        return allowPeriod;
045    }
046
047    /**
048     * @param allowPeriod
049     */
050    public void setAllowPeriod(boolean allowPeriod) {
051        this.allowPeriod = allowPeriod;
052    }    
053    
054    /**
055         * @return the allowPeriod
056         */
057        public boolean isAllowPeriod() {
058                return allowPeriod;
059        }
060    
061    /**
062         * @return the allowParenthesis
063         */
064        public boolean isAllowParenthesis() {
065                return allowParenthesis;
066        }
067
068        /**
069         * @param allowParenthesis the allowParenthesis to set
070         */
071        public void setAllowParenthesis(boolean allowParenthesis) {
072                this.allowParenthesis = allowParenthesis;
073        }
074        
075        /**
076         * @return the allowDollar
077         */
078        public boolean isAllowDollar() {
079                return allowDollar;
080        }
081
082        /**
083         * @param allowDollar the allowDollar to set
084         */
085        public void setAllowDollar(boolean allowDollar) {
086                this.allowDollar = allowDollar;
087        }
088
089        /**
090         * @return the allowforwardSlash
091         */
092        public boolean isAllowForwardSlash() {
093                return allowForwardSlash;
094        }
095
096        /**
097         * @param allowForwardSlash the allowforwardSlash to set
098         */
099        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}