View Javadoc

1   /**
2    * Copyright 2005-2013 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.krad.datadictionary.validation.constraint;
17  
18  import org.kuali.rice.core.api.config.property.ConfigurationService;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  import org.kuali.rice.krad.service.KRADServiceLocator;
22  import org.kuali.rice.krad.uif.UifConstants;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * Validation pattern for matching floating point numbers, optionally matching negative numbers
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @BeanTag(name = "floatingPointPatternConstraint-bean", parent = "FloatingPointPatternConstraint")
33  public class FloatingPointPatternConstraint extends ConfigurationBasedRegexPatternConstraint {
34  
35      protected boolean allowNegative;
36  
37      /**
38       * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString()
39       */
40      @Override
41      protected String getRegexString() {
42          StringBuffer regex = new StringBuffer();
43  
44          if (isAllowNegative()) {
45              regex.append("-?");
46          }
47          regex.append(super.getRegexString());
48  
49          return regex.toString();
50      }
51  
52      /**
53       * @return the allowNegative
54       */
55      @BeanTagAttribute(name = "allowNegative")
56      public boolean isAllowNegative() {
57          return this.allowNegative;
58      }
59  
60      /**
61       * @param allowNegative the allowNegative to set
62       */
63      public void setAllowNegative(boolean allowNegative) {
64          this.allowNegative = allowNegative;
65      }
66  
67      /**
68       * This overridden method ...
69       *
70       * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidDataPatternConstraint#getValidationMessageParams()
71       */
72      @Override
73      public List<String> getValidationMessageParams() {
74          if (validationMessageParams == null) {
75              validationMessageParams = new ArrayList<String>();
76              ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
77              if (allowNegative) {
78                  validationMessageParams.add(configService.getPropertyValueAsString(
79                          UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrNegative"));
80              } else {
81                  validationMessageParams.add(configService.getPropertyValueAsString(
82                          UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
83              }
84          }
85          return validationMessageParams;
86      }
87  }