Package org.apache.commons.validator
Class UrlValidator
- java.lang.Object
-
- org.apache.commons.validator.UrlValidator
-
- All Implemented Interfaces:
java.io.Serializable
public class UrlValidator extends java.lang.Object implements java.io.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, 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"
- Since:
- Validator 1.1
- Version:
- $Revision: 1651811 $
- See Also:
- Uniform Resource Identifiers (URI): Generic Syntax , Serialized Form
-
-
Field Summary
Fields 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.private java.util.Set<java.lang.String>
allowedSchemes
Deprecated.The set of schemes that are allowed to be in a URL.private static java.lang.String
ALPHA_CHARS
Deprecated.private static java.util.regex.Pattern
ALPHA_PATTERN
Deprecated.private static java.lang.String
ATOM
Deprecated.private static java.util.regex.Pattern
ATOM_PATTERN
Deprecated.private static java.lang.String
AUTHORITY_CHARS_REGEX
Deprecated.private static java.util.regex.Pattern
AUTHORITY_PATTERN
Deprecated.private static java.lang.String
AUTHORITY_REGEX
Deprecated.protected java.lang.String[]
defaultSchemes
Deprecated.If no schemes are provided, default to this set.private static java.util.regex.Pattern
DOMAIN_PATTERN
Deprecated.private static java.util.regex.Pattern
LEGAL_ASCII_PATTERN
Deprecated.static int
NO_FRAGMENTS
Deprecated.Enabling this options disallows any URL fragments.private Flags
options
Deprecated.Holds the set of current validation options.private static int
PARSE_AUTHORITY_EXTRA
Deprecated.Should always be empty.private static int
PARSE_AUTHORITY_HOST_IP
Deprecated.private static int
PARSE_AUTHORITY_PORT
Deprecated.private static int
PARSE_URL_AUTHORITY
Deprecated.Includes hostname/ip and port number.private static int
PARSE_URL_FRAGMENT
Deprecated.private static int
PARSE_URL_PATH
Deprecated.private static int
PARSE_URL_QUERY
Deprecated.private static int
PARSE_URL_SCHEME
Deprecated.Schema/Protocol (ie.private static java.util.regex.Pattern
PATH_PATTERN
Deprecated.private static java.util.regex.Pattern
PORT_PATTERN
Deprecated.private static java.util.regex.Pattern
QUERY_PATTERN
Deprecated.private static java.util.regex.Pattern
SCHEME_PATTERN
Deprecated.Protocol (ie.private static long
serialVersionUID
Deprecated.private static java.lang.String
SPECIAL_CHARS
Deprecated.private static java.util.regex.Pattern
URL_PATTERN
Deprecated.private static java.lang.String
URL_REGEX
Deprecated.This expression derived/taken from the BNF for URI (RFC2396).private static java.lang.String
VALID_CHARS
Deprecated.
-
Constructor Summary
Constructors 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:
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods 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.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Deprecated.- See Also:
- Constant Field Values
-
ALLOW_ALL_SCHEMES
public static final int ALLOW_ALL_SCHEMES
Deprecated.Allows all validly formatted schemes to pass validation instead of supplying a set of valid schemes.- See Also:
- Constant Field Values
-
ALLOW_2_SLASHES
public static final int ALLOW_2_SLASHES
Deprecated.Allow two slashes in the path component of the URL.- See Also:
- Constant Field Values
-
NO_FRAGMENTS
public static final int NO_FRAGMENTS
Deprecated.Enabling this options disallows any URL fragments.- See Also:
- Constant Field Values
-
ALPHA_CHARS
private static final java.lang.String ALPHA_CHARS
Deprecated.- See Also:
- Constant Field Values
-
SPECIAL_CHARS
private static final java.lang.String SPECIAL_CHARS
Deprecated.- See Also:
- Constant Field Values
-
VALID_CHARS
private static final java.lang.String VALID_CHARS
Deprecated.- See Also:
- Constant Field Values
-
AUTHORITY_CHARS_REGEX
private static final java.lang.String AUTHORITY_CHARS_REGEX
Deprecated.- See Also:
- Constant Field Values
-
ATOM
private static final java.lang.String ATOM
Deprecated.- See Also:
- Constant Field Values
-
URL_REGEX
private static final java.lang.String URL_REGEX
Deprecated.This expression derived/taken from the BNF for URI (RFC2396).- See Also:
- Constant Field Values
-
URL_PATTERN
private static final java.util.regex.Pattern URL_PATTERN
Deprecated.
-
PARSE_URL_SCHEME
private static final int PARSE_URL_SCHEME
Deprecated.Schema/Protocol (ie. http:, ftp:, file:, etc).- See Also:
- Constant Field Values
-
PARSE_URL_AUTHORITY
private static final int PARSE_URL_AUTHORITY
Deprecated.Includes hostname/ip and port number.- See Also:
- Constant Field Values
-
PARSE_URL_PATH
private static final int PARSE_URL_PATH
Deprecated.- See Also:
- Constant Field Values
-
PARSE_URL_QUERY
private static final int PARSE_URL_QUERY
Deprecated.- See Also:
- Constant Field Values
-
PARSE_URL_FRAGMENT
private static final int PARSE_URL_FRAGMENT
Deprecated.- See Also:
- Constant Field Values
-
SCHEME_PATTERN
private static final java.util.regex.Pattern SCHEME_PATTERN
Deprecated.Protocol (ie. http:, ftp:,https:).
-
AUTHORITY_REGEX
private static final java.lang.String AUTHORITY_REGEX
Deprecated.- See Also:
- Constant Field Values
-
AUTHORITY_PATTERN
private static final java.util.regex.Pattern AUTHORITY_PATTERN
Deprecated.
-
PARSE_AUTHORITY_HOST_IP
private static final int PARSE_AUTHORITY_HOST_IP
Deprecated.- See Also:
- Constant Field Values
-
PARSE_AUTHORITY_PORT
private static final int PARSE_AUTHORITY_PORT
Deprecated.- See Also:
- Constant Field Values
-
PARSE_AUTHORITY_EXTRA
private static final int PARSE_AUTHORITY_EXTRA
Deprecated.Should always be empty.- See Also:
- Constant Field Values
-
PATH_PATTERN
private static final java.util.regex.Pattern PATH_PATTERN
Deprecated.
-
QUERY_PATTERN
private static final java.util.regex.Pattern QUERY_PATTERN
Deprecated.
-
LEGAL_ASCII_PATTERN
private static final java.util.regex.Pattern LEGAL_ASCII_PATTERN
Deprecated.
-
DOMAIN_PATTERN
private static final java.util.regex.Pattern DOMAIN_PATTERN
Deprecated.
-
PORT_PATTERN
private static final java.util.regex.Pattern PORT_PATTERN
Deprecated.
-
ATOM_PATTERN
private static final java.util.regex.Pattern ATOM_PATTERN
Deprecated.
-
ALPHA_PATTERN
private static final java.util.regex.Pattern ALPHA_PATTERN
Deprecated.
-
options
private final Flags options
Deprecated.Holds the set of current validation options.
-
allowedSchemes
private final java.util.Set<java.lang.String> allowedSchemes
Deprecated.The set of schemes that are allowed to be in a URL.
-
defaultSchemes
protected java.lang.String[] defaultSchemes
Deprecated.If no schemes are provided, default to this set.
-
-
Constructor Detail
-
UrlValidator
public UrlValidator()
Deprecated.Create a UrlValidator with default properties.
-
UrlValidator
public UrlValidator(java.lang.String[] schemes)
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
public UrlValidator(int options)
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
public UrlValidator(java.lang.String[] schemes, int options)
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 Detail
-
isValid
public boolean isValid(java.lang.String value)
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.
-
isValidScheme
protected boolean isValidScheme(java.lang.String scheme)
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.
-
isValidAuthority
protected boolean isValidAuthority(java.lang.String authority)
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.
-
isValidPath
protected boolean isValidPath(java.lang.String path)
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
protected boolean isValidQuery(java.lang.String query)
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.
-
isValidFragment
protected boolean isValidFragment(java.lang.String fragment)
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.
-
countToken
protected int countToken(java.lang.String token, java.lang.String target)
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.
-
-