Mark-12345 | 9 Feb 23:47
Picon
Gravatar

Dynamic Templates


I thought I would share the following code with the Apache Velocity
community.

Problem Description:  I wanted to use Dynamic Templates though I found the
following had massive performance implications.

-- Velocity Call Snippet --
String template = "message.to:  ${message.to} ";
StringWriter velocityWriter = new StringWriter();
velocityEngine.evaluate( velocityContext, velocityWriter, "LOG", template );
return velocityWriter.toString();
-- Velocity Call Snippet --

As such, I needed an alternate solution and guessed that if I could cache
the Velocity templates used I could see big performance gains.

I initially looked to the
org.apache.velocity.runtime.resource.loader.StringResourceLoader class to
solve my problems.   The StringResourceLoader class requires an instance of
the StringResourceRepository class, and the only implementation of
StringResourceRepository is StringResourceRepositoryImpl.  Unfortunately,
since the number of unique templates will grow over time, in time the
StringResourceRepositoryImpl.resources Map will cause an out of memory
error.

Why doesn't StringResourceRepositoryImpl use a cache with a maximum size? 
Is a cache even needed as the Velocity ResourceCacheImpl will cache
Templates?

(Continue reading)

Chad La Joie | 6 Feb 13:17

Validate templates before use

Is there a way to "validate" a template prior to using it?  I'd like
to check that some user supplied templates are, at least, parsable
during system startup.

Thanks.

--

-- 
Chad La Joie
www.itumi.biz
trusted identities, delivered
Chad La Joie | 4 Feb 16:58

Most efficient evaluation

I'm looking for the most efficient/performant way to evaluate a
template and have some questions surrounding this.

1. Are Template objects reusable and thread safe?  If they're just
ASTs, it seems like they should be.

2. Does the Velocity/VelocityEngine class cache compiled templates (as
Template objects or anything else)?

3. If yes to both above, is there really any difference between
calling Velocity[Engine].merge and Template.merge?

Thanks.

--

-- 
Chad La Joie
www.itumi.biz
trusted identities, delivered
Christopher Schultz | 31 Jan 16:44

[TOOLS] Trouble building 2.0.x

All,

I'm having trouble building with the new Maven build system.

$ svn info
Path: .
URL: https://svn.apache.org/repos/asf/velocity/tools/branches/2.0.x
Repository Root: https://svn.apache.org/repos/asf
Repository UUID: 13f79535-47bb-0310-9956-ffa450edef68
Revision: 1238670
Node Kind: directory
Schedule: normal
Last Changed Author: schultz
Last Changed Rev: 1151923
Last Changed Date: 2011-07-28 12:44:21 -0400 (Thu, 28 Jul 2011)

$ mvn clean
$ mvn deploy

[tons of downloads, etc.]

Tests in error:

methodConfigure_ValueParser(org.apache.velocity.tools.generic.XmlToolTests):
Could not find file, classpath resource or standard URL for
'@test.file.dir@/file.xml'.
  methodToString(org.apache.velocity.tools.generic.XmlToolTests): Could
not find file, classpath resource or standard URL for
'@test.file.dir@/file.xml'.
  testStringFileEquals(org.apache.velocity.tools.generic.XmlToolTests):
(Continue reading)

Andrew Ducker | 29 Jan 21:49
Picon
Gravatar

Stopping parsing

Is there a way to say "Stop parsing at this point"?

I can wrap the two paths through my document in an #if #else but it 
would feel a bit cleaner to me to say:
#if(!$user.loggedIn)
You are not logged in
#STOPOPROCESSING

And then have the rest of my document underneath that.

If that's not possible then I'll live with:
#if(!$user.loggedIn)
You are not logged in
#else
Do lots of stuff
#end

Thanks,

Andy
Steve Cohen | 28 Jan 03:21

standalone template validation

I would like to validate a template standalone.

I have a template that is giving me errors and since there is a 
non-trivial build-deploy cycle to get it to run in my application I 
would like a way to validate the template file itself at the command line.

I have found this:

http://code.google.com/p/velocity-validator/
but it appears to be non-functional.  When run as directed it exits 
immediately telling me to supply a good log4j configuration.  I try to 
supply one (but even this seems excessive for a standalone tool) to no 
avail.

What is best way forward here?
Angelo zerr | 26 Jan 01:33
Picon
Gravatar

Re: Velocity and XML as context

Hi Nathan,

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

Thanks.

Regards Angelo

Le 25 janvier 2012 16:02, Nathan Bubna <nbubna <at> gmail.com> a écrit :

> 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.
>
> On Wed, Jan 25, 2012 at 6:19 AM, Angelo zerr <angelo.zerr <at> gmail.com>
> wrote:
> > 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
(Continue reading)

Sergiu Dumitriu | 25 Jan 19:01
Picon
Gravatar

MIME type for velocity templates

Is there a recommended MIME type that should be used for .vm files? I 
found text/velocity on http://www.filesuffix.com/extension/vm.html but 
I'd like to get an official opinion.
--

-- 
Sergiu Dumitriu
http://purl.org/net/sergiu/
Nathan Bubna | 25 Jan 16:02
Picon

Re: Velocity and XML as context

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.

On Wed, Jan 25, 2012 at 6:19 AM, Angelo zerr <angelo.zerr <at> gmail.com> wrote:
> 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
(Continue reading)

Angelo zerr | 25 Jan 15:19
Picon
Gravatar

Velocity and XML as context

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
(Continue reading)

abc12345 | 24 Jan 18:40
Favicon
Gravatar

Velocity template Evaluation


I'm a developer and trying to evaluate Velocity as an alternative to JSP, 
When I go to the Apache Velocity Site I don't see much activity on this
Project other than a few bug fixes, there are no dates for the next Release
etc. 
Can someone tell me if this is a dead project.

Thanks 
--

-- 
View this message in context: http://old.nabble.com/Velocity-template-Evaluation-tp33196367p33196367.html
Sent from the Velocity - User mailing list archive at Nabble.com.

Gmane