View Javadoc

1   package org.apache.turbine.services.intake.validator;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Map;
23  
24  /***
25   * Validates numbers with the following constraints in addition to those
26   * listed in DefaultValidator.
27   *
28   * <table>
29   * <tr><th>Name</th><th>Valid Values</th><th>Default Value</th></tr>
30   * <tr><td>minValue</td><td>greater than BigDecimal.MIN_VALUE</td>
31   * <td>&nbsp;</td></tr>
32   * <tr><td>maxValue</td><td>less than BigDecimal.MAX_VALUE</td>
33   * <td>&nbsp;</td></tr>
34   * <tr><td>notANumberMessage</td><td>Some text</td>
35   * <td>Entry was not a valid number</td></tr>
36   * </table>
37   *
38   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
39   * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
40   * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
41   * @version $Id: NumberValidator.java 534527 2007-05-02 16:10:59Z tv $
42   */
43  abstract class NumberValidator
44          extends DefaultValidator
45  {
46      /*** The message to show if field fails min-value test */
47      String minValueMessage = null;
48  
49      /*** The message to show if field fails max-value test */
50      String maxValueMessage = null;
51  
52      /*** The message to use for invalid numbers */
53      String invalidNumberMessage = null;
54  
55      /***
56       * Extract the relevant parameters from the constraints listed
57       * in <rule> tags within the intake.xml file.
58       *
59       * @param paramMap a <code>Map</code> of <code>rule</code>'s
60       * containing constraints on the input.
61       * @exception InvalidMaskException an invalid mask was specified
62       */
63      public void init(Map paramMap)
64              throws InvalidMaskException
65      {
66          super.init(paramMap);
67  
68          Constraint constraint =
69                  (Constraint) paramMap.get(INVALID_NUMBER_RULE_NAME);
70  
71          if (constraint != null)
72          {
73              invalidNumberMessage = constraint.getMessage();
74          }
75      }
76  
77      // ************************************************************
78      // **                Bean accessor methods                   **
79      // ************************************************************
80  
81      /***
82       * Get the value of minValueMessage.
83       *
84       * @return value of minValueMessage.
85       */
86      public String getMinValueMessage()
87      {
88          return minValueMessage;
89      }
90  
91      /***
92       * Set the value of minValueMessage.
93       *
94       * @param minValueMessage  Value to assign to minValueMessage.
95       */
96      public void setMinValueMessage(String minValueMessage)
97      {
98          this.minValueMessage = minValueMessage;
99      }
100 
101     /***
102      * Get the value of maxValueMessage.
103      *
104      * @return value of maxValueMessage.
105      */
106     public String getMaxValueMessage()
107     {
108         return maxValueMessage;
109     }
110 
111     /***
112      * Set the value of maxValueMessage.
113      *
114      * @param maxValueMessage  Value to assign to maxValueMessage.
115      */
116     public void setMaxValueMessage(String maxValueMessage)
117     {
118         this.maxValueMessage = maxValueMessage;
119     }
120 
121     /***
122      * Get the value of invalidNumberMessage.
123      *
124      * @return value of invalidNumberMessage.
125      */
126     public String getInvalidNumberMessage()
127     {
128         return invalidNumberMessage;
129     }
130 
131     /***
132      *
133      * Set the value of invalidNumberMessage.
134      * @param invalidNumberMessage  Value to assign to invalidNumberMessage.
135      */
136     public void setInvalidNumberMessage(String invalidNumberMessage)
137     {
138         this.invalidNumberMessage = invalidNumberMessage;
139     }
140 
141 }