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.krad.datadictionary.validation.constraint;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
020 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
021 import org.kuali.rice.krad.uif.UifConstants;
022
023 /**
024 * Pattern for matching any printable character
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028 @BeanTag(name = "utf8AnyCharacterPatternConstraint-bean", parent = "UTF8AnyCharacterPatternConstraint")
029 public class UTF8AnyCharacterPatternConstraint extends ValidCharactersPatternConstraint {
030 protected boolean allowWhitespace = false;
031 protected boolean omitNewline = false;
032
033 /**
034 * @return allowWhitespace
035 */
036 @BeanTagAttribute(name = "allowWhitespace")
037 public boolean getAllowWhitespace() {
038 return allowWhitespace;
039 }
040
041 /**
042 * @param allowWhitespace
043 */
044 public void setAllowWhitespace(boolean allowWhitespace) {
045 this.allowWhitespace = allowWhitespace;
046 }
047
048 /**
049 * {@inheritDoc}
050 */
051 @Override
052 protected String getRegexString() {
053 StringBuffer regexString = new StringBuffer("[");
054
055 regexString.append("\\u0000-\\uFFFF");
056 if (allowWhitespace) {
057 regexString.append("\\t\\v\\040");
058 if (!omitNewline) {
059 regexString.append("\\f\\r\\n");
060 }
061 }
062
063 regexString.append("]");
064
065 return regexString.toString();
066 }
067
068 /**
069 * @see BaseConstraint#getMessageKey()
070 */
071 @Override
072 public String getMessageKey() {
073 String messageKey = super.getMessageKey();
074 if (StringUtils.isNotEmpty(messageKey)) {
075 return messageKey;
076 }
077
078 if (!allowWhitespace) {
079 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "noWhitespace";
080 } else {
081 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "utf8AnyCharacterPattern";
082 }
083 }
084
085 @BeanTagAttribute(name = "omitNewline")
086 public boolean isOmitNewline() {
087 return omitNewline;
088 }
089
090 /**
091 * When set to true, omit new line characters from the set of valid characters. This flag
092 * will only have an effect if the allowWhitespace flag is true, otherwise all whitespace
093 * including new lines characters are omitted.
094 *
095 * @param omitNewline
096 */
097 public void setOmitNewline(boolean omitNewline) {
098 this.omitNewline = omitNewline;
099 }
100 }