Discussion:
Velocity and XML as context
Angelo zerr
2012-01-25 14:19:24 UTC
Permalink
Hi Velocity Team,

I'm one of developer of XDocReport <http://code.google.com/p/xdocreport/>which
is Java reporting API to generate docx, odt, pptx etc from a docx, odt,
pptx by using Velocity and Freemarker syntax to set the fields to replace,
manage loop etc...
Goal of XDocReport is to create reporting with MS Word or OpenOffice and
use Velocity/Freemarker interpolation and directive. So the report is very
simply to create.

Velocity integration with XDocReport works great and very performant (I had
implemented my own Velocity cache).

I would like use XML DOM as Java context (insteaod of Java POJO context).
When I serach XML+Velocity in google I find :

* DVSL : http://velocity.apache.org/dvsl/releases/dvsl-1.0/users-guide.html
* Anakia : http://velocity.apache.org/engine/devel/anakia.html

As I have said, goal of XDocReport is to simplify the reporting creation
and if I want to use XML as Java context with Velocity It seems I must use
Anakia and I find it's not very easy to write the fields (more there is a
new dependency to JDOM).
You must write that with Velocity Anakia :

------------------------------------------------------------------------------------------------------
#set ($customMenus = $xpath.applyTo("body/menu",$customContext))
#foreach($customMenu in $customMenus)
<strong>$customMenu.getAttributeValue("name")</strong>
#end
------------------------------------------------------------------------------------------------------

With Freemarker I find it's more easy :

------------------------------------------------------------------------------------------------------
[#list doc.body.menu as m]
<strong>${***@name}</strong>
[/#list]
------------------------------------------------------------------------------------------------------

So I would like know if it's possible to do that with Velocity, if I can
implement my own DOM-Wrapper to manage this syntax.

Thank a lot for your help.

Regards Angelo
Nathan Bubna
2012-01-25 15:02:21 UTC
Permalink
You might prefer the syntax provided by the XmlTool (in the
VelocityTools project)

http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/XmlTool.html

I much prefer it to Anakia and DVSL for simply navigating/reading xml
files in a template.
Post by Angelo zerr
Hi Velocity Team,
I'm one of developer of XDocReport <http://code.google.com/p/xdocreport/>which
is Java reporting API to generate docx, odt, pptx etc from a docx, odt,
pptx by using Velocity and Freemarker syntax to set the fields to replace,
manage loop etc...
Goal of XDocReport is to create reporting with MS Word or OpenOffice and
use Velocity/Freemarker interpolation and directive. So the report is very
simply to create.
Velocity integration with XDocReport works great and very performant (I had
implemented my own Velocity cache).
I would like use XML DOM as Java context (insteaod of Java POJO context).
 * DVSL : http://velocity.apache.org/dvsl/releases/dvsl-1.0/users-guide.html
* Anakia : http://velocity.apache.org/engine/devel/anakia.html
As I have said, goal of XDocReport is to simplify the reporting creation
and if I want to use XML as Java context with Velocity It seems I must use
Anakia and I find it's not very easy to write the fields (more there is a
new dependency to JDOM).
------------------------------------------------------------------------------------------------------
#set ($customMenus = $xpath.applyTo("body/menu",$customContext))
#foreach($customMenu in $customMenus)
 <strong>$customMenu.getAttributeValue("name")</strong>
#end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
[#list doc.body.menu as m]
[/#list]
------------------------------------------------------------------------------------------------------
So I would like know if it's possible to do that with Velocity, if I can
implement my own DOM-Wrapper to manage this syntax.
Thank a lot for your help.
Regards Angelo
Angelo zerr
2012-01-26 00:33:25 UTC
Permalink
Hi Nathan,

Thank a lot to answer me. I will study XmlTool.

Thanks.

Regards Angelo
Post by Nathan Bubna
You might prefer the syntax provided by the XmlTool (in the
VelocityTools project)
http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/XmlTool.html
I much prefer it to Anakia and DVSL for simply navigating/reading xml
files in a template.
Post by Angelo zerr
Hi Velocity Team,
I'm one of developer of XDocReport <http://code.google.com/p/xdocreport/
which
is Java reporting API to generate docx, odt, pptx etc from a docx, odt,
pptx by using Velocity and Freemarker syntax to set the fields to
replace,
Post by Angelo zerr
manage loop etc...
Goal of XDocReport is to create reporting with MS Word or OpenOffice and
use Velocity/Freemarker interpolation and directive. So the report is
very
Post by Angelo zerr
simply to create.
Velocity integration with XDocReport works great and very performant (I
had
Post by Angelo zerr
implemented my own Velocity cache).
I would like use XML DOM as Java context (insteaod of Java POJO context).
http://velocity.apache.org/dvsl/releases/dvsl-1.0/users-guide.html
Post by Angelo zerr
* Anakia : http://velocity.apache.org/engine/devel/anakia.html
As I have said, goal of XDocReport is to simplify the reporting creation
and if I want to use XML as Java context with Velocity It seems I must
use
Post by Angelo zerr
Anakia and I find it's not very easy to write the fields (more there is a
new dependency to JDOM).
------------------------------------------------------------------------------------------------------
Post by Angelo zerr
#set ($customMenus = $xpath.applyTo("body/menu",$customContext))
#foreach($customMenu in $customMenus)
<strong>$customMenu.getAttributeValue("name")</strong>
#end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
Post by Angelo zerr
[#list doc.body.menu as m]
[/#list]
------------------------------------------------------------------------------------------------------
Post by Angelo zerr
So I would like know if it's possible to do that with Velocity, if I can
implement my own DOM-Wrapper to manage this syntax.
Thank a lot for your help.
Regards Angelo
---------------------------------------------------------------------
Loading...