001 /**
002 * Copyright 2005-2014 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 */
016 package org.kuali.rice.kns.datadictionary.validation.charlevel;
017
018 import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
019 import org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern;
020 import org.kuali.rice.krad.util.KRADConstants;
021
022 /**
023 * Pattern for matching any printable character
024 *
025 *
026 */
027 public class AnyCharacterValidationPattern extends CharacterLevelValidationPattern {
028 protected boolean allowWhitespace = false;
029
030
031 /**
032 * @return allowWhitespace
033 */
034 public boolean getAllowWhitespace() {
035 return allowWhitespace;
036 }
037
038 /**
039 * @param allowWhitespace
040 */
041 public void setAllowWhitespace(boolean allowWhitespace) {
042 this.allowWhitespace = allowWhitespace;
043 }
044
045
046 /**
047 * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
048 */
049 protected String getRegexString() {
050 StringBuffer regexString = new StringBuffer("[");
051
052
053 regexString.append("\\p{Graph}");
054 if (allowWhitespace) {
055 regexString.append("\\p{Space}");
056 }
057 regexString.append("]");
058
059 return regexString.toString();
060 }
061
062
063 /**
064 * @see org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.rice.krad.datadictionary.exporter.ExportMap)
065 */
066 public void extendExportMap(ExportMap exportMap) {
067 exportMap.set("type", "anyCharacter");
068
069 if (allowWhitespace) {
070 exportMap.set("allowWhitespace", "true");
071 }
072 }
073
074 @Override
075 protected String getValidationErrorMessageKeyOptions() {
076 if (getAllowWhitespace()) {
077 return ".allowWhitespace";
078 }
079 return KRADConstants.EMPTY_STRING;
080 }
081 }