All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.antelopeframework.validation.FileSuffixValidator Maven / Gradle / Ivy

The newest version!
package com.github.antelopeframework.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;

public class FileSuffixValidator implements ConstraintValidator {
	
	String[] suffixs;
	
	@Override
	public void initialize(FileSuffix parameters) {
		suffixs = StringUtils.split(parameters.suffix(), ",");
	}

	@Override
	public boolean isValid(MultipartFile value, ConstraintValidatorContext context) {
		if (value == null) {
			return true;
		}
		
		String fileName = value.getOriginalFilename();
		if (!StringUtils.endsWithAny(fileName, suffixs)) {
			return false;
		}
		
		return true;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy