vs72737 / xdocreport

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

Cannot allow inline macros with local scope #399

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

What steps will reproduce the problem?
1. Create a velocity library with one macro
2. create a docx template T1 overriding the macro and calling it
3. Create a docx template T2 calling the global macro

The velocity properties used are the following :

velocimacro.permissions.allow.inline.to.replace.global=true
velocimacro.permissions.allow.inline.local.scope=true
velocimacro.permissions.allowInline=true

What is the expected output? What do you see instead?
T1 display the content of the macro, T2 will display the call, not replaced : 
#d()

If velocimacro.permissions.allow.inline.local.scope is set to false, both 
templates will display the code wrote in template 1 (global macro is replaced)

What version of the product are you using? On what operating system?
Velocity 1.7
XDocReport 1.0.3 (I also tried with 1.0.4)
Windows 7, JDK 1.7.0_40

Please provide any additional information below.

Thanks a lot in advance, I cannot figure out why it does not work from 
XDocReport, when it works perfectly with a simple Velocity exemple.

Original issue reported on code.google.com by julie.no...@gmail.com on 12 May 2014 at 12:17

GoogleCodeExporter commented 8 years ago
To be honnest with you, I have never played with Velocity Macro inside 
XDocReport.

I sugest you to attach a basic sample with your problem and I will see your 
problem when I will have time.

Regards Angelo

Original comment by angelo.z...@gmail.com on 12 May 2014 at 12:28

GoogleCodeExporter commented 8 years ago
Thanks for your time !

Here is the attached sample code :

- TestVelocityMacro shows that it works with Velocity only
- TestXDocReportMacro tries to do the same with XDocReport : the global macro 
is not evaluated
- Both classes are in src/test

Thanks a lot !

Original comment by julie.no...@gmail.com on 12 May 2014 at 1:30

Attachments:

GoogleCodeExporter commented 8 years ago
I didn't use a mergefield in the docx file but I changed the xml directly in 
the archive... 

Original comment by julie.no...@gmail.com on 12 May 2014 at 1:36

GoogleCodeExporter commented 8 years ago
I finally overrided the processNoCache of the VelocityTemplateEngine to make it 
works... it seems that Velocity clean the provided namespace after each 
"evaluate". Providing the empty String "" will result in clearing the global 
namespace and all the macros. It works properly with a "LOCAL" namespace.

@Override
    protected void processNoCache(String entryName, IContext context, Reader reader, Writer writer)
            throws XDocReportException, IOException {
        VelocityEngine velocityEngine = getVelocityEngine();
        // Here use a local namespace name to avoid dumping the global namespace after each template
        velocityEngine.evaluate((VelocityContext) context, writer, "LOCAL", reader);
    }

Hope it can be integrated in an official release of XDocReport,

Regards,

Julie

Original comment by julie.no...@gmail.com on 23 May 2014 at 8:32

GoogleCodeExporter commented 8 years ago
Julie, could you explain me what is "LOCAL" namespace? Is it Velocity feature 
(perhaps it exists a Velocity constant for that).

Original comment by angelo.z...@gmail.com on 23 May 2014 at 8:47

GoogleCodeExporter commented 8 years ago
I am not sure I well understood how Velocity handle the namespaces... here, 
this value should be chosen by the caller.

It is described in the Javadoc as :
logTag string to be used as the template name for log messages in case of error

... and later in the velocity process as the template name itself, and at the 
end, as the namespace.

So I guess it is to defined a specific namespace for each template, and define 
values and macros inside that namespace.... Maybe the best value here would be 
entryName.

What is sure is that "" will override the global namespace.

Hope it helps !

Original comment by julie.no...@gmail.com on 23 May 2014 at 9:40

GoogleCodeExporter commented 8 years ago
Sorry Julie,

I was very busy. 

If we use entryName as template name (ex : word/document.xml) it means that all 
docx report will share the same name. Do you think there is a problem with that?

Perhaps we should use the reportId?

Original comment by angelo.z...@gmail.com on 7 Aug 2014 at 8:53

GoogleCodeExporter commented 8 years ago
I agree with you, it seems a good idea to use a reportId... but I didn't get 
any issue using the template name, maybe Velocity cleans the local cache 
between each evalutation.

Hope this can be integrated in a further release.

Thanks a lot,

Julie

Original comment by julie.no...@gmail.com on 15 Aug 2014 at 2:03

GoogleCodeExporter commented 8 years ago
Hi Julie,

Please see my commit at 
https://code.google.com/p/xdocreport/source/detail?r=14d83bd84d2d28462fab797dbed
e672916e4a70c

Now template engine (Velocity and Freemarker) uses the template name (reportId 
! entryName) for cache and no cache process.

Please test to tell me if it resolves your initial problem.

Thank's

Regard's Angelo

Original comment by angelo.z...@gmail.com on 18 Aug 2014 at 6:22