public class UrlValidator extends Object implements Validator
UrlValidator validates the string argument
values are URLs. If the value is a URL, the string value in
the List of values is replaced with the
URL instance.
URLs can also be validated based on their scheme by using
the setProtocol method, or by using the specified
constructor.
The following example shows how to limit the valid values
for the site argument to 'https' URLs.
...
ArgumentBuilder builder = new ArgumentBuilder();
Argument site =
builder.withName("site");
.withValidator(new URLValidator("https"));
| Constructor and Description |
|---|
UrlValidator()
Creates a UrlValidator.
|
UrlValidator(String protocol)
Creates a UrlValidator for the specified protocol.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getProtocol()
Returns the protocol that must be used by a valid URL.
|
void |
setProtocol(String protocol)
Specifies the protocol that a URL must have to be valid.
|
void |
validate(List values)
Validate the list of values against the list of permitted values.
|
public UrlValidator()
public UrlValidator(String protocol)
protocol - the protocol to be usedpublic void validate(List values) throws InvalidArgumentException
values
List with the { java.net.URL} instance.validate in interface Validatorvalues - The values to validate.InvalidArgumentException - If any of the
specified values are not valid.Validator.validate(java.util.List)public String getProtocol()
public void setProtocol(String protocol)
protocol - the protocol that a URL must have to be valid.Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.