FileItem file = (FileItem) value;
if (maxSize != null && file.getSize() > maxSize) {
FacesMessage facesMessage = MessageUtils.getMessage(
facesContext, facesContext.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR,
SIZE_LIMIT_MESSAGE_ID, maxSize, component.getId());
throw new ValidatorException(facesMessage);
}
// Check only a valid file
if (file.getSize() > 0 && contentType != null && contentType.length > 0) {
boolean found = false;
for (String contentTypeStr : contentType) {
if (ContentType.valueOf(contentTypeStr).match(ContentType.valueOf(file.getContentType()))) {
found = true;
break;
}
}
if (!found) {
String message;
if (contentType.length == 1) {
message = contentType[0];
} else {
message = Arrays.toString(contentType);
}
FacesMessage facesMessage = MessageUtils.getMessage(
facesContext, facesContext.getViewRoot().getLocale(), FacesMessage.SEVERITY_ERROR,
CONTENT_TYPE_MESSAGE_ID, message, component.getId());
throw new ValidatorException(facesMessage);
}
}
}
}