[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Re: template.merge output an empty file
From:       "Craig K. Dalrymple" <packetman () kc ! rr ! com>
Date:       2013-02-21 19:47:49
Message-ID: 6f47bfe4-97a4-476e-a868-132c46ff9366 () email ! android ! com
[Download RAW message or body]


Sometimes you just need that extra set of eyes.  For example, look at some of my earlier posts....


-------- Original Message --------
From: Garey Mills <gmills@library.berkeley.edu>
Sent: Thu Feb 21 13:19:34 CST 2013
To: Velocity Users List <user@velocity.apache.org>
Cc: Sergiu Dumitriu <sergiu.dumitriu@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.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic