You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2008/09/03 08:02:01 UTC
svn commit: r691520 - in
/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation: ./
validator/
Author: ivaynberg
Date: Tue Sep 2 23:01:56 2008
New Revision: 691520
URL: http://svn.apache.org/viewvc?rev=691520&view=rev
Log:
more validator generification
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/CompoundValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/INullAcceptingValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidatable.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/Validatable.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/AbstractValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/CreditCardValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/DateValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/NumberValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/PatternValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/CompoundValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/CompoundValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/CompoundValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/CompoundValidator.java Tue Sep 2 23:01:56 2008
@@ -26,13 +26,15 @@
* checked, the rest of the validator chain is ignored.
*
* @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of validatable
* @since 1.2.6
*/
-public class CompoundValidator implements IValidator
+public class CompoundValidator<T> implements IValidator<T>
{
private static final long serialVersionUID = 1L;
- private final List<IValidator> validators = new ArrayList<IValidator>(2);
+ private final List<IValidator<T>> validators = new ArrayList<IValidator<T>>(2);
/**
* Constructor.
@@ -48,7 +50,7 @@
* an <code>IValidator</code> to be added
* @return this <code>ValidationError</code> for chaining purposes
*/
- public final CompoundValidator add(IValidator validator)
+ public final CompoundValidator<T> add(IValidator<T> validator)
{
if (validator == null)
{
@@ -61,9 +63,9 @@
/**
* @see IValidator#validate(IValidatable)
*/
- public final void validate(IValidatable validatable)
+ public final void validate(IValidatable<T> validatable)
{
- Iterator<IValidator> it = validators.iterator();
+ Iterator<IValidator<T>> it = validators.iterator();
while (it.hasNext() && validatable.isValid())
{
it.next().validate(validatable);
@@ -75,7 +77,7 @@
*
* @return unmodifiable list of delegate {@link IValidator}s inside this one
*/
- public final List<IValidator> getValidators()
+ public final List<IValidator<T>> getValidators()
{
return Collections.unmodifiableList(validators);
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/INullAcceptingValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/INullAcceptingValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/INullAcceptingValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/INullAcceptingValidator.java Tue Sep 2 23:01:56 2008
@@ -19,8 +19,8 @@
import org.apache.wicket.markup.html.form.FormComponent;
/**
- * Marker interface for validators that will accept a <code>null</code> value. Without
- * implementing this interface Wicket will never pass <code>null</code> values to
+ * Marker interface for validators that will accept a <code>null</code> value. Without implementing
+ * this interface Wicket will never pass <code>null</code> values to
* {@link IValidator#validate(IValidatable)}.
* <p>
* Keep in mind that the {@link FormComponent} must have set the required property to
@@ -28,11 +28,13 @@
* <code>null</code> value.
*
* @author Matej Knopp
+ * @param <T>
+ * type of validatable
* @since 1.2.6
* @see IValidator
* @see FormComponent#setRequired(boolean)
*/
-public interface INullAcceptingValidator extends IValidator
+public interface INullAcceptingValidator<T> extends IValidator<T>
{
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidatable.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidatable.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidatable.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidatable.java Tue Sep 2 23:01:56 2008
@@ -21,6 +21,8 @@
* Interface representing any object that can be validated.
*
* @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of value
* @since 1.2.6
*/
public interface IValidatable<T>
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/IValidator.java Tue Sep 2 23:01:56 2008
@@ -26,6 +26,8 @@
*
* @author Jonathan Locke
* @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of validatable value
* @since 1.2.6
*/
public interface IValidator<T> extends IClusterable
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/Validatable.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/Validatable.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/Validatable.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/Validatable.java Tue Sep 2 23:01:56 2008
@@ -48,12 +48,14 @@
* </pre></code>
*
* @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of validatable
* @since 1.2.6
*/
-public class Validatable implements IValidatable
+public class Validatable<T> implements IValidatable<T>
{
/** the value object */
- private Object value;
+ private T value;
/** the list of errors */
private ArrayList<IValidationError> errors;
@@ -71,7 +73,7 @@
* @param value
* The value that will be tested
*/
- public Validatable(Object value)
+ public Validatable(T value)
{
this.value = value;
}
@@ -82,7 +84,7 @@
* @param value
* the value object
*/
- public void setValue(Object value)
+ public void setValue(T value)
{
this.value = value;
}
@@ -90,7 +92,7 @@
/**
* @see IValidatable#getValue()
*/
- public Object getValue()
+ public T getValue()
{
return value;
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/AbstractValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/AbstractValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/AbstractValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/AbstractValidator.java Tue Sep 2 23:01:56 2008
@@ -34,28 +34,30 @@
* <p>
* Error messages can be registered by calling one of the error (<code>IValidatable</code>)
* overloads. By default this class will skip validation if the {@link IValidatable#getValue()}
- * returns <code>null</code>. Validators that wish to validate the <code>null</code> value need
- * to override {@link #validateOnNullValue()} and return <code>true</code>.
+ * returns <code>null</code>. Validators that wish to validate the <code>null</code> value need to
+ * override {@link #validateOnNullValue()} and return <code>true</code>.
*
*
* @author Jonathan Locke
* @author Eelco Hillenius
* @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of validatable
* @since 1.2.6
*/
-public abstract class AbstractValidator implements INullAcceptingValidator, IClusterable
+public abstract class AbstractValidator<T> implements INullAcceptingValidator<T>, IClusterable
{
private static final long serialVersionUID = 1L;
/**
* Indicates whether or not to validate the value if it is <code>null</code>. It is usually
- * desirable to skip validation if the value is <code>null</code>, unless we want to make
- * sure the value is in fact <code>null</code> (a rare use case). Validators that extend this
- * and wish to ensure the value is <code>null</code> should override this method and return
+ * desirable to skip validation if the value is <code>null</code>, unless we want to make sure
+ * the value is in fact <code>null</code> (a rare use case). Validators that extend this and
+ * wish to ensure the value is <code>null</code> should override this method and return
* <code>true</code>.
*
- * @return <code>true</code> to validate on <code>null</code> value, <code>false</code> to
- * skip validation on <code>null</code> value
+ * @return <code>true</code> to validate on <code>null</code> value, <code>false</code> to skip
+ * validation on <code>null</code> value
*/
public boolean validateOnNullValue()
{
@@ -68,12 +70,12 @@
* @param validatable
* the given <code>IValidatable</code> instance
*/
- protected abstract void onValidate(IValidatable validatable);
+ protected abstract void onValidate(IValidatable<T> validatable);
/**
* @see IValidator#validate(IValidatable)
*/
- public final void validate(IValidatable validatable)
+ public final void validate(IValidatable<T> validatable)
{
if (validatable.getValue() != null || validateOnNullValue())
{
@@ -90,7 +92,7 @@
* the <code>IValidatable</code> instance being validated
*
*/
- public void error(final IValidatable validatable)
+ public void error(final IValidatable<T> validatable)
{
error(validatable, resourceKey(), variablesMap(validatable));
}
@@ -106,7 +108,7 @@
* the message resource key to use
*
*/
- public void error(final IValidatable validatable, String resourceKey)
+ public void error(final IValidatable<T> validatable, String resourceKey)
{
if (resourceKey == null)
{
@@ -125,7 +127,7 @@
* @param vars
* <code>Map</code> of variables for variable interpolation
*/
- public void error(final IValidatable validatable, final Map<String, Object> vars)
+ public void error(final IValidatable<T> validatable, final Map<String, Object> vars)
{
if (vars == null)
{
@@ -145,7 +147,7 @@
* @param vars
* <code>Map</code> of variables for variable interpolation
*/
- public void error(final IValidatable validatable, final String resourceKey,
+ public void error(final IValidatable<T> validatable, final String resourceKey,
Map<String, Object> vars)
{
if (validatable == null)
@@ -196,7 +198,7 @@
*
* @return a <code>Map</code> of variables for variable interpolation
*/
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<T> validatable)
{
final Map<String, Object> resourceModel = new HashMap<String, Object>(1);
return resourceModel;
@@ -209,11 +211,9 @@
*
* Gets the default variables for interpolation. These are:
* <ul>
- * <li>${input}: the user's input</li>
- * <li>${name}: the name of the component</li>
- * <li>${label}: the label of the <code>Component</code> - either comes from
- * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that
- * order</li>
+ * <li>${input}: the user's input</li> <li>${name}: the name of the component</li> <li>${label}:
+ * the label of the <code>Component</code> - either comes from <code>FormComponent.labelModel
+ * </code> or resource key [form-id].[form-component-id] in that order</li>
* </ul>
*
* @param formComponent
@@ -224,10 +224,10 @@
* @throws UnsupportedOperationException
*
*
- * FIXME 2.0: remove asap
+ * FIXME 2.0: remove asap
*/
@Deprecated
- protected final Map<String, Object> messageModel(final FormComponent formComponent)
+ protected final Map<String, Object> messageModel(final FormComponent<T> formComponent)
{
throw new UnsupportedOperationException("THIS METHOD IS DEPRECATED, SEE JAVADOC");
}
@@ -246,11 +246,11 @@
* @throws UnsupportedOperationException
*
*
- * FIXME 2.0: remove asap
+ * FIXME 2.0: remove asap
*
*/
@Deprecated
- protected final String resourceKey(final FormComponent formComponent)
+ protected final String resourceKey(final FormComponent<T> formComponent)
{
throw new UnsupportedOperationException("THIS METHOD IS DEPRECATED, SEE JAVADOC");
}
@@ -273,10 +273,10 @@
* @throws UnsupportedOperationException
*
*
- * FIXME 2.0: remove asap
+ * FIXME 2.0: remove asap
*/
@Deprecated
- public final void validate(final FormComponent component)
+ public final void validate(final FormComponent<T> component)
{
throw new UnsupportedOperationException("THIS METHOD IS DEPRECATED, SEE JAVADOC");
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/CreditCardValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/CreditCardValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/CreditCardValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/CreditCardValidator.java Tue Sep 2 23:01:56 2008
@@ -29,16 +29,17 @@
* @author Johan Compagner
* @since 1.2.6
*/
-public class CreditCardValidator extends AbstractValidator
+public class CreditCardValidator extends AbstractValidator<String>
{
private static final long serialVersionUID = 1L;
/**
* @see AbstractValidator#onValidate(IValidatable)
*/
- protected void onValidate(IValidatable validatable)
+ @Override
+ protected void onValidate(IValidatable<String> validatable)
{
- String input = ((String)validatable.getValue());
+ String input = (validatable.getValue());
String numberToCheck = input.replaceAll("[ -]", "");
int nulOffset = '0';
int sum = 0;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/DateValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/DateValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/DateValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/DateValidator.java Tue Sep 2 23:01:56 2008
@@ -33,7 +33,7 @@
* @author Igor Vaynberg (ivaynberg)
* @since 1.2.6
*/
-public abstract class DateValidator extends AbstractValidator
+public abstract class DateValidator extends AbstractValidator<Date>
{
/**
@@ -42,10 +42,10 @@
private static final long serialVersionUID = 1L;
/**
- * Gets a <code>Date</code> range validator for checking if the <code>Date</code> value
- * falls between the minimum and maximum <code>Date</code> values. If that is not the case, an
- * error message will be generated with the key "DateValidator.range". The message keys that can
- * be used are:
+ * Gets a <code>Date</code> range validator for checking if the <code>Date</code> value falls
+ * between the minimum and maximum <code>Date</code> values. If that is not the case, an error
+ * message will be generated with the key "DateValidator.range". The message keys that can be
+ * used are:
* <p>
* <ul>
* <li>${minimum}: the minimum date</li>
@@ -133,7 +133,7 @@
}
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<Date> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
map.put("minimum", minimum);
@@ -151,9 +151,9 @@
}
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<Date> validatable)
{
- Date value = (Date)validatable.getValue();
+ Date value = validatable.getValue();
if (value.before(minimum) || value.after(maximum))
{
error(validatable);
@@ -174,7 +174,7 @@
}
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<Date> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
map.put("minimum", minimum);
@@ -189,9 +189,9 @@
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<Date> validatable)
{
- Date value = (Date)validatable.getValue();
+ Date value = validatable.getValue();
if (value.before(minimum))
{
error(validatable);
@@ -212,7 +212,7 @@
}
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<Date> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
map.put("maximum", maximum);
@@ -227,9 +227,9 @@
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<Date> validatable)
{
- Date value = (Date)validatable.getValue();
+ Date value = validatable.getValue();
if (value.after(maximum))
{
error(validatable);
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/NumberValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/NumberValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/NumberValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/NumberValidator.java Tue Sep 2 23:01:56 2008
@@ -29,9 +29,11 @@
* @author Jonathan Locke
* @author Johan Compagner
* @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of validatable
* @since 1.2.6
*/
-public abstract class NumberValidator extends AbstractValidator
+public abstract class NumberValidator<T extends Number> extends AbstractValidator<T>
{
/**
*
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/PatternValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/PatternValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/PatternValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/PatternValidator.java Tue Sep 2 23:01:56 2008
@@ -24,19 +24,19 @@
// FIXME 2.0: ivaynberg: look over javadoc
/**
- * Validates a <code>Component</code> by matching the component's value against a regular
- * expression pattern. A <code>PatternValidator</code> can be constructed with either a Java
- * regular expression (compiled or not) or a <code>MetaPattern</code>. If the pattern matches
- * against the value of the <code>Component</code> it is attached to when <code>validate</code>
- * is called by the framework, then that input value is considered valid. If the pattern does not
- * match, the <code>errorMessage</code> method will be called.
+ * Validates a <code>Component</code> by matching the component's value against a regular expression
+ * pattern. A <code>PatternValidator</code> can be constructed with either a Java regular expression
+ * (compiled or not) or a <code>MetaPattern</code>. If the pattern matches against the value of the
+ * <code>Component</code> it is attached to when <code>validate</code> is called by the framework,
+ * then that input value is considered valid. If the pattern does not match, the
+ * <code>errorMessage</code> method will be called.
* <p>
* For example, to restrict a field to only digits, you might add a <code>PatternValidator</code>
* constructed with the pattern "\d+". Another way to do the same thing would be to construct the
- * <code>PatternValidator</code> passing in <code>MetaPattern.DIGITS</code>. The advantages of
- * using <code>MetaPattern</code> over straight Java regular expressions are that the patterns are
- * easier to construct and easier to combine into complex patterns. They are also more readable and
- * more reusable. See {@link org.apache.wicket.util.parse.metapattern.MetaPattern MetaPattern} for
+ * <code>PatternValidator</code> passing in <code>MetaPattern.DIGITS</code>. The advantages of using
+ * <code>MetaPattern</code> over straight Java regular expressions are that the patterns are easier
+ * to construct and easier to combine into complex patterns. They are also more readable and more
+ * reusable. See {@link org.apache.wicket.util.parse.metapattern.MetaPattern MetaPattern} for
* details.
* <p>
* The error message will be generated with the key "PatternValidator" and the message keys that can
@@ -47,8 +47,8 @@
* <li>${input}: the input the user gave</li>
* <li>${name}: the name of the <code>Component</code> that failed</li>
* <li>${label}: the label of the <code>Component</code> - either comes from
- * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that
- * order</li>
+ * <code>FormComponent.labelModel</code> or resource key [form-id].[form-component-id] in that order
+ * </li>
* </ul>
*
* @author Jonathan Locke
@@ -76,8 +76,8 @@
}
/**
- * Constructor that accepts a <code>String</code> pattern and Java <code>regex</code>
- * compile flags as arguments.
+ * Constructor that accepts a <code>String</code> pattern and Java <code>regex</code> compile
+ * flags as arguments.
*
* @param pattern
* a regular expression pattern
@@ -129,7 +129,7 @@
* the <code>IValidatable</code> to check
*/
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<String> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
map.put("pattern", pattern.pattern());
@@ -152,10 +152,10 @@
* the <code>IValidatable</code> to check
*/
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<String> validatable)
{
// Check value against pattern
- if (!pattern.matcher((String)validatable.getValue()).matches())
+ if (!pattern.matcher(validatable.getValue()).matches())
{
error(validatable);
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/StringValidator.java Tue Sep 2 23:01:56 2008
@@ -30,7 +30,7 @@
* @author Igor Vaynberg (ivaynberg)
* @since 1.2.6
*/
-public abstract class StringValidator extends AbstractValidator
+public abstract class StringValidator extends AbstractValidator<String>
{
/**
@@ -72,9 +72,9 @@
* see AbstractValidator#onValidate(IValidatable)
*/
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<String> validatable)
{
- if (((String)validatable.getValue()).length() != length)
+ if ((validatable.getValue()).length() != length)
{
error(validatable);
}
@@ -93,10 +93,10 @@
* @see AbstractValidator#variablesMap(IValidatable)
*/
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<String> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
- map.put("length", new Integer(((String)validatable.getValue()).length()));
+ map.put("length", new Integer((validatable.getValue()).length()));
map.put("exact", new Integer(length));
return map;
}
@@ -104,8 +104,7 @@
}
/**
- * Validator for checking if the length of a <code>String</code> is within the specified
- * range.
+ * Validator for checking if the length of a <code>String</code> is within the specified range.
*/
public static class LengthBetweenValidator extends StringValidator
{
@@ -152,9 +151,9 @@
* see AbstractValidator#onValidate(IValidatable)
*/
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<String> validatable)
{
- final String value = (String)validatable.getValue();
+ final String value = validatable.getValue();
if (value.length() < minimum || value.length() > maximum)
{
error(validatable);
@@ -175,12 +174,12 @@
* @see AbstractValidator#variablesMap(IValidatable)
*/
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<String> validatable)
{
final Map<String, Object> 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()));
+ map.put("length", new Integer((validatable.getValue()).length()));
return map;
}
@@ -220,9 +219,9 @@
* see AbstractValidator#onValidate(IValidatable)
*/
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<String> validatable)
{
- if (((String)validatable.getValue()).length() > maximum)
+ if ((validatable.getValue()).length() > maximum)
{
error(validatable);
}
@@ -241,11 +240,11 @@
* @see AbstractValidator#variablesMap(IValidatable)
*/
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<String> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
map.put("maximum", new Integer(maximum));
- map.put("length", new Integer(((String)validatable.getValue()).length()));
+ map.put("length", new Integer((validatable.getValue()).length()));
return map;
}
}
@@ -284,9 +283,9 @@
* see AbstractValidator#onValidate(IValidatable)
*/
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<String> validatable)
{
- if (((String)validatable.getValue()).length() < minimum)
+ if ((validatable.getValue()).length() < minimum)
{
error(validatable);
}
@@ -305,21 +304,20 @@
* @see AbstractValidator#variablesMap(IValidatable)
*/
@Override
- protected Map<String, Object> variablesMap(IValidatable validatable)
+ protected Map<String, Object> variablesMap(IValidatable<String> validatable)
{
final Map<String, Object> map = super.variablesMap(validatable);
map.put("minimum", new Integer(minimum));
- map.put("length", new Integer(((String)validatable.getValue()).length()));
+ map.put("length", new Integer((validatable.getValue()).length()));
return map;
}
}
/**
- * Gets a <code>String</code> exact length validator for checking if a string length is
- * exactly the same as the given length value. If that is not the case, then an error message
- * will be generated with the key "StringValidator.exact". The message keys that can be used
- * are:
+ * Gets a <code>String</code> exact length validator for checking if a string length is exactly
+ * the same as the given length value. If that is not the case, then an error message will be
+ * generated with the key "StringValidator.exact". The message keys that can be used are:
* <p>
* <ul>
* <li>${exact}: the maximum length</li>
@@ -342,8 +340,8 @@
}
/**
- * Gets a <code>String</code> range validator for checking if a string length falls between
- * the minimum and and maximum lengths. If that is not the case, then an error message will be
+ * Gets a <code>String</code> range validator for checking if a string length falls between the
+ * minimum and and maximum lengths. If that is not the case, then an error message will be
* generated with the key "StringValidator.range". The message keys that can be used are:
* <p>
* <ul>
@@ -370,9 +368,9 @@
}
/**
- * Gets a <code>String</code> maximum validator for checking if a string length is smaller
- * than the given maximum value. If that is not the case, then an error message will be
- * generated with the key "StringValidator.maximum". The message keys that can be used are:
+ * Gets a <code>String</code> maximum validator for checking if a string length is smaller than
+ * the given maximum value. If that is not the case, then an error message will be generated
+ * with the key "StringValidator.maximum". The message keys that can be used are:
* <p>
* <ul>
* <li>${maximum}: the maximum length</li>
@@ -395,9 +393,9 @@
}
/**
- * Gets a <code>String</code> minimum validator for checking if a string length is greater
- * than the given minimum value. If that is not the case, then an error message will be
- * generated with the key "StringValidator.minimum". The message keys that can be used are:
+ * Gets a <code>String</code> minimum validator for checking if a string length is greater than
+ * the given minimum value. If that is not the case, then an error message will be generated
+ * with the key "StringValidator.minimum". The message keys that can be used are:
* <p>
* <ul>
* <li>${minimum}: the minimum length</li>
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java?rev=691520&r1=691519&r2=691520&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/validation/validator/UrlValidator.java Tue Sep 2 23:01:56 2008
@@ -31,12 +31,11 @@
* The behavior of validation is modified by passing in one of these options:
* <p>
* <ul>
- * <li><code>ALLOW_2_SLASHES - [FALSE]</code>: Allows double '/' characters in the path
- * component.</li>
+ * <li><code>ALLOW_2_SLASHES - [FALSE]</code>: Allows double '/' characters in the path component.</li>
* <li><code>NO_FRAGMENT- [FALSE]</code>: By default fragments are allowed. If this option is
* included then fragments are flagged as illegal.</li>
- * <li><code>ALLOW_ALL_SCHEMES - [FALSE]</code>: By default only http, https, and ftp are
- * considered valid schemes. Enabling this option will let any scheme pass validation.</li>
+ * <li><code>ALLOW_ALL_SCHEMES - [FALSE]</code>: By default only http, https, and ftp are considered
+ * valid schemes. Enabling this option will let any scheme pass validation.</li>
* </ul>
* <p>
* This was originally based <code>org.apache.commons.validator.UrlValidator</code>, but the
@@ -44,17 +43,16 @@
* <p>
*
* <pre>
- * <code>
+ * <code>
* Component.add(new UrlValidator({"http", "https"}));
- * </code>
+ * </code>
* </pre>
*
* @author Vincent Demay
* @since 1.2.6
- * @see <a href="http://www.ietf.org/rfc/rfc2396.txt">Uniform Resource Identifiers (URI): Generic
- * Syntax (RFC 2396)</a>
+ * @see "http://www.ietf.org/rfc/rfc2396.txt"
*/
-public class UrlValidator extends AbstractValidator
+public class UrlValidator extends AbstractValidator<String>
{
private static final long serialVersionUID = 1L;
@@ -174,8 +172,8 @@
*
* @param schemes
* Pass in one or more <code>URL</code> schemes to consider valid. Passing in a
- * <code>null</code> will default to "<code>http,https,ftp</code>" being used.
- * If a non-<code>null</code> scheme is specified, then all valid schemes must be
+ * <code>null</code> will default to "<code>http,https,ftp</code>" being used. If a
+ * non-<code>null</code> scheme is specified, then all valid schemes must be
* specified. Setting the <code>ALLOW_ALL_SCHEMES</code> option will ignore the
* contents of <code>schemes</code>.
*/
@@ -204,8 +202,8 @@
*
* @param schemes
* Pass in one or more <code>URL</code> schemes to consider valid. Passing in a
- * <code>null</code> will default to "<code>http,https,ftp</code>" being used.
- * If a non-<code>null</code> scheme is specified, then all valid schemes must be
+ * <code>null</code> will default to "<code>http,https,ftp</code>" being used. If a
+ * non-<code>null</code> scheme is specified, then all valid schemes must be
* specified. Setting the <code>ALLOW_ALL_SCHEMES</code> option will ignore the
* contents of <code>schemes</code>.
* @param options
@@ -236,9 +234,9 @@
* @see AbstractValidator#onValidate(IValidatable)
*/
@Override
- protected void onValidate(IValidatable validatable)
+ protected void onValidate(IValidatable<String> validatable)
{
- String url = (String)validatable.getValue();
+ String url = validatable.getValue();
if (url != null && !isValid(url))
{
error(validatable);
@@ -246,8 +244,8 @@
}
/**
- * Checks if a field has a valid <code>URL</code>. This method is public because it is
- * directly used in tests.
+ * Checks if a field has a valid <code>URL</code>. This method is public because it is directly
+ * used in tests.
*
* @param value
* The value validation is being performed on. A <code>null</code> value is
@@ -305,8 +303,8 @@
}
/**
- * Validates a scheme. If schemes[] was initialized to non-<code>null</code>, then only
- * those schemes are allowed. Note that this is slightly different than for the constructor.
+ * Validates a scheme. If schemes[] was initialized to non-<code>null</code>, then only those
+ * schemes are allowed. Note that this is slightly different than for the constructor.
*
* @param scheme
* The scheme to validate. A <code>null</code> value is considered invalid.
@@ -338,8 +336,7 @@
/**
* Returns <code>true</code> if the authority is properly formatted. An authority is the
- * combination of host name and port. A <code>null</code> authority value is considered
- * invalid.
+ * combination of host name and port. A <code>null</code> authority value is considered invalid.
*
* @param authority
* an authority value to validate
@@ -519,8 +516,8 @@
}
/**
- * Returns <code>true</code> if the query is <code>null</code> or if it's a
- * properly-formatted query string.
+ * Returns <code>true</code> if the query is <code>null</code> or if it's a properly-formatted
+ * query string.
*
* @param query
* a query value to validate
@@ -581,8 +578,8 @@
}
/**
- * Checks if the field isn't <code>null</code> and if length of the field is greater than
- * zero, not including whitespace.
+ * Checks if the field isn't <code>null</code> and if length of the field is greater than zero,
+ * not including whitespace.
*
* @param value
* the value validation is being performed on