Class ResourceImportValidator

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, io.clogr.Clogged, Validator<ResourceImport>

public class ResourceImportValidator extends AbstractValidator<ResourceImport> implements io.clogr.Clogged
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 the null 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 the null 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.
    Default constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes)
    Accepted content types constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, boolean valueRequired)
    Accepted content types and value required constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, long maxContentLength)
    Accepted content types and maximum content length constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, long maxContentLength, boolean valueRequired)
    Accepted content types, maximum content length, and value required constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<String> acceptedExtensions)
    Accepted content types, and accepted extensions constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<String> acceptedExtensions, boolean valueRequired)
    Accepted content types, accepted extensions, and value required constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<String> acceptedExtensions, long maxContentLength)
    Accepted content types, accepted extensions, and maximum content length constructor.
    ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<String> acceptedExtensions, long maxContentLength, boolean valueRequired)
    Accepted content types, accepted extensions, maximum content length, and value required constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    Set<com.globalmentor.net.MediaType>
     
     
    long
     
    protected 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.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 io.clogr.Clogged

    getLogger

    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 Details

    • 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(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, or null 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(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, or null if all content types are accepted.
      valueRequired - Whether the value must be non-null in order to be considered valid.
    • ResourceImportValidator

      public ResourceImportValidator(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, or null 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(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, or null 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(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<String> acceptedExtensions)
      Accepted content types, and accepted extensions constructor.
      Parameters:
      acceptedContentTypes - The accepted content types, each of which can have the special wildcard ("*") subtype, or null if all content types are accepted.
      acceptedExtensions - The accepted filename extensions, or null if all filename extensions are accepted.
    • ResourceImportValidator

      public ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<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, or null if all content types are accepted.
      acceptedExtensions - The accepted filename extensions, or null if all filename extensions are accepted.
      valueRequired - Whether the value must be non-null in order to be considered valid.
    • ResourceImportValidator

      public ResourceImportValidator(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<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, or null if all content types are accepted.
      acceptedExtensions - The accepted filename extensions, or null 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(Set<com.globalmentor.net.MediaType> acceptedContentTypes, Set<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, or null if all content types are accepted.
      acceptedExtensions - The accepted filename extensions, or null 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 Details

    • getAcceptedContentTypes

      public 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 Set<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 call AbstractValidator.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 to Validator.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 to AbstractValidator.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 interface Validator<ResourceImport>
      Overrides:
      validate in class AbstractValidator<ResourceImport>
      Parameters:
      resourceImport - The value to validate, which may be null.
      Throws:
      ValidationException - if the provided value is not valid.
      See Also:
    • toString

      protected String toString(ResourceImport resourceImport)
      Retrieves a string representation of the given value appropriate for error messages. This implementation returns the Object.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 class AbstractValidator<ResourceImport>
      Parameters:
      resourceImport - The value for which a string representation should be returned.
      Returns:
      A string representation of the given value.