You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/05/10 17:18:26 UTC
svn commit: r536886 -
/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java
Author: ehillenius
Date: Thu May 10 08:18:25 2007
New Revision: 536886
URL: http://svn.apache.org/viewvc?view=rev&rev=536886
Log:
added accessors for validator parameters
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java?view=diff&rev=536886&r1=536885&r2=536886
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java Thu May 10 08:18:25 2007
@@ -34,110 +34,58 @@
{
/**
- * Gets a String range validator to check if a string length is between min
- * and max.
- *
- * If that is not the case then an error message will be generated with the
- * key "StringValidator.range" and the messages keys that can be used are:
- * <ul>
- * <li>${minimum}: the minimum length</li>
- * <li>${maximum}: the maximum length</li>
- * <li>${length}: the length of the user input</li>
- * <li>${input}: the input the user did give</li>
- * <li>${name}: the name of the component that failed</li>
- * <li>${label}: the label of the component - either comes from
- * FormComponent.labelModel or resource key [form-id].[form-component-id] in
- * that order</li>
- * </ul>
- *
- * @param minimum
- * The minimum length of the string.
- * @param maximum
- * The maximum length of the string.
- *
- * @return The StringValidator
+ * Validator to check if the length of the string is exactly the specified
+ * length
*/
- public static StringValidator lengthBetween(int minimum, int maximum)
+ public static class ExactLengthValidator extends StringValidator
{
- return new LengthBetweenValidator(minimum, maximum);
- }
+ private static final long serialVersionUID = 1L;
+ private final int length;
- /**
- * Gets a String minimum validator to check if a string length is greater
- * then the given minimum value.
- *
- * If that is not the case then an error message will be generated with the
- * key "StringValidator.minimum" and the messages keys that can be used are:
- * <ul>
- * <li>${minimum}: the minimum length</li>
- * <li>${length}: the length of the user input</li>
- * <li>${input}: the input the user did give</li>
- * <li>${name}: the name of the component that failed</li>
- * <li>${label}: the label of the component - either comes from
- * FormComponent.labelModel or resource key [form-id].[form-component-id] in
- * that order</li>
- * </ul>
- *
- * @param minimum
- * The minimum length of the string.
- *
- * @return The StringValidator
- */
- public static StringValidator minimumLength(int minimum)
- {
- return new MinimumLengthValidator(minimum);
- }
+ /**
+ * Construct.
+ *
+ * @param length
+ */
+ public ExactLengthValidator(int length)
+ {
+ this.length = length;
+ }
- /**
- * Gets a String maximum validator to check if a string length is smaller
- * then the given maximum value.
- *
- * If that is not the case then an error message will be generated with the
- * key "StringValidator.maximum" and the messages keys that can be used are:
- * <ul>
- * <li>${maximum}: the maximum length</li>
- * <li>${length}: the length of the user input</li>
- * <li>${input}: the input the user did give</li>
- * <li>${name}: the name of the component that failed</li>
- * <li>${label}: the label of the component - either comes from
- * FormComponent.labelModel or resource key [form-id].[form-component-id] in
- * that order</li>
- * </ul>
- *
- * @param maximum
- * The maximum length of the string.
- *
- * @return The StringValidator
- */
- public static StringValidator maximumLength(int maximum)
- {
- return new MaximumLengthValidator(maximum);
- }
+ /**
+ * Gets length.
+ *
+ * @return length
+ */
+ public final int getLength()
+ {
+ return length;
+ }
+
+ protected void onValidate(IValidatable validatable)
+ {
+ if (((String)validatable.getValue()).length() != length)
+ {
+ error(validatable);
+ }
+ }
+
+ /**
+ * @see org.apache.wicket.markup.html.form.validation.AbstractValidator#resourceKey(org.apache.wicket.markup.html.form.FormComponent)
+ */
+ protected String resourceKey()
+ {
+ return "StringValidator.exact";
+ }
+
+ protected Map variablesMap(IValidatable validatable)
+ {
+ final Map map = super.variablesMap(validatable);
+ map.put("length", new Integer(((String)validatable.getValue()).length()));
+ map.put("exact", new Integer(this.length));
+ return map;
+ }
- /**
- * Gets a String exact length validator to check if a string length is
- * exactly the same as the given value
- *
- * If that is not the case then an error message will be generated with the
- * key "StringValidator.exact" and the messages keys that can be used are:
- * <ul>
- * <li>${exact}: the maximum length</li>
- * <li>${length}: the length of the user input</li>
- * <li>${input}: the input the user did give</li>
- * <li>${name}: the name of the component that failed</li>
- * <li>${label}: the label of the component - either comes from
- * FormComponent.labelModel or resource key [form-id].[form-component-id] in
- * that order</li>
- * </ul>
- *
- * @param length
- * The required length of the string.
- *
- * @return The StringValidator
- */
- public static StringValidator exactLength(int length)
- {
- return new ExactLengthValidator(length);
}
/**
@@ -146,8 +94,8 @@
public static class LengthBetweenValidator extends StringValidator
{
private static final long serialVersionUID = 1L;
- private final int minimum;
private final int maximum;
+ private final int minimum;
/**
* Construct.
@@ -163,23 +111,23 @@
}
/**
- * @see org.apache.wicket.validation.validator.AbstractValidator#variablesMap(org.apache.wicket.validation.IValidatable)
+ * Gets maximum.
+ *
+ * @return maximum
*/
- protected Map variablesMap(IValidatable validatable)
+ public final int getMaximum()
{
- final Map map = super.variablesMap(validatable);
- map.put("minimum", new Integer(minimum));
- map.put("maximum", new Integer(maximum));
- map.put("length", new Integer(((String)validatable.getValue()).length()));
- return map;
+ return maximum;
}
/**
- * @see org.apache.wicket.markup.html.form.validation.AbstractValidator#resourceKey(org.apache.wicket.markup.html.form.FormComponent)
+ * Gets minimum.
+ *
+ * @return minimum
*/
- protected String resourceKey()
+ public final int getMinimum()
{
- return "StringValidator.range";
+ return minimum;
}
protected void onValidate(IValidatable validatable)
@@ -192,25 +140,12 @@
}
- }
-
- /**
- * Validator to check if the length of the string meets a minumum
- * requirement
- */
- public static class MinimumLengthValidator extends StringValidator
- {
- private static final long serialVersionUID = 1L;
- private final int minimum;
-
/**
- * Construct.
- *
- * @param minimum
+ * @see org.apache.wicket.markup.html.form.validation.AbstractValidator#resourceKey(org.apache.wicket.markup.html.form.FormComponent)
*/
- public MinimumLengthValidator(int minimum)
+ protected String resourceKey()
{
- this.minimum = minimum;
+ return "StringValidator.range";
}
/**
@@ -220,101 +155,105 @@
{
final Map map = super.variablesMap(validatable);
map.put("minimum", new Integer(minimum));
+ map.put("maximum", new Integer(maximum));
map.put("length", new Integer(((String)validatable.getValue()).length()));
return map;
}
- /**
- * @see org.apache.wicket.markup.html.form.validation.AbstractValidator#resourceKey(org.apache.wicket.markup.html.form.FormComponent)
- */
- protected String resourceKey()
- {
- return "StringValidator.minimum";
- }
-
- protected void onValidate(IValidatable validatable)
- {
- if (((String)validatable.getValue()).length() < minimum)
- {
- error(validatable);
- }
- }
-
}
/**
- * Validator to check if the length of the string is exactly the specified
- * length
+ * Validator to check if the length of the string meets a maximum
+ * requirement
*/
- public static class ExactLengthValidator extends StringValidator
+ public static class MaximumLengthValidator extends StringValidator
{
private static final long serialVersionUID = 1L;
- private final int length;
+ private final int maximum;
/**
* Construct.
*
- * @param length
+ * @param maximum
*/
- public ExactLengthValidator(int length)
- {
- this.length = length;
- }
-
- protected Map variablesMap(IValidatable validatable)
+ public MaximumLengthValidator(int maximum)
{
- final Map map = super.variablesMap(validatable);
- map.put("length", new Integer(((String)validatable.getValue()).length()));
- map.put("exact", new Integer(this.length));
- return map;
+ this.maximum = maximum;
}
/**
- * @see org.apache.wicket.markup.html.form.validation.AbstractValidator#resourceKey(org.apache.wicket.markup.html.form.FormComponent)
+ * Gets maximum.
+ *
+ * @return maximum
*/
- protected String resourceKey()
+ public final int getMaximum()
{
- return "StringValidator.exact";
+ return maximum;
}
protected void onValidate(IValidatable validatable)
{
- if (((String)validatable.getValue()).length() != length)
+ if (((String)validatable.getValue()).length() > maximum)
{
error(validatable);
}
}
+ /**
+ * @see org.apache.wicket.markup.html.form.validation.AbstractValidator#resourceKey(org.apache.wicket.markup.html.form.FormComponent)
+ */
+ protected String resourceKey()
+ {
+ return "StringValidator.maximum";
+ }
+
+ /**
+ * @see org.apache.wicket.validation.validator.AbstractValidator#variablesMap(org.apache.wicket.validation.IValidatable)
+ */
+ protected Map variablesMap(IValidatable validatable)
+ {
+ final Map map = super.variablesMap(validatable);
+ map.put("maximum", new Integer(maximum));
+ map.put("length", new Integer(((String)validatable.getValue()).length()));
+ return map;
+ }
}
/**
- * Validator to check if the length of the string meets a maximum
+ * Validator to check if the length of the string meets a minumum
* requirement
*/
- public static class MaximumLengthValidator extends StringValidator
+ public static class MinimumLengthValidator extends StringValidator
{
private static final long serialVersionUID = 1L;
- private final int maximum;
+ private final int minimum;
/**
* Construct.
*
- * @param maximum
+ * @param minimum
*/
- public MaximumLengthValidator(int maximum)
+ public MinimumLengthValidator(int minimum)
{
- this.maximum = maximum;
+ this.minimum = minimum;
}
/**
- * @see org.apache.wicket.validation.validator.AbstractValidator#variablesMap(org.apache.wicket.validation.IValidatable)
+ * Gets minimum.
+ *
+ * @return minimum
*/
- protected Map variablesMap(IValidatable validatable)
+ public final int getMinimum()
{
- final Map map = super.variablesMap(validatable);
- map.put("maximum", new Integer(maximum));
- map.put("length", new Integer(((String)validatable.getValue()).length()));
- return map;
+ return minimum;
+ }
+
+ protected void onValidate(IValidatable validatable)
+ {
+ if (((String)validatable.getValue()).length() < minimum)
+ {
+ error(validatable);
+ }
}
/**
@@ -322,15 +261,126 @@
*/
protected String resourceKey()
{
- return "StringValidator.maximum";
+ return "StringValidator.minimum";
}
- protected void onValidate(IValidatable validatable)
+ /**
+ * @see org.apache.wicket.validation.validator.AbstractValidator#variablesMap(org.apache.wicket.validation.IValidatable)
+ */
+ protected Map variablesMap(IValidatable validatable)
{
- if (((String)validatable.getValue()).length() > maximum)
- {
- error(validatable);
- }
+ final Map map = super.variablesMap(validatable);
+ map.put("minimum", new Integer(minimum));
+ map.put("length", new Integer(((String)validatable.getValue()).length()));
+ return map;
}
+
+ }
+
+ /**
+ * Gets a String exact length validator to check if a string length is
+ * exactly the same as the given value
+ *
+ * If that is not the case then an error message will be generated with the
+ * key "StringValidator.exact" and the messages keys that can be used are:
+ * <ul>
+ * <li>${exact}: the maximum length</li>
+ * <li>${length}: the length of the user input</li>
+ * <li>${input}: the input the user did give</li>
+ * <li>${name}: the name of the component that failed</li>
+ * <li>${label}: the label of the component - either comes from
+ * FormComponent.labelModel or resource key [form-id].[form-component-id] in
+ * that order</li>
+ * </ul>
+ *
+ * @param length
+ * The required length of the string.
+ *
+ * @return The StringValidator
+ */
+ public static StringValidator exactLength(int length)
+ {
+ return new ExactLengthValidator(length);
+ }
+
+ /**
+ * Gets a String range validator to check if a string length is between min
+ * and max.
+ *
+ * If that is not the case then an error message will be generated with the
+ * key "StringValidator.range" and the messages keys that can be used are:
+ * <ul>
+ * <li>${minimum}: the minimum length</li>
+ * <li>${maximum}: the maximum length</li>
+ * <li>${length}: the length of the user input</li>
+ * <li>${input}: the input the user did give</li>
+ * <li>${name}: the name of the component that failed</li>
+ * <li>${label}: the label of the component - either comes from
+ * FormComponent.labelModel or resource key [form-id].[form-component-id] in
+ * that order</li>
+ * </ul>
+ *
+ * @param minimum
+ * The minimum length of the string.
+ * @param maximum
+ * The maximum length of the string.
+ *
+ * @return The StringValidator
+ */
+ public static StringValidator lengthBetween(int minimum, int maximum)
+ {
+ return new LengthBetweenValidator(minimum, maximum);
+ }
+
+ /**
+ * Gets a String maximum validator to check if a string length is smaller
+ * then the given maximum value.
+ *
+ * If that is not the case then an error message will be generated with the
+ * key "StringValidator.maximum" and the messages keys that can be used are:
+ * <ul>
+ * <li>${maximum}: the maximum length</li>
+ * <li>${length}: the length of the user input</li>
+ * <li>${input}: the input the user did give</li>
+ * <li>${name}: the name of the component that failed</li>
+ * <li>${label}: the label of the component - either comes from
+ * FormComponent.labelModel or resource key [form-id].[form-component-id] in
+ * that order</li>
+ * </ul>
+ *
+ * @param maximum
+ * The maximum length of the string.
+ *
+ * @return The StringValidator
+ */
+ public static StringValidator maximumLength(int maximum)
+ {
+ return new MaximumLengthValidator(maximum);
+ }
+
+ /**
+ * Gets a String minimum validator to check if a string length is greater
+ * then the given minimum value.
+ *
+ * If that is not the case then an error message will be generated with the
+ * key "StringValidator.minimum" and the messages keys that can be used are:
+ * <ul>
+ * <li>${minimum}: the minimum length</li>
+ * <li>${length}: the length of the user input</li>
+ * <li>${input}: the input the user did give</li>
+ * <li>${name}: the name of the component that failed</li>
+ * <li>${label}: the label of the component - either comes from
+ * FormComponent.labelModel or resource key [form-id].[form-component-id] in
+ * that order</li>
+ * </ul>
+ *
+ * @param minimum
+ * The minimum length of the string.
+ *
+ * @return The StringValidator
+ */
+ public static StringValidator minimumLength(int minimum)
+ {
+ return new MinimumLengthValidator(minimum);
}
}