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  import org.kuali.rice.krad.util.KRADConstants;
21  
22  /**
23   * Pattern for matching any UTF-8 character with whitespace option
24   * 
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   *
27   * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.UTF8AnyCharacterPatternConstraint}.
28   */
29  @Deprecated
30  public class UTF8AnyCharacterValidationPattern extends CharacterLevelValidationPattern{
31  	
32      protected boolean allowWhitespace = false;
33  
34  
35      /**
36       * @return allowWhitespace
37       */
38      public boolean getAllowWhitespace() {
39          return allowWhitespace;
40      }
41  
42      /**
43       * @param allowWhitespace
44       */
45      public void setAllowWhitespace(boolean allowWhitespace) {
46          this.allowWhitespace = allowWhitespace;
47      }
48  
49  	/**
50  	 * This overridden method ...
51  	 * 
52       * @see org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.rice.krad.datadictionary.exporter.ExportMap)
53  	 */
54  	@Override
55  	protected String getRegexString() {
56  		StringBuffer regexString = new StringBuffer("[");
57  		
58  		if(!allowWhitespace) {
59          regexString.append("[\\u0000-\\uFFFF&&[^\\p{Space}]]");
60          } else {
61              regexString.append("\\u0000-\\uFFFF");
62  		}
63  		
64  		regexString.append("]");
65  		return regexString.toString();
66  	}
67  	
68  	/**
69  	 * This overridden method ...
70  	 * 
71       * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
72  	 */
73  	@Override
74  	public void extendExportMap(ExportMap exportMap) {
75          exportMap.set("type", "broaderAnyCharacter");
76  
77          if (allowWhitespace) {
78              exportMap.set("allowWhitespace", "true");
79          }
80  	}
81  
82  
83  	
84  	@Override
85  	protected String getValidationErrorMessageKeyOptions() {
86  		if (getAllowWhitespace()) {
87  			return ".allowWhitespace";
88  		}
89  		return KRADConstants.EMPTY_STRING;
90  	}
91  
92  }