Class ResourceImportValidator
- java.lang.Object
-
- com.globalmentor.beans.BoundPropertyObject
-
- io.guise.framework.event.GuiseBoundPropertyObject
-
- io.guise.framework.validator.AbstractValidator<ResourceImport>
-
- io.guise.framework.validator.ResourceImportValidator
-
- All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable
,com.globalmentor.beans.PropertyConstrainable
,Validator<ResourceImport>
public class ResourceImportValidator extends AbstractValidator<ResourceImport>
A resource import validator that can validate resource imports against accepted content types, file extensions, and/or maximum size. If accepted content types are specified, the set needs to contain thenull
value if resource imports with no content type are to be allowed. Not providing a set of accepted content types allows any content types. If accepted filename extensions are specified, the set needs to contain thenull
value if resource imports with no extension are to be allowed. Not providing a set of accepted filename extensions allows any extensions. If a maximum content length of -1 is specified, any content length, including an undefined content length, will be accepted. Specifying a content length greater than zero will never allow a resource with an undefined content length.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
-
Fields inherited from interface io.guise.framework.validator.Validator
INVALID_VALUE_MESSAGE_PROPERTY, VALUE_REQUIRED_MESSAGE_PROPERTY, VALUE_REQUIRED_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description ResourceImportValidator(long maxContentLength)
Maximum content length constructor.ResourceImportValidator(long maxContentLength, boolean valueRequired)
Maximum content length and value required constructor.ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType)
Accepted content type constructor.ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType, boolean valueRequired)
Accepted content type, and value required constructor.ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType, long maxContentLength)
Accepted content type and maximum content length constructor.ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType, long maxContentLength, boolean valueRequired)
Accepted content type, maximum content length, and value required constructor.ResourceImportValidator(GuiseSession session)
Default constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes)
Accepted content types constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, boolean valueRequired)
Accepted content types and value required constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, long maxContentLength)
Accepted content types and maximum content length constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, long maxContentLength, boolean valueRequired)
Accepted content types, maximum content length, and value required constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions)
Accepted content types, and accepted extensions constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions, boolean valueRequired)
Accepted content types, accepted extensions, and value required constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions, long maxContentLength)
Accepted content types, accepted extensions, and maximum content length constructor.ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions, long maxContentLength, boolean valueRequired)
Accepted content types, accepted extensions, maximum content length, and value required constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<com.globalmentor.net.MediaType>
getAcceptedContentTypes()
java.util.Set<java.lang.String>
getAcceptedExtensions()
long
getMaxContentLength()
protected java.lang.String
toString(ResourceImport resourceImport)
Retrieves a string representation of the given value appropriate for error messages.void
validate(ResourceImport resourceImport)
Checks whether a given value is valid, and throws an exception if not.-
Methods inherited from class io.guise.framework.validator.AbstractValidator
getInvalidValueMessage, getValueRequiredMessage, isValid, isValueRequired, setInvalidValueMessage, setValueRequired, setValueRequiredMessage, throwInvalidValueValidationException, throwValueRequiredValidationException
-
Methods inherited from class io.guise.framework.event.GuiseBoundPropertyObject
getSession
-
Methods inherited from class com.globalmentor.beans.BoundPropertyObject
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface io.guise.framework.validator.Validator
getSession
-
-
-
-
Constructor Detail
-
ResourceImportValidator
public ResourceImportValidator(GuiseSession session)
Default constructor.- Parameters:
session
- The Guise session that owns the validator.
-
ResourceImportValidator
public ResourceImportValidator(long maxContentLength)
Maximum content length constructor.- Parameters:
maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.
-
ResourceImportValidator
public ResourceImportValidator(long maxContentLength, boolean valueRequired)
Maximum content length and value required constructor.- Parameters:
maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes)
Accepted content types constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.
-
ResourceImportValidator
public ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType)
Accepted content type constructor.- Parameters:
acceptedContentType
- The single accepted content types.
-
ResourceImportValidator
public ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType, boolean valueRequired)
Accepted content type, and value required constructor.- Parameters:
acceptedContentType
- The single accepted content types.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, boolean valueRequired)
Accepted content types and value required constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, long maxContentLength)
Accepted content types and maximum content length constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.
-
ResourceImportValidator
public ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType, long maxContentLength)
Accepted content type and maximum content length constructor.- Parameters:
acceptedContentType
- The single accepted content type.maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.
-
ResourceImportValidator
public ResourceImportValidator(com.globalmentor.net.MediaType acceptedContentType, long maxContentLength, boolean valueRequired)
Accepted content type, maximum content length, and value required constructor.- Parameters:
acceptedContentType
- The single accepted content type.maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, long maxContentLength, boolean valueRequired)
Accepted content types, maximum content length, and value required constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions)
Accepted content types, and accepted extensions constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.acceptedExtensions
- The accepted filename extensions, ornull
if all filename extensions are accepted.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions, boolean valueRequired)
Accepted content types, accepted extensions, and value required constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.acceptedExtensions
- The accepted filename extensions, ornull
if all filename extensions are accepted.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions, long maxContentLength)
Accepted content types, accepted extensions, and maximum content length constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.acceptedExtensions
- The accepted filename extensions, ornull
if all filename extensions are accepted.maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.
-
ResourceImportValidator
public ResourceImportValidator(java.util.Set<com.globalmentor.net.MediaType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions, long maxContentLength, boolean valueRequired)
Accepted content types, accepted extensions, maximum content length, and value required constructor.- Parameters:
acceptedContentTypes
- The accepted content types, each of which can have the special wildcard ("*") subtype, ornull
if all content types are accepted.acceptedExtensions
- The accepted filename extensions, ornull
if all filename extensions are accepted.maxContentLength
- The maximum content length to accept, or -1 if there is no limit to the content length.valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
-
Method Detail
-
getAcceptedContentTypes
public java.util.Set<com.globalmentor.net.MediaType> getAcceptedContentTypes()
- Returns:
- The read-only set of accepted content types, each of which can have the special wildcard ("*") subtype, or
null
if all content types are accepted.
-
getAcceptedExtensions
public java.util.Set<java.lang.String> getAcceptedExtensions()
- Returns:
- The read-only set of accepted filename extensions, or
null
if all filename extensions are accepted.
-
getMaxContentLength
public long getMaxContentLength()
- Returns:
- The maximum content length to accept, or -1 if there is no limit to the content length.
-
validate
public void validate(ResourceImport resourceImport) throws ValidationException
Checks whether a given value is valid, and throws an exception if not.The message of the thrown exception should be appropriate for display to the user, although it may include string resource references. If a child class has no specific message to return, that class may call
AbstractValidator.throwInvalidValueValidationException(Object)
as a convenience. A child class may also callAbstractValidator.throwValueRequiredValidationException(Object)
as a convenience, but this is usually not required if this version of the method, which provides a missing value check, is called first.This version checks whether a value is provided if values are required. Child classes should call this version as a convenience for checking non-
null
and required status.Adding new validation logic always requires overriding this method. Although
Validator.isValid(Object)
may be overridden to provide optimized fast-fail determinations, adding new logic toValidator.isValid(Object)
cannot be used in place of overriding this method.This version checks whether a value is provided if values are required. Child classes should call this version as a convenience for checking non-
null
and required status.Adding new validation logic always requires overriding this method. Although
AbstractValidator.isValid(Object)
may be overridden to provide optimized fast-fail determinations, adding new logic toAbstractValidator.isValid(Object)
cannot be used in place of overriding this method.This version delegates to the super class version to determine whether
null
values are allowed.- Specified by:
validate
in interfaceValidator<ResourceImport>
- Overrides:
validate
in classAbstractValidator<ResourceImport>
- Parameters:
resourceImport
- The value to validate, which may benull
.- Throws:
ValidationException
- if the provided value is not valid.- See Also:
getAcceptedContentTypes()
,getAcceptedExtensions()
,getMaxContentLength()
-
toString
protected java.lang.String toString(ResourceImport resourceImport)
Retrieves a string representation of the given value appropriate for error messages. This implementation returns theObject.toString()
string representation of the value.This version returns the resource import name, if present; otherwise the simple name of the class instance.
- Overrides:
toString
in classAbstractValidator<ResourceImport>
- Parameters:
resourceImport
- The value for which a string representation should be returned.- Returns:
- A string representation of the given value.
-
-