StimVinsh / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Conditional statements with string comparison in docx with freemarker #29

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When using freemarker and a docx template the " characters in the merge field 
are escaped to \" resulting in a parse exception:
freemarker.core.ParseException: Token manager error: 
freemarker.core.TokenMgrError: Lexical error at line x, column y.  Encountered: 
"\"" (34), after : "\\" in 
fr.opensagres.xdocreport.document.docx.DocXReport@18e2b22!word/document.xml

[#if project.numberAsInt = 1]one[#else]not one[/#if] - Works fine

[#if project.numberAsString = "one"]1[#else]not 1[/#if] - Fails

document.xml contains
MERGEFIELD  "[#if project.numberAsString == \"one\"]1[#else]not 1[/#if]"  \* 
MERGEFORMAT

If the " characters are replaced with ' characters in the merge field the 
generated document.xml looks OK but there is still a parse exception 
freemarker.core.ParseException: Encountered "&" at line...

Original issue reported on code.google.com by eamon.wa...@evaluefe.com on 3 Aug 2011 at 6:17

GoogleCodeExporter commented 8 years ago
Hi eamon,

Thank a lot for having create this issue. I will do study the problem. Is it 
possible to attach your docx please with this problem?

Thanks

Regards Angelo

Original comment by angelo.z...@gmail.com on 3 Aug 2011 at 10:01

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 3 Aug 2011 at 10:44

GoogleCodeExporter commented 8 years ago
docx which gives error

Original comment by eamon.wa...@evaluefe.com on 4 Aug 2011 at 8:08

Attachments:

GoogleCodeExporter commented 8 years ago
Hi eamon,

Thank a lot for your TesTemplate.docx. Could you attach too your problem with 
simple quote please. I have not problem with simple quote?

I have fixed the problem with double quote. I have tested with your 
TestTemplate.docx and it works well.

I have created several JUnit for that : 

1) 
http://xdocreport.googlecode.com/svn/trunk/integrationtests/fr.opensagres.xdocre
port.core.test/src/test/java/fr/opensagres/xdocreport/document/docx/preprocessor
/DocxPreprocessorMergefieldWithConditionTestCase.java where you can see XML 
docx with simple and double quote.

2) 
http://xdocreport.googlecode.com/svn/trunk/integrationtests/fr.opensagres.xdocre
port.core.test/src/test/java/fr/opensagres/xdocreport/examples/docx/DocxConditio
nnalWithFreemarker.java which is basic sampel with Freemarker condition with 
simple and double quote which use the docx 
http://xdocreport.googlecode.com/svn/trunk/integrationtests/fr.opensagres.xdocre
port.core.test/src/test/resources/fr/opensagres/xdocreport/examples/docx/DocxCon
ditionnalWithFreemarker.docx

I'm waiting for your another docx with simple quote to fix the problem with 
simple quote and I will close this bug.

Regards Angelo

Original comment by angelo.z...@gmail.com on 4 Aug 2011 at 8:22

GoogleCodeExporter commented 8 years ago
Hi Angelo,
I was editing the file back and forth between single and double quotes. When I 
created a new file with single quotes the error did not occur. I still see the 
error when using one of the docx files I created yesterday but cannot attach 
that to this bug due to the content in the file, sorry. It seems that the file 
is somehow invalid but MS word opens the file ignoring the invalid content. If 
I can work out the steps to replicate the issue I will let you know.

Regards Eamon

Original comment by eamon.wa...@evaluefe.com on 4 Aug 2011 at 9:59

GoogleCodeExporter commented 8 years ago
Ok Eamon,

XDocReport 0.9.1 will fix your problem, which is planned for the end of this 
month. For the moment you can get sources from SVN or download at 
http://oss.sonatype.org/content/repositories/snapshots/fr/opensagres/ if you 
wish test it.

Regards Angelo

Original comment by angelo.z...@gmail.com on 4 Aug 2011 at 1:06

GoogleCodeExporter commented 8 years ago
I have replicated the single quote issue. The two files attached both contain 
the same merge field. The first file contains only the merge field and works 
fine. The second contains a table with some formatted text and the merge field 
and fails.

The volume of markup around the merge field appears to cause the error

Error log:

