diff --git a/src/main/java/com/ec/survey/tools/export/OdfExportCreator.java b/src/main/java/com/ec/survey/tools/export/OdfExportCreator.java index 087f2f30c..804e6d93d 100644 --- a/src/main/java/com/ec/survey/tools/export/OdfExportCreator.java +++ b/src/main/java/com/ec/survey/tools/export/OdfExportCreator.java @@ -503,8 +503,12 @@ private void parseAnswerSet(AnswerSet answerSet, List answerrow, Publica if (answerSet == null) { - cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter))); - cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++))); + String v = answerrow.get(answerrowcounter++); + if (v != null && v.length() > 0) + { + cell.setStringValue(ConversionTools.removeHTMLNoEscape(v)); + cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v)); + } } else { List answers = answerSet.getAnswers(matrixQuestion.getId(), matrixQuestion.getUniqueId()); @@ -528,8 +532,12 @@ private void parseAnswerSet(AnswerSet answerSet, List answerrow, Publica cell = sheet.getCellByPosition(columnIndex++, rowIndex); if (answerSet == null) { - cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter))); - cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++))); + String v = answerrow.get(answerrowcounter++); + if (v != null && v.length() > 0) + { + cell.setStringValue(ConversionTools.removeHTMLNoEscape(v)); + cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v)); + } } else { List answers = answerSet.getAnswers(childQuestion.getId(), childQuestion.getUniqueId()); @@ -622,8 +630,12 @@ private void parseAnswerSet(AnswerSet answerSet, List answerrow, Publica cell = sheet.getCellByPosition(columnIndex++, rowIndex); if (answerSet == null) { - cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter))); - cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++))); + String v = answerrow.get(answerrowcounter++); + if (v != null && v.length() > 0) + { + cell.setStringValue(ConversionTools.removeHTMLNoEscape(v)); + cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v)); + } } else { String answer = answerSet.getTableAnswer(table, tableRow, tableCol, false); if (answer == null) answer = ""; @@ -638,8 +650,12 @@ private void parseAnswerSet(AnswerSet answerSet, List answerrow, Publica cell = sheet.getCellByPosition(columnIndex++, rowIndex); if (answerSet == null) { - cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter))); - cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++))); + String v = answerrow.get(answerrowcounter++); + if (v != null && v.length() > 0) + { + cell.setStringValue(ConversionTools.removeHTMLNoEscape(v)); + cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v)); + } } else { List answers = answerSet.getAnswers(question.getId(), question.getUniqueId()); @@ -718,8 +734,12 @@ private void parseAnswerSet(AnswerSet answerSet, List answerrow, Publica cell = sheet.getCellByPosition(columnIndex++, rowIndex); if (answerSet == null) { - cell.setStringValue(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter))); - cell.setDisplayText(ConversionTools.removeHTMLNoEscape(answerrow.get(answerrowcounter++))); + String v = answerrow.get(answerrowcounter++); + if (v != null && v.length() > 0) + { + cell.setStringValue(ConversionTools.removeHTMLNoEscape(v)); + cell.setDisplayText(ConversionTools.removeHTMLNoEscape(v)); + } } else { List answers = answerSet.getAnswers(question.getId(), question.getUniqueId()); diff --git a/src/main/java/com/ec/survey/tools/export/XmlExportCreator.java b/src/main/java/com/ec/survey/tools/export/XmlExportCreator.java index 647bb7edd..89f9bf34d 100644 --- a/src/main/java/com/ec/survey/tools/export/XmlExportCreator.java +++ b/src/main/java/com/ec/survey/tools/export/XmlExportCreator.java @@ -794,44 +794,47 @@ void parseAnswerSet(Survey survey, XMLStreamWriter writer, List questio } else { String sanswers = row.get(answerrowcounter++); - String[] answers = sanswers.split(";"); - for (String answer : answers) - { - if (answer.length() > 0) { - writer.writeStartElement("Answer"); - writer.writeAttribute("qid", question.getUniqueId()); - if (question instanceof ChoiceQuestion) - { - writer.writeAttribute("aid", answer); - } else if (question instanceof Upload) - { - StringBuilder text = new StringBuilder(); - File file; - try { - - if (answer.contains("|")) - { - answer = answer.substring(0, answer.indexOf("|")); - } - - file = fileService.get(answer); - if (!uploadedFilesByQuestionUID.containsKey(question.getUniqueId())) - { - uploadedFilesByQuestionUID.put(question.getUniqueId(), new ArrayList<>()); + + if (sanswers != null) { + String[] answers = sanswers.split(";"); + for (String answer : answers) + { + if (answer.length() > 0) { + writer.writeStartElement("Answer"); + writer.writeAttribute("qid", question.getUniqueId()); + if (question instanceof ChoiceQuestion) + { + writer.writeAttribute("aid", answer); + } else if (question instanceof Upload) + { + StringBuilder text = new StringBuilder(); + File file; + try { + + if (answer.contains("|")) + { + answer = answer.substring(0, answer.indexOf("|")); + } + + file = fileService.get(answer); + if (!uploadedFilesByQuestionUID.containsKey(question.getUniqueId())) + { + uploadedFilesByQuestionUID.put(question.getUniqueId(), new ArrayList<>()); + } + uploadedFilesByQuestionUID.get(question.getUniqueId()).add(file); + + text.append((text.length() > 0) ? ";" : "").append(file.getName()); + } catch (FileNotFoundException e) { + logger.error(e.getLocalizedMessage(), e); } - uploadedFilesByQuestionUID.get(question.getUniqueId()).add(file); - text.append((text.length() > 0) ? ";" : "").append(file.getName()); - } catch (FileNotFoundException e) { - logger.error(e.getLocalizedMessage(), e); + writer.writeCharacters(text.toString()); + } else { + writer.writeCharacters(ConversionTools.removeInvalidHtmlEntities(answer)); } - writer.writeCharacters(text.toString()); - } else { - writer.writeCharacters(ConversionTools.removeInvalidHtmlEntities(answer)); + writer.writeEndElement(); //Answer } - - writer.writeEndElement(); //Answer } } }