diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/VotingBoothConfiguration.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/VotingBoothConfiguration.java index 2e312e8..fde3d63 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/VotingBoothConfiguration.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/configuration/VotingBoothConfiguration.java @@ -1,6 +1,12 @@ package meerkat.voting.gui.configuration; + +import com.google.protobuf.ByteString; +import javafx.embed.swing.SwingFXUtils; import meerkat.protobuf.BallotQuestionUIElementOuterClass; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; + /** * Created by Vladimir Eliezer Tokarev on 10/1/2016. * This object contains all the questions and configurations needed for the voting-booth-gui work @@ -28,6 +34,24 @@ public class VotingBoothConfiguration { BallotQuestionUIElementOuterClass.ValueType.forNumber(NameSelectionQuestion.getAnswers().getAnswersType()) == null ){ return false; } + // Check that all the given answers are valid bte strings that can be converted into strings + for (ByteString answer: NameSelectionQuestion.getAnswers().getAnswers().getAnswersList()){ + try { + String strAnswer = answer.toStringUtf8(); + } catch (Exception e){ + return false; + } + } + // Check that all given byteStrings that are pictures can be converted into pictures + for (ByteString answer :NameSelectionByPictureQuestion.getAnswers().getAnswers().getAnswersList()){ + try { + BufferedImage bufferedImage = ImageIO.read(answer.newInput()); + SwingFXUtils.toFXImage(bufferedImage, null); + } catch (Exception e) { + return false; + } + } + return true; }