net.dpml.cli.validation

Class URLValidator

Implemented Interfaces:
Validator

public class URLValidator
extends java.lang.Object
implements Validator

The URLValidator validates the string argument values are URLs. If the value is a URL, the string value in the java.util.List of values is replaced with the java.net.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"));
 
Version:
@PROJECT-VERSION@
Author:
@PUBLISHER-NAME@

Constructor Summary

URLValidator()
Creates a URLValidator.
URLValidator(String protocol)
Creates a URLValidator for the specified protocol.

Method Summary

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.

Constructor Details

URLValidator

public URLValidator()
Creates a URLValidator.

URLValidator

public URLValidator(String protocol)
Creates a URLValidator for the specified protocol.
Parameters:
protocol - the url protocol

Method Details

getProtocol

public String getProtocol()
Returns the protocol that must be used by a valid URL.
Returns:
the protocol that must be used by a valid URL.

setProtocol

public void setProtocol(String protocol)
Specifies the protocol that a URL must have to be valid.
Parameters:
protocol - the protocol that a URL must have to be valid.

validate

public void validate(List values)
            throws InvalidArgumentException
Validate the list of values against the list of permitted values. If a value is valid, replace the string in the values java.util.List with the { java.net.URL} instance.
Specified by:
validate in interface Validator
Parameters:
values - the list of values to validate
Throws:
InvalidArgumentException - if a value is invalid
See Also:
net.dpml.cli.validation.Validator.validate(java.util.List)