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