java.io.Serializable
@Deprecated
public class UrlValidator
extends java.lang.Object
implements java.io.Serializable
Validates URLs.
Behavour of validation is modified by passing in options:Originally based in on php script by Debbie Dyer, validation.php v1.2b, Date: 03/07/02, http://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"
Modifier and Type | Field | Description |
---|---|---|
static int |
ALLOW_2_SLASHES |
Deprecated.
Allow two slashes in the path component of the URL.
|
static int |
ALLOW_ALL_SCHEMES |
Deprecated.
Allows all validly formatted schemes to pass validation instead of
supplying a set of valid schemes.
|
protected java.lang.String[] |
defaultSchemes |
Deprecated.
If no schemes are provided, default to this set.
|
static int |
NO_FRAGMENTS |
Deprecated.
Enabling this options disallows any URL fragments.
|
Constructor | Description |
---|---|
UrlValidator() |
Deprecated.
Create a UrlValidator with default properties.
|
UrlValidator(int options) |
Deprecated.
Initialize a UrlValidator with the given validation options.
|
UrlValidator(java.lang.String[] schemes) |
Deprecated.
Behavior of validation is modified by passing in several strings options:
|
UrlValidator(java.lang.String[] schemes,
int options) |
Deprecated.
Behavour of validation is modified by passing in options:
|
Modifier and Type | Method | Description |
---|---|---|
protected int |
countToken(java.lang.String token,
java.lang.String target) |
Deprecated.
Returns the number of times the token appears in the target.
|
boolean |
isValid(java.lang.String value) |
Deprecated.
Checks if a field has a valid url address.
|
protected boolean |
isValidAuthority(java.lang.String authority) |
Deprecated.
Returns true if the authority is properly formatted.
|
protected boolean |
isValidFragment(java.lang.String fragment) |
Deprecated.
Returns true if the given fragment is null or fragments are allowed.
|
protected boolean |
isValidPath(java.lang.String path) |
Deprecated.
Returns true if the path is valid.
|
protected boolean |
isValidQuery(java.lang.String query) |
Deprecated.
Returns true if the query is null or it's a properly formatted query string.
|
protected boolean |
isValidScheme(java.lang.String scheme) |
Deprecated.
Validate scheme.
|
public static final int ALLOW_ALL_SCHEMES
public static final int ALLOW_2_SLASHES
public static final int NO_FRAGMENTS
protected java.lang.String[] defaultSchemes
public UrlValidator()
public UrlValidator(java.lang.String[] schemes)
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.public UrlValidator(int options)
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.public UrlValidator(java.lang.String[] schemes, int options)
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.public boolean isValid(java.lang.String value)
Checks if a field has a valid url address.
value
- The value validation is being performed on. A null
value is considered invalid.protected boolean isValidScheme(java.lang.String scheme)
scheme
- The scheme to validate. A null
value is considered
invalid.protected boolean isValidAuthority(java.lang.String authority)
null
authority value is considered invalid.authority
- Authority value to validate.protected boolean isValidPath(java.lang.String path)
null
value is considered invalid.path
- Path value to validate.protected boolean isValidQuery(java.lang.String query)
query
- Query value to validate.protected boolean isValidFragment(java.lang.String fragment)
fragment
- Fragment value to validate.protected int countToken(java.lang.String token, java.lang.String target)
token
- Token value to be counted.target
- Target value to count tokens in.Copyright © 2002–2018. All rights reserved.