template.merge output an empty file
Garey Mills <[email protected]>
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <[email protected]> |
Hi -
I am trying to user VelocityEngine.
Here is my code:
Properties vp = new Properties();
vp.setProperty("file.resource.loader.path",
templatesDirectory + "/");
VelocityEngine ve = new VelocityEngine();
ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM,
fysclLogger);
ve.init(vp);
VelocityContext context = new VelocityContext();
context.put("coll", coll);
context.put("metsArk", metsArk);
Template template = null;
try {
FileWriter fw = new FileWriter(new File(metsDirectory +
"/" + metsFileName));
template = ve.getTemplate("metsTemplate.vm");
template.merge(context, fw);
} catch(ResourceNotFoundException rnfe) {
System.out.println("Resource not found exception trying
to get template: " + rnfe);
} catch(ParseErrorException pee) {
System.out.println("Parse error exception trying to get
template: " + pee);
} catch(MethodInvocationException mie) {
System.out.println("Method invocation exception trying
to get template: " + mie);
} catch(Exception e) {
System.out.println("Exception trying to get template: "
+ e);
}
Here is my template (reduced for debugging):
OBJID="${metsArk}"
LABEL="${coll.getTitle()}"
And here is the logging output:
Initializing Velocity, Calling init()...
*******************************************************************
Starting Apache Velocity v1.7 (compiled: 2010-11-19 12:14:37)
RuntimeInstance initializing.
Default Properties File:
org/apache/velocity/runtime/defaults/velocity.properties
Default ResourceManager initializing. (class
org.apache.velocity.runtime.resource.ResourceManagerImpl)
ResourceLoader instantiated:
org.apache.velocity.runtime.resource.loader.FileResourceLoader
FileResourceLoader : initialization starting.
Do unicode file recognition: false
FileResourceLoader : adding path '/data/apps/fysclmgr/web/templates/'
FileResourceLoader : initialization complete.
ResourceCache: initialized (class
org.apache.velocity.runtime.resource.ResourceCacheImpl) with class
java.util.Collections$SynchronizedMap cache map.
Default ResourceManager initialization complete.
Loaded System Directive: org.apache.velocity.runtime.directive.Stop
Loaded System Directive: org.apache.velocity.runtime.directive.Define
Loaded System Directive: org.apache.velocity.runtime.directive.Break
Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
Loaded System Directive: org.apache.velocity.runtime.directive.Literal
Loaded System Directive: org.apache.velocity.runtime.directive.Macro
Loaded System Directive: org.apache.velocity.runtime.directive.Parse
Loaded System Directive: org.apache.velocity.runtime.directive.Include
Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
Created '20' parsers.
Velocimacro : initialization starting.
Velocimacro : "velocimacro.library" is not set. Trying default library:
VM_global_library.vm
Velocimacro : Default library not found.
Velocimacro : allowInline = true : VMs can be defined inline in templates
Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT
replace previous VM definitions
Velocimacro : allowInlineLocal = false : VMs defined inline will be
global in scope if allowed.
Velocimacro : autoload off : VM system will not automatically reload
global library macros
Velocimacro : Velocimacro : initialization complete.
RuntimeInstance successfully initialized.
Velocity Engine initialized
ResourceManager : found metsTemplate.vm with loader
org.apache.velocity.runtime.resource.loader.FileResourceLoader
The result is always the same, the output file is empty.
And ideas about what I can try?
-- Garey Mills Library Systems Office UC Berkeley