StimVinsh / xdocreport

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

Problem processing the docx as Velocity Template #89

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1.Take the attached docx file
2.Try to parse it
3. Will throw exception

What is the expected output? What do you see instead?
Exception in thread "main" org.apache.velocity.exception.ParseErrorException: 
Lexical error,   Encountered: "<" (60), after : "" at 
fr.opensagres.xdocreport.document.docx.DocxReport@5099681b!word/document.xml[lin
e 1, column 1578]
        at org.apache.velocity.Template.process(Template.java:151)
        at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:437)
        at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
        at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
        at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:392)
        at fr.opensagres.xdocreport.template.velocity.VelocityTemplateEngine.processWithCache(VelocityTemplateEngine.java:89)
        at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:110)
        at fr.opensagres.xdocreport.template.AbstractTemplateEngine.process(AbstractTemplateEngine.java:82)
        at fr.opensagres.xdocreport.document.AbstractXDocReport.processTemplateEngine(AbstractXDocReport.java:739)

What version of the product are you using? On what operating system?
0.9.6 on Linux

Please provide any additional information below.

Original issue reported on code.google.com by mingkem...@yahoo.com on 13 Mar 2012 at 12:05

Attachments:

GoogleCodeExporter commented 8 years ago
Your case is when you type $ in the docx. I think that should be forbidden 
because $ crashes the Velocity. If you have some idea to resolve that, don't 
hesitate.

Regards Angelo

Original comment by angelo.z...@gmail.com on 13 Mar 2012 at 12:52

GoogleCodeExporter commented 8 years ago
The $ happen to be a dollar sign for cash amount, which unfortunately is going 
to occur in many documents.   I thought  XDocReport only supposed to  parse 
stuff
that is a MergeField ?  If the $ sign is not in the Merge field, is it possible 
to replace
it with some other encoding(or put a empty space behind it), to escape the $ 
sign ? 

I guess this is also a velocity issue, in that it should not recognize "$___" 
as a special 
tokens, and should just ignore it as plain strings.

Thanks.

Original comment by mingkem...@yahoo.com on 13 Mar 2012 at 3:15

GoogleCodeExporter commented 8 years ago
Hi,

I understand your need, so I have implemented your idea with Freemarker and 
Velocity for docx+odt where template engine is evaluated only for mergefield 
(for Velocity, #[[ ]]# is used and for Freemarker [#noparse][/#noparse]).

By default, the whole XML entry (ex: word/document.xml for Docx, content.xml 
for ODT, etc) is evaluated by the template engine. If you wish evaluate only 
directive coming from mergefield, you must customize FieldsMetadata like this : 

------------------------------------------------------------------
FieldsMetadata metadata = report.createFieldsMetadata();
metadata.setEvaluateEngineOnlyForFields( true );
------------------------------------------------------------------

I have tested with your docx and it works. This feature is commited on Git. 

Regards Angelo

Original comment by angelo.z...@gmail.com on 13 Mar 2012 at 2:40

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 27 Mar 2012 at 9:40