001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.core.datadictionary.validation.charlevel;
017:
018: import org.kuali.core.datadictionary.exporter.ExportMap;
019: import org.kuali.core.datadictionary.validation.CharacterLevelValidationPattern;
020:
021: /**
022: * Pattern for matching alphanumeric characters
023: *
024: *
025: */
026: public class AlphaNumericValidationPattern extends
027: CharacterLevelValidationPattern {
028: private boolean allowWhitespace = false;
029: private boolean allowUnderscore = false;
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: * @return allowUnderscore
047: */
048: public boolean getAllowUnderscore() {
049: return allowUnderscore;
050: }
051:
052: /**
053: * @param allowWhitespace
054: */
055: public void setAllowUnderscore(boolean allowUnderscore) {
056: this .allowUnderscore = allowUnderscore;
057: }
058:
059: /**
060: * @see org.kuali.core.datadictionary.validation.ValidationPattern#getRegexString()
061: */
062: protected String getRegexString() {
063: StringBuffer regexString = new StringBuffer("[A-Za-z0-9");
064:
065: if (allowWhitespace) {
066: regexString.append("\\s");
067: }
068: if (allowUnderscore) {
069: regexString.append("_");
070: }
071: regexString.append("]");
072:
073: return regexString.toString();
074: }
075:
076: /**
077: * @see org.kuali.core.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.bo.datadictionary.exporter.ExportMap)
078: */
079: public void extendExportMap(ExportMap exportMap) {
080: exportMap.set("type", "alphaNumeric");
081:
082: if (allowWhitespace) {
083: exportMap.set("allowWhitespace", "true");
084: }
085: if (allowUnderscore) {
086: exportMap.set("allowUnderscore", "true");
087: }
088: }
089:
090: /**
091: * @see org.kuali.core.datadictionary.validation.ValidationPattern#getPatternXml()
092: */
093: public String getPatternXml() {
094: StringBuffer xml = new StringBuffer("<alphaNumeric ");
095: if (allowWhitespace) {
096: xml.append("allowWhitespace=\"true\" ");
097: }
098: if (allowUnderscore) {
099: xml.append("allowUnderscore=\"true\" ");
100: }
101: xml.append("/>");
102:
103: return xml.toString();
104: }
105: }
|