Author: ymartel Date: 2012-06-19 10:52:49 +0200 (Tue, 19 Jun 2012) New Revision: 3520 Url: http://chorem.org/repositories/revision/pollen/3520 Log: fix #596 : on image choice, only accept image/* mimetype file for upload Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-19 08:18:29 UTC (rev 3519) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-19 08:52:49 UTC (rev 3520) @@ -891,7 +891,24 @@ addInformationsError( choiceErrorField, _("pollen.error.poll.imageChoice.upload.badContentType")); - //TODO ymartel 2012/06/18 + //Remove the file and its thumb + PollImageChoice imageChoice = (PollImageChoice) choice; + File imageFile = new File(imageChoice.getLocation()); + File imageThumbFile = getPollService().getImageThumbFile(imageFile); + FileUtils.deleteQuietly(imageThumbFile); + FileUtils.deleteQuietly(imageFile); + // The choice has no more location + String choiceId = imageChoice.getTopiaId(); + if (StringUtils.isBlank(choiceId)) { + imageChoice.setLocation(null); + // As the name of the choice is the fileName, remove it too. + imageChoice.setName(null); + } else { + // in case of update, get back the old values for name and location and keep the old choice + PollImageChoice pollChoice = (PollImageChoice) poll.getChoiceByTopiaId(choiceId); + imageChoice.setName(pollChoice.getName()); + imageChoice.setLocation(pollChoice.getLocation()); + } continue; } }