public final class UrlAddressConstraint extends CheckConstraint<String>
CheckConstraint
implementation that checks
whether a string is valid URL reference. Also the allowed set of protocols
and prefix pattern can be configured.
Note that prefix should not describe URL protocol.
For example, prefix of the SCM URL scm:svn:http://svn.foxlabs.org
should be defined as scm:svn:
or scm:[a-z]:
regex.UrlAddress
,
ConstraintFactory.urlAddress()
,
ConstraintFactory.urlAddress(String, String...)
Modifier and Type | Field and Description |
---|---|
static UrlAddressConstraint |
DEFAULT
UrlAddressConstraint default instance initialized with
no prefix and empty set of protocols. |
Modifier and Type | Method and Description |
---|---|
boolean |
appendMessageArguments(ValidationContext<?> context,
Map<String,Object> arguments)
Appends
protocols argument that contains set of allowed
protocols. |
protected <T> boolean |
check(String value,
ValidationContext<T> context)
Checks whether the specified string is valid URL reference with allowed
prefix and protocol.
|
Pattern |
getPrefix()
Returns prefix pattern if any.
|
Set<String> |
getProtocols()
Returns set of allowed protocols (empty set means all protocols are
allowed).
|
Class<?> |
getType()
Returns
java.lang.String type. |
validate
getMessageTemplate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMessageTemplate
public static final UrlAddressConstraint DEFAULT
UrlAddressConstraint
default instance initialized with
no prefix and empty set of protocols.public Class<?> getType()
java.lang.String
type.java.lang.String
type.public Pattern getPrefix()
public Set<String> getProtocols()
public boolean appendMessageArguments(ValidationContext<?> context, Map<String,Object> arguments)
protocols
argument that contains set of allowed
protocols.appendMessageArguments
in interface Constraint<String>
appendMessageArguments
in interface Validation<String>
appendMessageArguments
in class AbstractValidation<String>
context
- Validation context.arguments
- Arguments to be substituted into the error message
template.true
.protected <T> boolean check(String value, ValidationContext<T> context)
check
in class CheckConstraint<String>
T
- The type of validated entity.value
- URL string.context
- Validation context.true
if the specified string is valid URL reference
with allowed protocol and prefix; false
otherwise.Copyright © 2011–2020 FoxLabs. All rights reserved.