001/** 002 * Copyright 2005-2016 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; 020import org.kuali.rice.krad.util.KRADConstants; 021 022/** 023 * Pattern for matching any UTF-8 character with whitespace option 024 * 025 * @author Kuali Rice Team (rice.collab@kuali.org) 026 * 027 * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.UTF8AnyCharacterPatternConstraint}. 028 */ 029@Deprecated 030public class UTF8AnyCharacterValidationPattern extends CharacterLevelValidationPattern{ 031 032 protected boolean allowWhitespace = false; 033 034 035 /** 036 * @return allowWhitespace 037 */ 038 public boolean getAllowWhitespace() { 039 return allowWhitespace; 040 } 041 042 /** 043 * @param allowWhitespace 044 */ 045 public void setAllowWhitespace(boolean allowWhitespace) { 046 this.allowWhitespace = allowWhitespace; 047 } 048 049 /** 050 * This overridden method ... 051 * 052 * @see org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.rice.krad.datadictionary.exporter.ExportMap) 053 */ 054 @Override 055 protected String getRegexString() { 056 StringBuffer regexString = new StringBuffer("["); 057 058 if(!allowWhitespace) { 059 regexString.append("[\\u0000-\\uFFFF&&[^\\p{Space}]]"); 060 } else { 061 regexString.append("\\u0000-\\uFFFF"); 062 } 063 064 regexString.append("]"); 065 return regexString.toString(); 066 } 067 068 /** 069 * This overridden method ... 070 * 071 * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString() 072 */ 073 @Override 074 public void extendExportMap(ExportMap exportMap) { 075 exportMap.set("type", "broaderAnyCharacter"); 076 077 if (allowWhitespace) { 078 exportMap.set("allowWhitespace", "true"); 079 } 080 } 081 082 083 084 @Override 085 protected String getValidationErrorMessageKeyOptions() { 086 if (getAllowWhitespace()) { 087 return ".allowWhitespace"; 088 } 089 return KRADConstants.EMPTY_STRING; 090 } 091 092}