velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Dickinson <ian.dickin...@hp.com>
Subject Re: Macros will not run
Date Thu, 09 Aug 2007 14:42:33 GMT
Hi Nathan,
> Do you have any log output for this that we could see?
Yes, attached below.  I've tracked the problem down to a difference in 
the way I'm invoking the engine. I have two test cases, both of which 
read the same template. This one, taken from the user manual, works fine:

VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();

Template template = null;
template = ve.getTemplate(templateName);
StringWriter sw = new StringWriter();
template.merge( context, sw );
log.debug( sw.toString() );


This one, which I use because my templates will in future be dynamically 
generated rather than loaded from a file, doesn't:

StringWriter sw = new StringWriter();
java.io.File f = new java.io.File( templateName );
Reader reader = new FileReader( f );

VelocityEngine ve = new VelocityEngine();
ve.init();
log.debug( "Velocity macro prop: " + ve.getProperty( 
"velocimacro.permissions.allow.inline" ));

VelocityContext pvc = new VelocityContext();
ve.evaluate( pvc, sw, null, reader );
log.debug( sw.toString() );


I can't see a way of creating a Template object from a reader, so from 
reading the API I think I have to call evaluate() directly. However, I 
must presumably be missing a crucial step somewhere.

Any suggestions gratefully received.
Thanks,
Ian

__________________________________________________________________
Ian Dickinson   HP Labs, Bristol, UK   mailto:ian.dickinson@hp.com
http://www.hpl.hp.com/people/Ian_Dickinson    ph: +44 117 312 8796
Hewlett-Packard Limited              Registered No: 690597 England
Registered Office:            Cain Road, Bracknell, Berks RG12 1HN

Mime
View raw message