Class 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 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
    • 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.ContentType acceptedContentType)
      Accepted content type constructor.
      ResourceImportValidator​(com.globalmentor.net.ContentType acceptedContentType, boolean valueRequired)
      Accepted content type, and value required constructor.
      ResourceImportValidator​(com.globalmentor.net.ContentType acceptedContentType, long maxContentLength)
      Accepted content type and maximum content length constructor.
      ResourceImportValidator​(com.globalmentor.net.ContentType 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.ContentType> acceptedContentTypes)
      Accepted content types constructor.
      ResourceImportValidator​(java.util.Set<com.globalmentor.net.ContentType> acceptedContentTypes, boolean valueRequired)
      Accepted content types and value required constructor.
      ResourceImportValidator​(java.util.Set<com.globalmentor.net.ContentType> acceptedContentTypes, long maxContentLength)
      Accepted content types and maximum content length constructor.
      ResourceImportValidator​(java.util.Set<com.globalmentor.net.ContentType> acceptedContentTypes, long maxContentLength, boolean valueRequired)
      Accepted content types, maximum content length, and value required constructor.
      ResourceImportValidator​(java.util.Set<com.globalmentor.net.ContentType> acceptedContentTypes, java.util.Set<java.lang.String> acceptedExtensions)
      Accepted content types, and accepted extensions constructor.
      ResourceImportValidator​(java.util.Set<com.globalmentor.net.ContentType> 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.ContentType> 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.ContentType> 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.ContentType> 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 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
    • 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.ContentType> 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.ContentType acceptedContentType)
        Accepted content type constructor.
        Parameters:
        acceptedContentType - The single accepted content types.
      • ResourceImportValidator

        public ResourceImportValidator​(com.globalmentor.net.ContentType 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.ContentType> 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​(java.util.Set<com.globalmentor.net.ContentType> 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.ContentType 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.ContentType 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.ContentType> 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​(java.util.Set<com.globalmentor.net.ContentType> 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, or null if all content types are accepted.
        acceptedExtensions - The accepted filename extensions, or null if all filename extensions are accepted.
      • ResourceImportValidator

        public ResourceImportValidator​(java.util.Set<com.globalmentor.net.ContentType> 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, 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​(java.util.Set<com.globalmentor.net.ContentType> 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, 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​(java.util.Set<com.globalmentor.net.ContentType> 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, 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 Detail

      • getAcceptedContentTypes

        public java.util.Set<com.globalmentor.net.ContentType> 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.
      • toString

        protected java.lang.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.