Added the validation that the answers given are valid strings and pictures

android-scanner
VladimirEliTokarev 2016-10-28 20:02:27 +03:00
parent e440bb3e76
commit fbc1707b37
1 changed files with 24 additions and 0 deletions

View File

@ -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;
}