Open matthiasbasler opened 4 years ago
I changed the FreeMarker syntax in the template back to square brackets and to my surprise the PDF document was again created well. Which means, that the Configuration.ANGLE_BRACKET_TAG_SYNTAX
flag has no effect. Further investigation shows that fr.opensagres.xdocreport.template.freemarker.FreemarkerTemplateEngine.setFreemarkerConfiguration(Configuration)
overwrites my tag syxtax flag with Configuration.SQUARE_BRACKET_TAG_SYNTAX
, so no surprise it isn't working.
Can anyone please explain to me why there is a FM syntax configuration flag if the API overwrites it to whatever it considers right?
I have following suggestions here:
final Configuration fmConfig = new Configuration(Configuration.VERSION_2_3_28);
((FreemarkerTemplateEngine) report.getTemplateEngine()).setFreemarkerConfiguration(fmConfig);
// Set the flag afterwards, so it really gets respected
fmConfig.setTagSyntax(Configuration.ANGLE_BRACKET_TAG_SYNTAX);
In this case I get a stange error about Freemarker failing to parse the expression "${___info.imageId}" - no idea where this comes from, but certainly not from the content of my template.
Sorry, accidentially closed -> reopened.
We are using XDocreport 2.0.1 in order to parse "docx" files and fill out certain fields - the typical "Mail Merge" functionality. We use the "xwpf" converter to finally create a PDF out of it. So far we have been using the square bracket Freemarker syntax, e.g. [#if ...] [/#if] and this worked. Since we are using the angle bracket Freemarker Syntax in the rest of our application we wanted to switch XDocreport over as well. There is a configuration setting to do so. So we set
Of course we changed the syntax of the template .docx file as well, e.g.
<#if applicant_houseNumber?hasContent> ${applicant_houseNumber}</#if>
Afterwards, we get a
SAXParseException
before XDocReport even reaches our template model. As far as I can conclude from the stack trace (see below) and the parser state when the exception is thrown, the Xerces SAX parser tries to evaluate the mergefield content <#if ...> and chokes on this because it thinks "<#" is not a valid XML tag. It certainly isn't, but the document parser should not even try to parse the content of a merge field as XML imho.Unfortunately there is little to find regarding the
Configuration.ANGLE_BRACKET_TAG_SYNTAX
flag on the web, so I wonder if I overlooked something or whether this is a bug.The stack trace (abbreviated to relevant classes) is as follows: