1 15 package org.apache.tapestry.valid; 16 17 import org.apache.tapestry.form.IFormComponent; 18 19 25 public abstract class AbstractNumericValidator extends BaseValidator 26 { 27 private boolean _zeroIsNull; 28 29 public AbstractNumericValidator() 30 { 31 super(); 32 } 33 34 public AbstractNumericValidator(String initializer) 35 { 36 super(initializer); 37 } 38 39 public AbstractNumericValidator(boolean required) 40 { 41 super(required); 42 } 43 44 48 49 public boolean getZeroIsNull() 50 { 51 return _zeroIsNull; 52 } 53 54 public void setZeroIsNull(boolean zeroIsNull) 55 { 56 _zeroIsNull = zeroIsNull; 57 } 58 59 private String _scriptPath = 60 getDefaultScriptPath(); 61 62 63 private String _invalidNumericFormatMessage; 64 65 private String _invalidIntegerFormatMessage; 66 67 private String _numberTooSmallMessage; 68 69 private String _numberTooLargeMessage; 70 71 private String _numberRangeMessage; 72 73 76 public String getScriptPath() 77 { 78 return _scriptPath; 79 } 80 81 89 public void setScriptPath(String scriptPath) 90 { 91 _scriptPath = scriptPath; 92 } 93 94 95 public String getInvalidNumericFormatMessage() 96 { 97 return _invalidNumericFormatMessage; 98 } 99 100 101 public String getInvalidIntegerFormatMessage() 102 { 103 return _invalidIntegerFormatMessage; 104 } 105 106 107 public String getNumberRangeMessage() 108 { 109 return _numberRangeMessage; 110 } 111 112 113 public String getNumberTooLargeMessage() 114 { 115 return _numberTooLargeMessage; 116 } 117 118 119 public String getNumberTooSmallMessage() 120 { 121 return _numberTooSmallMessage; 122 } 123 124 130 public void setInvalidNumericFormatMessage(String string) 131 { 132 _invalidNumericFormatMessage = string; 133 } 134 135 141 public void setInvalidIntegerFormatMessage(String string) 142 { 143 _invalidIntegerFormatMessage = string; 144 } 145 146 152 public void setNumberRangeMessage(String string) 153 { 154 _numberRangeMessage = string; 155 } 156 157 163 public void setNumberTooLargeMessage(String string) 164 { 165 _numberTooLargeMessage = string; 166 } 167 168 174 public void setNumberTooSmallMessage(String string) 175 { 176 _numberTooSmallMessage = string; 177 } 178 179 180 protected String buildInvalidNumericFormatMessage(IFormComponent field) 181 { 182 String pattern = getPattern( 183 getInvalidNumericFormatMessage(), 184 "invalid-numeric-format", 185 field.getPage().getLocale()); 186 187 return formatString(pattern, field.getDisplayName()); 188 } 189 190 protected String buildNumberTooSmallMessage(IFormComponent field, Number minimum) 191 { 192 String pattern = getPattern(getNumberTooSmallMessage(), "number-too-small", field.getPage() 193 .getLocale()); 194 195 return formatString(pattern, field.getDisplayName(), minimum); 196 } 197 198 199 protected String buildInvalidIntegerFormatMessage(IFormComponent field) 200 { 201 String pattern = getPattern(getInvalidIntegerFormatMessage(), "invalid-int-format", field 202 .getPage().getLocale()); 203 204 return formatString(pattern, field.getDisplayName()); 205 } 206 207 210 protected String buildNumberTooLargeMessage(IFormComponent field, Number maximum) 211 { 212 String pattern = getPattern(getNumberTooLargeMessage(), "number-too-large", field.getPage() 213 .getLocale()); 214 215 return formatString(pattern, field.getDisplayName(), maximum); 216 } 217 218 protected String buildNumberRangeMessage(IFormComponent field, Number mininum, Number maximum) 219 { 220 String pattern = getPattern(getNumberRangeMessage(), "number-range", field.getPage() 221 .getLocale()); 222 223 return formatString(pattern, new Object [] 224 { field.getDisplayName(), mininum, maximum }); 225 } 226 227 protected String buildRangeMessage(IFormComponent field, Number minimum, Number maximum) 228 { 229 if (minimum != null && maximum != null) 230 return buildNumberRangeMessage(field, minimum, maximum); 231 232 if (maximum != null) 233 return buildNumberTooLargeMessage(field, maximum); 234 235 return buildNumberTooSmallMessage(field, minimum); 236 } 237 238 protected abstract String getDefaultScriptPath(); 239 } | Popular Tags |