}
public ActionForward photoUpload(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {
PhotographUploadBean photo = getRenderedObject();
RenderUtils.invalidateViewState();
String base64Thumbnail = request.getParameter("encodedThumbnail");
String base64Image = request.getParameter("encodedPicture");
if (base64Image != null && base64Thumbnail != null) {
DateTime now = new DateTime();
photo.setFilename("mylovelypic_" + now.getYear() + now.getMonthOfYear() + now.getDayOfMonth() + now.getHourOfDay()
+ now.getMinuteOfDay() + now.getSecondOfMinute() + ".png");
photo.setBase64RawContent(base64Image.split(",")[1]);
photo.setBase64RawThumbnail(base64Thumbnail.split(",")[1]);
photo.setContentType(base64Image.split(",")[0].split(":")[1].split(";")[0]);
}
ActionMessages actionMessages = new ActionMessages();
if (photo.getFileInputStream() == null) {
actionMessages.add("error", new ActionMessage("errors.fileRequired"));
saveMessages(request, actionMessages);
return preparePhotoUpload(mapping, actionForm, request, response);
}
if (ContentType.getContentType(photo.getContentType()) == null) {
actionMessages.add("error", new ActionMessage("errors.unsupportedFile"));
saveMessages(request, actionMessages);
return preparePhotoUpload(mapping, actionForm, request, response);
}
if (photo.getRawSize() > MAX_RAW_SIZE) {
actionMessages.add("error", new ActionMessage("errors.fileTooLarge"));
saveMessages(request, actionMessages);
photo.deleteTemporaryFiles();
return preparePhotoUpload(mapping, actionForm, request, response);
}
try {
photo.processImage();
} catch (UnableToProcessTheImage e) {
actionMessages.add("error", new ActionMessage("errors.unableToProcessImage"));
saveMessages(request, actionMessages);
photo.deleteTemporaryFiles();
return preparePhotoUpload(mapping, actionForm, request, response);
}
try {
updatePersonPhoto(photo);
} catch (Exception e) {
actionMessages.add("error", new ActionMessage("errors.unableToSaveImage"));
saveMessages(request, actionMessages);
photo.deleteTemporaryFiles();
return preparePhotoUpload(mapping, actionForm, request, response);
}
actionMessages.add("success", new ActionMessage("label.operator.submit.ok", ""));
saveMessages(request, actionMessages);