private Result<File> copyStreamToTempFile(InputStream stream, String fileName, long size) if (!fileResult.isValid()) File tempFile = fileResult.getResult(); return new Result<File>().addError(text, ErrorCollection.Reason.VALIDATION_FAILED); return new Result<File>().addError(getText("avatarpicker.upload.size.toobig", fileName, FileSize.format(tooBigIOException.getMaxSize())), ErrorCollection.Reason.VALIDATION_FAILED); return new Result<File>().addError(getText("attachfile.error.io.error", fileName, e.getMessage()), ErrorCollection.Reason.VALIDATION_FAILED);
ownerId, type); if (!tempAvatarResult.isValid()) return returnErrorMessagesAsHtml(tempAvatarResult.getErrorCollection().getErrorMessages()); final AvatarPickerHelperImpl.TemporaryAvatarBean temporaryAvatarBean = tempAvatarResult.getResult(); .convertTemporaryToReal(ownerId, type, selection); if (!conversionResult.isValid()) return returnErrorMessagesAsHtml(conversionResult.getErrorCollection().getErrorMessages()); + "<textarea>" + "{" + "\"id\": \"" + conversionResult.getResult().getId() + "\"" + "}" + "</textarea>"
validationResult.getSize(), ownerId, type); if (!tempAvatarResult.isValid()) throwWebException(tempAvatarResult.getErrorCollection()); final AvatarCroppingBean croppingInstructions = AvatarBeanFactory.createTemporaryAvatarCroppingInstructions(tempAvatarResult.getResult()); if (tempAvatarResult.getResult().isCroppingNeeded())
return new Result<TemporaryAvatarBean>().addError(null, ErrorCollection.Reason.FORBIDDEN); return new Result<TemporaryAvatarBean>().addError(getText("avatarpicker.upload.contenttype.no.ext.failure"), ErrorCollection.Reason.VALIDATION_FAILED); return new Result<TemporaryAvatarBean>().addError(getText("avatarpicker.upload.contenttype.failure"), ErrorCollection.Reason.VALIDATION_FAILED); if (!copyResult.isValid()) return new Result<TemporaryAvatarBean>(copyResult); final File file = copyResult.getResult(); final String invalidChars = new FileNameCharacterCheckerUtil().assertFileNameDoesNotContainInvalidChars(fileName); if (invalidChars == null) if (!scaledFile.isValid()) return new Result<TemporaryAvatarBean>(scaledFile); image = thumber.getImage(scaledFile.getResult(), Predicates.<ReusableBufferedInputStream>alwaysTrue()); TemporaryAvatar tempAvatar = new TemporaryAvatar(contentType, temporaryContentType, fileName, scaledFile.getResult(), null); ExecutingHttpRequest.get().getSession().setAttribute(SessionKeys.TEMP_AVATAR, tempAvatar); return new Result<TemporaryAvatarBean>(new TemporaryAvatarBean(getTemporaryAvatarUrl(), image.getWidth(null), image.getHeight(null), isCroppingNeeded(image))); return new Result<TemporaryAvatarBean>().addError(getText("avatarpicker.upload.filename.failure", invalidChars), ErrorCollection.Reason.VALIDATION_FAILED);
return new Result<Avatar>().addError(null, ErrorCollection.Reason.FORBIDDEN); return new Result<Avatar>().addError(getText("avatarpicker.upload.failure"), ErrorCollection.Reason.SERVER_ERROR); if (selection.getTopLeftX() < 0 || selection.getTopLeftY() < 0 || selection.getTopLeftX() > maxOffset || selection.getTopLeftY() > maxOffset) return new Result<Avatar>().addError(getText("avatarpicker.upload.failure"), ErrorCollection.Reason.VALIDATION_FAILED); return new Result<Avatar>().addError(getText("avatarpicker.upload.temp.io", e.getMessage()), ErrorCollection.Reason.SERVER_ERROR); return new Result<Avatar>(newAvatar);
.convertTemporaryToReal(ownerId, type, selection); if (!conversionResult.isValid()) throwWebException(conversionResult.getErrorCollection()); final AvatarBean avatarBean = AvatarBeanFactory.createAvatarBean(conversionResult.getResult());
new Result<File>().addError(getText("avatarpicker.upload.image.corrupted"), ErrorCollection.Reason.VALIDATION_FAILED); return new ResultAndContentTypeChanged(new Result<File>().addError(getText("avatarpicker.upload.image.corrupted"), ErrorCollection.Reason.VALIDATION_FAILED), false); if (sourceHeight * sourceWidth > (maxPixels * 1000000)) return new ResultAndContentTypeChanged(new Result<File>().addError(getText("avatarpicker.upload.too.big", maxPixels), ErrorCollection.Reason.VALIDATION_FAILED), false); return new ResultAndContentTypeChanged(new Result<File>(sourceFile), false);
private ResultAndContentTypeChanged cropImageToFile(final int edgeSize, final Image sourceImage) { Result<File> prescaledFile = createTemporaryFile(TEMP_FILE_EXTENSION); if (!prescaledFile.isValid()) { return new ResultAndContentTypeChanged(prescaledFile, false); } ThumbnailDimension dimensions = thumber.determineScaleSize(edgeSize, edgeSize, sourceImage.getWidth(null), sourceImage.getHeight(null)); BufferedImage scaledImage = thumber.scaleImage(sourceImage, dimensions); try { ImageIO.write(scaledImage, AVATAR_IMAGE_FORMAT, prescaledFile.getResult()); return new ResultAndContentTypeChanged(prescaledFile, true); } catch (IOException e) { return new ResultAndContentTypeChanged(new Result<File>().addError(getText("avatarpicker.upload.temp.io", e.getMessage()), ErrorCollection.Reason.SERVER_ERROR), false); } }
@Override public Result<TemporaryAvatarBean> cropTemporary(String ownerId, Avatar.Type type, Selection selection) { if (!isAllowedToPickAvatar(ownerId, type)) { return new Result<TemporaryAvatarBean>().addError(null, ErrorCollection.Reason.FORBIDDEN); } TemporaryAvatar temporaryAvatar = (TemporaryAvatar) ExecutingHttpRequest.get().getSession() .getAttribute(SessionKeys.TEMP_AVATAR); if (temporaryAvatar == null) { return new Result<TemporaryAvatarBean>().addError(getText("avatarpicker.upload.failure"), ErrorCollection.Reason.SERVER_ERROR); } TemporaryAvatar croppedAvatar = new TemporaryAvatar(temporaryAvatar.getContentType(), temporaryAvatar.getTemporaryContentType(), temporaryAvatar.getOriginalFilename(), temporaryAvatar.getFile(), selection); ExecutingHttpRequest.get().getSession().setAttribute(SessionKeys.TEMP_AVATAR, croppedAvatar); return new Result<TemporaryAvatarBean>(new TemporaryAvatarBean(getTemporaryAvatarUrl(), selection)); }
private Result<File> createTemporaryFile(String suffix) { try { final File tempFile = File.createTempFile(TEMP_FILE_PREFIX, suffix); tempFile.deleteOnExit(); return new Result<File>(tempFile); } catch (IOException e) { return new Result<File>().addError(getText("avatarpicker.upload.temp.fail"), ErrorCollection.Reason.SERVER_ERROR); } }
Result(Result<?> result) { errorCollection = result.getErrorCollection(); }
public Response cropTemporaryAvatar(final Avatar.Type type, final String ownerId, final AvatarCroppingBean croppingInstructions) { Selection selection = new Selection(croppingInstructions.getCropperOffsetX(), croppingInstructions.getCropperOffsetY(), croppingInstructions.getCropperWidth(), croppingInstructions.getCropperWidth()); AvatarPickerHelperImpl.Result<AvatarPickerHelperImpl.TemporaryAvatarBean> cropResult = avatarPickerHelper .cropTemporary(ownerId, type, selection); if (!cropResult.isValid()) { throwWebException(cropResult.getErrorCollection()); } return Response.status(Response.Status.OK).cacheControl(never()).build(); }