freemarker.core.ParseException: Encountered "&" at line 2, column 2665 in 
fr.opensagres.xdocreport.document.docx.DocXReport@18e2b22!word/document.xml.
Was expecting one of:
    <STRING_LITERAL> ...
    <RAW_STRING> ...
    "false" ...
    "true" ...
    <INTEGER> ...
    <DECIMAL> ...
    "." ...
    "+" ...
    "-" ...
    "!" ...
    "[" ...
    "(" ...
    "{" ...
    <ID> ...

    at freemarker.core.FMParser.generateParseException(FMParser.java:4697)
    at freemarker.core.FMParser.jj_consume_token(FMParser.java:4568)
    at freemarker.core.FMParser.UnaryExpression(FMParser.java:323)
    at freemarker.core.FMParser.MultiplicativeExpression(FMParser.java:435)
    at freemarker.core.FMParser.AdditiveExpression(FMParser.java:385)
    at freemarker.core.FMParser.RangeExpression(FMParser.java:556)
    at freemarker.core.FMParser.RelationalExpression(FMParser.java:511)
    at freemarker.core.FMParser.EqualityExpression(FMParser.java:494)
    at freemarker.core.FMParser.AndExpression(FMParser.java:585)
    at freemarker.core.FMParser.OrExpression(FMParser.java:608)
    at freemarker.core.FMParser.Expression(FMParser.java:221)
    at freemarker.core.FMParser.If(FMParser.java:1170)
    at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2372)
    at freemarker.core.FMParser.Content(FMParser.java:2618)
    at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
    at freemarker.core.FMParser.Escape(FMParser.java:2302)
    at freemarker.core.FMParser.FreemarkerDirective(FMParser.java:2445)
    at freemarker.core.FMParser.Content(FMParser.java:2618)
    at freemarker.core.FMParser.OptionalBlock(FMParser.java:2786)
    at freemarker.core.FMParser.Root(FMParser.java:2958)
    at freemarker.template.Template.<init>(Template.java:149)
    at freemarker.cache.TemplateCache.loadTemplate(TemplateCache.java:457)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:370)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:238)
    at freemarker.template.Configuration.getTemplate(Configuration.java:493)
    at freemarker.template.Configuration.getTemplate(Configuration.java:458)
    at fr.opensagres.xdocreport.template.freemarker.FreemarkerTemplateEngine.processWithCache(FreemarkerTemplateEngine.java:84)
    at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:97)
    at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:75)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:602)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:406)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.process(AbstractXDocReport.java:374)

Original comment by eamon.wa...@evaluefe.com on 5 Aug 2011 at 9:40

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Eamon,

I have fixed your problem with simple quote in the SVN.

Regards Angelo

Original comment by angelo.z...@gmail.com on 5 Aug 2011 at 1:08

GoogleCodeExporter commented 8 years ago
I have a complex data structure which at its most basic is a list within a
list. Is it possible to add the inner list as a FieldsMetadata element and
loop over the inner list in a table? eg
metadata.addFieldAsList("list.innerlist.data1");
metadata.addFieldAsList("list.innerlist.data2");
Then use the loop functionality to iterate over the first list generating
a table and each inner list generating the rows within each table.

I would also like to be able to generate a table with an unknown number of
columns, repeating over the elements in a list creating a new table cell
for each element. Similar to the row loop functionality but applied to
table cells.

Both of these approaches are possible using the '@' and '@/' notation in
JOD reports, see http://jodreports.sourceforge.net/?q=node/26, but I am
struggling to get the same results using xdoc.

Eamon Walls

eValue
+44 (0)7917 897 805
eamon.walls@evaluefe.com
www.evaluefe.com
Notice of Confidentiality
This transmission contains information that may be confidential. It has been 
prepared for the sole and exclusive use of the intended recipient and on the 
basis agreed with that person. If you are not the intended recipient of the 
message (or authorised to receive it for the intended recipient), you should 
notify us immediately; you should delete it from your system and may not 
disclose its contents to anyone else.
eValue FE Limited is a limited liability company registered in 
England and Wales under registered number 07382500.

The registered address of eValue FE Limited is Lambourn House, Newbury Business 
Park, Newbury, Berkshire RG14 2RE.

Original comment by eamon.wa...@evaluefe.com on 31 Aug 2011 at 6:17

GoogleCodeExporter commented 8 years ago
Hi Eamon, 

I close this issue and I have created a new issue 
http://code.google.com/p/xdocreport/issues/detail?id=36 (Manage complex table) 
for your last requirement because it's an other subject than this issue.

Regards Angelo

Original comment by angelo.z...@gmail.com on 1 Sep 2011 at 7:13

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 1 Sep 2011 at 7:13