You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Garey Mills <gm...@library.berkeley.edu> on 2013/02/21 19:50:20 UTC
template.merge output an empty file
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
Re: template.merge output an empty file
Posted by "Craig K. Dalrymple" <pa...@kc.rr.com>.
Sometimes you just need that extra set of eyes. For example, look at some of my earlier posts....
-------- Original Message --------
From: Garey Mills <gm...@library.berkeley.edu>
Sent: Thu Feb 21 13:19:34 CST 2013
To: Velocity Users List <us...@velocity.apache.org>
Cc: Sergiu Dumitriu <se...@gmail.com>
Subject: Re: template.merge output an empty file
That's it. I'm so embarassed.
Garey Mills
On 2/21/2013 10:54 AM, Sergiu Dumitriu wrote:
> On 02/21/2013 01:50 PM, Garey Mills wrote:
>> 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?
>>
> Try adding a fw.close() at the end?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
--
Garey Mills
Library Systems Office
UC Berkeley
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Re: template.merge output an empty file
Posted by Garey Mills <gm...@library.berkeley.edu>.
That's it. I'm so embarassed.
Garey Mills
On 2/21/2013 10:54 AM, Sergiu Dumitriu wrote:
> On 02/21/2013 01:50 PM, Garey Mills wrote:
>> 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?
>>
> Try adding a fw.close() at the end?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
--
Garey Mills
Library Systems Office
UC Berkeley
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: template.merge output an empty file
Posted by Sergiu Dumitriu <se...@gmail.com>.
On 02/21/2013 01:50 PM, Garey Mills wrote:
> 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?
>
Try adding a fw.close() at the end?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org