| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AlphaPatternConstraint | 
  | 
  | 2.0;2 | 
| 1 |  /* | |
| 2 |   * Copyright 2005-2008 The Kuali Foundation | |
| 3 |   *  | |
| 4 |   * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 |   * you may not use this file except in compliance with the License. | |
| 6 |   * You may obtain a copy of the License at | |
| 7 |   *  | |
| 8 |   * http://www.opensource.org/licenses/ecl2.php | |
| 9 |   *  | |
| 10 |   * Unless required by applicable law or agreed to in writing, software | |
| 11 |   * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 |   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 |   * See the License for the specific language governing permissions and | |
| 14 |   * limitations under the License. | |
| 15 |   */ | |
| 16 |  package org.kuali.rice.kns.datadictionary.validation.constraint; | |
| 17 | ||
| 18 |  import org.apache.commons.lang.StringUtils; | |
| 19 | ||
| 20 | ||
| 21 |  /** | |
| 22 |   * Pattern for matching alpha characters | |
| 23 |   *  | |
| 24 |   *  | |
| 25 |   */ | |
| 26 | 0 |  public class AlphaPatternConstraint extends ValidCharactersPatternConstraint { | 
| 27 | 0 |      protected boolean allowWhitespace = false; | 
| 28 | ||
| 29 | ||
| 30 |      /** | |
| 31 |       * @return allowWhitespace | |
| 32 |       */ | |
| 33 | public boolean getAllowWhitespace() {  | |
| 34 | 0 |          return allowWhitespace; | 
| 35 | }  | |
| 36 | ||
| 37 |      /** | |
| 38 |       * @param allowWhitespace | |
| 39 |       */ | |
| 40 | public void setAllowWhitespace(boolean allowWhitespace) {  | |
| 41 | 0 |          this.allowWhitespace = allowWhitespace; | 
| 42 | 0 |      } | 
| 43 | ||
| 44 | ||
| 45 |      /** | |
| 46 |       * @see org.kuali.rice.kns.datadictionary.validation.ValidationPattern#getRegexString() | |
| 47 |       */ | |
| 48 |      protected String getRegexString() { | |
| 49 | 0 |          StringBuffer regexString = new StringBuffer("[A-Za-z"); | 
| 50 | ||
| 51 | 0 |          if (allowWhitespace) { | 
| 52 | 0 |              regexString.append("\\s"); | 
| 53 | }  | |
| 54 | 0 |          regexString.append("]"); | 
| 55 | ||
| 56 | 0 |          return regexString.toString(); | 
| 57 | }  | |
| 58 | ||
| 59 |          /** | |
| 60 |           *  | |
| 61 |           * @see org.kuali.rice.kns.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
| 62 |           */ | |
| 63 | @Override  | |
| 64 |          public String getLabelKey() { | |
| 65 | 0 |                  String labelKey = super.getLabelKey(); | 
| 66 | 0 |                  if (StringUtils.isNotEmpty(labelKey)) { | 
| 67 | 0 |                          return labelKey; | 
| 68 | }  | |
| 69 | 0 |                  StringBuilder key = new StringBuilder(""); | 
| 70 | 0 |                  key.append("alphaPattern,"); | 
| 71 | 0 |                  if (getAllowWhitespace()) { | 
| 72 | 0 |                          key.append("whitespace"); | 
| 73 | }  | |
| 74 | 0 |                  return key.toString(); | 
| 75 | }  | |
| 76 | ||
| 77 |  //        @Override | |
| 78 |  //        protected String getValidationErrorMessageKeyOptions() { | |
| 79 |  //                if (getAllowWhitespace()) { | |
| 80 |  //                        return ".allowWhitespace"; | |
| 81 |  //                } | |
| 82 |  //                return KNSConstants.EMPTY_STRING; | |
| 83 |  //        } | |
| 84 | ||
| 85 | }  |