Skip to content

Commit

Permalink
PL-6625 Incorrect output for DOCX template with fields from other ban…
Browse files Browse the repository at this point in the history
…ds in table
  • Loading branch information
tinhol committed Feb 19, 2016
1 parent 8aef948 commit 084780c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import java.util.regex.Pattern;

public abstract class AbstractFormatter implements ReportFormatter {
public static final String SIMPLE_ALIAS_REGEXP = "\\$\\{([A-z0-9_]+?)\\}";

public static final String ALIAS_GROUP = "([A-z0-9_\\.]+?)";
public static final String STRING_FUNCTION_GROUP = "(\\[\\d+\\])";
public static final String ALIAS_GROUP = "([A-z0-9_\\.#]+?)";
public static final String UNIVERSAL_ALIAS_REGEXP = "\\$\\{" + ALIAS_GROUP + " *" + STRING_FUNCTION_GROUP + "?\\}";
public static final String ALIAS_WITH_BAND_NAME_REGEXP = "\\$\\{([A-z0-9_\\.]+?#?[A-z0-9_\\.]+?) *(\\[\\d+\\])?\\}";
public static final String ALIAS_WITH_BAND_NAME_REGEXP = UNIVERSAL_ALIAS_REGEXP;
public static final String BAND_NAME_DECLARATION_REGEXP = "##band=([A-z_0-9]+) *";

public static final Pattern UNIVERSAL_ALIAS_PATTERN = Pattern.compile(UNIVERSAL_ALIAS_REGEXP, Pattern.CASE_INSENSITIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ protected void collectHeadersAndFooters() {//collect data from headers
}
}

protected void collectTexts() {TextVisitor collectAliasesCallback = new TextVisitor(docxFormatter);
protected void collectTexts() {
TextVisitor collectAliasesCallback = new TextVisitor(docxFormatter);
new TraversalUtil(mainDocumentPart, collectAliasesCallback);
texts = collectAliasesCallback.textWrappers;
}

protected void collectTables() {TableCollector collectTablesCallback = new TableCollector(docxFormatter);
protected void collectTables() {
TableCollector collectTablesCallback = new TableCollector(docxFormatter);
new TraversalUtil(mainDocumentPart, collectTablesCallback);
tables = collectTablesCallback.tableManagers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public List<Object> apply(Object object) {
RegexpFinder aliasFinder = new RegexpFinder<P>(docxFormatter, AbstractFormatter.UNIVERSAL_ALIAS_PATTERN, P.class);
new TraversalUtil(currentRow, aliasFinder);

if (aliasFinder.getValue() != null) {
String foundAlias = aliasFinder.getValue();
if (foundAlias != null && foundAlias.matches(AbstractFormatter.SIMPLE_ALIAS_REGEXP)) {
currentTable.rowWithAliases = currentRow;
}
}
Expand Down
30 changes: 30 additions & 0 deletions core/modules/core/test/smoketest/DocxSpecificTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ public void testDocxTableWithSplittedBandAlias() throws Exception {
IOUtils.closeQuietly(outputStream);
}

@Test
public void testDocxTableWithAliasInHeader() throws Exception {
BandData root = new BandData("Root", null, BandOrientation.HORIZONTAL);
HashMap<String, Object> rootData = new HashMap<String, Object>();
root.setData(rootData);
BandData price = new BandData("Price", root, BandOrientation.HORIZONTAL);
price.setData(new RandomMap());
root.addChild(price);
BandData price2 = new BandData("Price", root, BandOrientation.HORIZONTAL);
price2.setData(new RandomMap());
root.addChild(price2);
BandData price3 = new BandData("Price", root, BandOrientation.HORIZONTAL);
price3.setData(new RandomMap());
root.addChild(price3);
BandData price4 = new BandData("Price", root, BandOrientation.HORIZONTAL);
price4.setData(new RandomMap());
root.addChild(price4);
BandData info = new BandData("Info", root, BandOrientation.HORIZONTAL);
info.setData(new RandomMap());
root.addChild(info);


FileOutputStream outputStream = new FileOutputStream("./result/smoke/TemplateRateBook.docx");
ReportFormatter formatter = new DefaultFormatterFactory().createFormatter(new FormatterFactoryInput("docx", root,
new ReportTemplateImpl("", "./modules/core/test/smoketest/TemplateRateBook.docx", "./modules/core/test/smoketest/TemplateRateBook.docx", ReportOutputType.docx), outputStream));
formatter.renderDocument();

IOUtils.closeQuietly(outputStream);
}


@Test
public void testDocxWithSplittedAlias() throws Exception {
Expand Down

0 comments on commit 084780c

Please sign in to comment.