FileItem file = (FileItem) value;
if (maxSize != null && file.getSize() > maxSize) {
Object[] args = {maxSize, component.getId()};
FacesMessage facesMessage = MessageFactory.createFacesMessage(context,
SIZE_LIMIT_MESSAGE_ID, FacesMessage.SEVERITY_ERROR, args);
throw new ValidatorException(facesMessage);
}
// Check only a valid file
if (file.getSize() > 0 && contentType != null
&& !ContentType.valueOf(contentType).match(ContentType.valueOf(file.getContentType()))) {
ContentType expectedContentType = ContentType.valueOf(contentType);
Object [] args = {expectedContentType, component.getId()};
FacesMessage facesMessage = MessageFactory.createFacesMessage(context,
CONTENT_TYPE_MESSAGE_ID, FacesMessage.SEVERITY_ERROR, args);
throw new ValidatorException(facesMessage);
}
}
}