public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException {
Locale locale = facesContext.getViewRoot().getLocale();
MessageContextFactory messageContextFactory = (MessageContextFactory) FactoryExtensionFinder.getFactory(
MessageContextFactory.class);
MessageContext messageContext = messageContextFactory.getMessageContext();
List<FacesMessage> facesMessages = new ArrayList<FacesMessage>();
@SuppressWarnings("unchecked")
List<UploadedFile> uploadedFiles = (List<UploadedFile>) value;
for (UploadedFile uploadedFile : uploadedFiles) {
if ((maxFileSize != null) && (maxFileSize >= 0) && (uploadedFile.getSize() > maxFileSize)) {
String errorMessage = messageContext.getMessage(locale, "file-x-is-y-bytes-but-may-not-exceed-z-bytes",
uploadedFile.getName(), uploadedFile.getSize(), maxFileSize);
facesMessages.add(new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
}
if ((contentTypeSet != null) && !contentTypeSet.contains(uploadedFile.getContentType())) {
String errorMessage = messageContext.getMessage(locale, "file-x-has-an-invalid-content-type-y",
uploadedFile.getName(), uploadedFile.getContentType());
facesMessages.add(new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage));
}
}