Package org.apache.commons.validator
Class UrlValidator
java.lang.Object
org.apache.commons.validator.UrlValidator
- All Implemented Interfaces:
Serializable
Deprecated.
Use the new UrlValidator in the routines package. This class
will be removed in a future release.
Validates URLs.
Behavour of validation is modified by passing in options:- ALLOW_2_SLASHES - [FALSE] Allows double '/' characters in the path component.
- NO_FRAGMENT- [FALSE] By default fragments are allowed, if this option is included then fragments are flagged as illegal.
- ALLOW_ALL_SCHEMES - [FALSE] By default only http, https, and ftp are considered valid schemes. Enabling this option will let any scheme pass validation.
Originally based in on php script by Debbie Dyer, validation.php v1.2b, Date: 03/07/02, https://javascript.internet.com. However, this validation now bears little resemblance to the php original.
Example of usage: Construct a UrlValidator with valid schemes of "http", and "https". String[] schemes = {"http","https"}. UrlValidator urlValidator = new UrlValidator(schemes); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("URL is valid"); } else { System.out.println("URL is invalid"); } prints "URL is invalid" If instead the default constructor is used. UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("URL is valid"); } else { System.out.println("URL is invalid"); } prints out "URL is valid"
- Since:
- 1.1
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Deprecated.Allow two slashes in the path component of the URL.static final int
Deprecated.Allows all validly formatted schemes to pass validation instead of supplying a set of valid schemes.protected String[]
Deprecated.If no schemes are provided, default to this set.static final int
Deprecated.Enabling this options disallows any URL fragments. -
Constructor Summary
ConstructorDescriptionDeprecated.Create a UrlValidator with default properties.UrlValidator
(int options) Deprecated.Initialize a UrlValidator with the given validation options.UrlValidator
(String[] schemes) Deprecated.Behavior of validation is modified by passing in several strings options:UrlValidator
(String[] schemes, int options) Deprecated.Behavour of validation is modified by passing in options: -
Method Summary
Modifier and TypeMethodDescriptionprotected int
countToken
(String token, String target) Deprecated.Returns the number of times the token appears in the target.boolean
Deprecated.Checks if a field has a valid URL address.protected boolean
isValidAuthority
(String authority) Deprecated.Returns true if the authority is properly formatted.protected boolean
isValidFragment
(String fragment) Deprecated.Returns true if the given fragment is null or fragments are allowed.protected boolean
isValidPath
(String path) Deprecated.Returns true if the path is valid.protected boolean
isValidQuery
(String query) Deprecated.Returns true if the query is null or it's a properly formatted query string.protected boolean
isValidScheme
(String scheme) Deprecated.Validate scheme.
-
Field Details
-
ALLOW_ALL_SCHEMES
Deprecated.Allows all validly formatted schemes to pass validation instead of supplying a set of valid schemes.- See Also:
-
ALLOW_2_SLASHES
Deprecated.Allow two slashes in the path component of the URL.- See Also:
-
NO_FRAGMENTS
Deprecated.Enabling this options disallows any URL fragments.- See Also:
-
defaultSchemes
Deprecated.If no schemes are provided, default to this set.
-
-
Constructor Details
-
UrlValidator
public UrlValidator()Deprecated.Create a UrlValidator with default properties. -
UrlValidator
Deprecated.Initialize a UrlValidator with the given validation options.- Parameters:
options
- The options should be set using the public constants declared in this class. To set multiple options you simply add them together. For example, ALLOW_2_SLASHES + NO_FRAGMENTS enables both of those options.
-
UrlValidator
Deprecated.Behavior of validation is modified by passing in several strings options:- Parameters:
schemes
- Pass in one or more URL schemes to consider valid, passing in a null will default to "http,https,ftp" being valid. If a non-null schemes is specified then all valid schemes must be specified. Setting the ALLOW_ALL_SCHEMES option will ignore the contents of schemes.
-
UrlValidator
Deprecated.Behavour of validation is modified by passing in options:- Parameters:
schemes
- The set of valid schemes.options
- The options should be set using the public constants declared in this class. To set multiple options you simply add them together. For example, ALLOW_2_SLASHES + NO_FRAGMENTS enables both of those options.
-
-
Method Details
-
countToken
Deprecated.Returns the number of times the token appears in the target.- Parameters:
token
- Token value to be counted.target
- Target value to count tokens in.- Returns:
- the number of tokens.
-
isValid
Deprecated.Checks if a field has a valid URL address.
- Parameters:
value
- The value validation is being performed on. Anull
value is considered invalid.- Returns:
- true if the URL is valid.
-
isValidAuthority
Deprecated.Returns true if the authority is properly formatted. An authority is the combination of hostname and port. Anull
authority value is considered invalid.- Parameters:
authority
- Authority value to validate.- Returns:
- true if authority (hostname and port) is valid.
-
isValidFragment
Deprecated.Returns true if the given fragment is null or fragments are allowed.- Parameters:
fragment
- Fragment value to validate.- Returns:
- true if fragment is valid.
-
isValidPath
Deprecated.Returns true if the path is valid. Anull
value is considered invalid.- Parameters:
path
- Path value to validate.- Returns:
- true if path is valid.
-
isValidQuery
Deprecated.Returns true if the query is null or it's a properly formatted query string.- Parameters:
query
- Query value to validate.- Returns:
- true if query is valid.
-
isValidScheme
Deprecated.Validate scheme. If schemes[] was initialized to a non null, then only those scheme's are allowed. Note this is slightly different than for the constructor.- Parameters:
scheme
- The scheme to validate. Anull
value is considered invalid.- Returns:
- true if valid.
-