use of org.entando.entando.web.filebrowser.model.FileBrowserRequest in project entando-core by entando.
the class FileBrowserValidator method validate.
@Override
public void validate(Object target, Errors errors) {
FileBrowserRequest request = (FileBrowserRequest) target;
String path = request.getPath();
if (path.endsWith("/")) {
if (request instanceof FileBrowserFileRequest) {
errors.rejectValue("path", ERRCODE_INVALID_PATH, new String[] { path }, "fileBrowser.filename.invalidPath");
return;
} else {
path = path.substring(0, path.length() - 1);
}
}
if (!path.contains("/")) {
return;
}
try {
String directory = path.substring(0, path.lastIndexOf("/"));
if (!this.getStorageManager().exists(directory, request.isProtectedFolder())) {
throw new ResourceNotFoundException(FileBrowserValidator.ERRCODE_RESOURCE_DOES_NOT_EXIST, "parent folder", path);
}
if (request instanceof FileBrowserFileRequest) {
FileBrowserFileRequest fileRequest = (FileBrowserFileRequest) target;
String extractedFileName = path.substring(path.lastIndexOf("/") + 1, path.length());
if (!extractedFileName.equalsIgnoreCase(fileRequest.getFilename())) {
errors.rejectValue("filename", ERRCODE_FILENAME_MISMATCH, new String[] { fileRequest.getFilename(), extractedFileName }, "fileBrowser.filename.body.mismatch");
throw new ValidationConflictException((BindingResult) errors);
}
}
} catch (ValidationConflictException vce) {
throw vce;
} catch (ResourceNotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Error checking path {} , protected {} ", path, request.isProtectedFolder(), e);
throw new RestServerError("error checking path", e);
}
}
Aggregations