com.guiseframework.validator
Class ResourceImportValidator

java.lang.Object
  extended by com.globalmentor.beans.BoundPropertyObject
      extended by com.guiseframework.event.GuiseBoundPropertyObject
          extended by com.guiseframework.validator.AbstractValidator<ResourceImport>
              extended by com.guiseframework.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 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 com.guiseframework.validator.Validator
INVALID_VALUE_MESSAGE_PROPERTY, VALUE_REQUIRED_MESSAGE_PROPERTY, VALUE_REQUIRED_PROPERTY
 
Constructor Summary
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(long maxContentLength)
          Maximum content length constructor.
ResourceImportValidator(long maxContentLength, boolean valueRequired)
          Maximum content length and value required 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
 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)
          Determines whether a given resource import meets the provided criteria.
 
Methods inherited from class com.guiseframework.validator.AbstractValidator
getInvalidValueMessage, getValueRequiredMessage, isValid, isValueRequired, setInvalidValueMessage, setValueRequired, setValueRequiredMessage, throwInvalidValueValidationException, throwValueRequiredValidationException
 
Methods inherited from class com.guiseframework.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.guiseframework.validator.Validator
getSession
 
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

ResourceImportValidator

public ResourceImportValidator(GuiseSession session)
Default constructor.


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.

validate

public void validate(ResourceImport resourceImport)
              throws ValidationException
Determines whether a given resource import meets the provided criteria. This version delgates 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 resource import to validate, which may be null.
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 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.


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.