WordBuilder.java: #7869 - In exported file fix hidden question title and a. /b. /c for empty answers.
a. fix hidden question title when more than 1 multiplicity answers, b. fix hidden question title when no value in the last multiplicity answer, c. Do not show a. / b. / c.... for empty multiplicity answers, d. Do not show a. / b. / c.... when more than 1 multiplicity answers, but only one with value.
This commit is contained in:
parent
b1788c2dc2
commit
18e98938d5
|
@ -285,33 +285,59 @@ public class WordBuilder {
|
||||||
for (FieldSet compositeField: compositeFields) {
|
for (FieldSet compositeField: compositeFields) {
|
||||||
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
|
if (visibilityRuleService.isElementVisible(compositeField.getId()) && hasVisibleFields(compositeField, visibilityRuleService)) {
|
||||||
char c = 'a';
|
char c = 'a';
|
||||||
|
int multiplicityItems = 0;
|
||||||
boolean hasMultiplicityItems = false;
|
boolean hasMultiplicityItems = false;
|
||||||
int paragraphPos = -1;
|
int paragraphPos = -1;
|
||||||
|
int paragraphPosInner = -1;
|
||||||
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
||||||
XWPFParagraph paragraph = addParagraphContent("\t" + page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
XWPFParagraph paragraph = addParagraphContent("\t" + page + "." + section + "." + (compositeField.getOrdinal() +1) + " " + compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
number.setVal(BigInteger.valueOf(indent));
|
||||||
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
paragraphPos = mainDocumentPart.getPosOfParagraph(paragraph);
|
||||||
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
|
if(compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()){
|
||||||
addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
||||||
|
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
|
||||||
|
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
||||||
hasMultiplicityItems = true;
|
hasMultiplicityItems = true;
|
||||||
|
multiplicityItems++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
hasValue = createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
if(hasValue){
|
if(hasValue){
|
||||||
returnedValue = true;
|
returnedValue = true;
|
||||||
|
} else if(paragraphPosInner > -1){
|
||||||
|
mainDocumentPart.removeBodyElement(paragraphPosInner);
|
||||||
|
c--;
|
||||||
|
multiplicityItems--;
|
||||||
}
|
}
|
||||||
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
|
if (compositeField.getMultiplicityItems() != null && !compositeField.getMultiplicityItems().isEmpty()) {
|
||||||
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
|
List<FieldSet> list = compositeField.getMultiplicityItems().stream().sorted(Comparator.comparingInt(FieldSet::getOrdinal)).collect(Collectors.toList());
|
||||||
for (FieldSet multiplicityFieldset : list) {
|
for (FieldSet multiplicityFieldset : list) {
|
||||||
|
paragraphPosInner = -1;
|
||||||
if(!createListing){
|
if(!createListing){
|
||||||
c++;
|
c++;
|
||||||
addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
// addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.HEADER6, numId);
|
||||||
|
XWPFParagraph paragraphInner = addParagraphContent(c + ". ", mainDocumentPart, ParagraphStyle.TEXT, numId);
|
||||||
|
paragraphPosInner = mainDocumentPart.getPosOfParagraph(paragraphInner);
|
||||||
hasMultiplicityItems = true;
|
hasMultiplicityItems = true;
|
||||||
|
multiplicityItems++;
|
||||||
}
|
}
|
||||||
hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
// hasValue = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
if(hasValue){
|
boolean hasValueInner = createFields(multiplicityFieldset.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService, hasMultiplicityItems);
|
||||||
|
// if(hasValue){
|
||||||
|
if(hasValueInner){
|
||||||
|
hasValue = true;
|
||||||
returnedValue = true;
|
returnedValue = true;
|
||||||
|
} else if(paragraphPosInner > -1){
|
||||||
|
mainDocumentPart.removeBodyElement(paragraphPosInner);
|
||||||
|
c--;
|
||||||
|
multiplicityItems--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(multiplicityItems == 1) {
|
||||||
|
String text = mainDocumentPart.getLastParagraph().getRuns().get(0).getText(0);
|
||||||
|
if(text.equals("a. ")) {
|
||||||
|
mainDocumentPart.getLastParagraph().removeRun(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,6 +448,7 @@ public class WordBuilder {
|
||||||
if(hasMultiplicityItems && format != null){
|
if(hasMultiplicityItems && format != null){
|
||||||
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
mainDocumentPart.getLastParagraph().createRun().setText(format);
|
||||||
hasMultiplicityItems = false;
|
hasMultiplicityItems = false;
|
||||||
|
hasValue = true;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
|
XWPFParagraph paragraph = addParagraphContent(format, mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
|
||||||
|
@ -461,6 +488,7 @@ public class WordBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
|
public XWPFParagraph addParagraphContent(Object content, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
|
||||||
|
// this.indent = 0;
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
if (content instanceof String && ((String)content).isEmpty()) {
|
if (content instanceof String && ((String)content).isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue