You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Marvin Greenberg <mg...@dctd.saic.com> on 2003/02/06 21:23:10 UTC

improvements (perhaps) to TemplateTool

I've made some minor changes to the template tool.  I got rid of the stuff
that listed every (including repeat) reference, and changed it so that
references are listed in a sorted order, and that a summary for all the
template files is also generated.  I also plan to add an option to make all
equivalent forms show up only once -- $class.Name and ${class.Name} and
$class.getName(), and compress methods references to only the name and arg
count.  Beyond that  I was thinking about a doclet to generate a bean
description from a java class or set of classes (something exists perhaps?),
which could then be used to actually validate the templates.

This little utility already pointed out to me the places I had misspelled
the references  $class.Superclass...  BTW ignore what I'm actually using
velocity for -- its certainly heretical...


java TemplateTool templates/class/*vm

File: templates/class/CORBAservantImplementation.cpp.vm
 $class.Name
 $class.Name.toQualifiedName()
 $templateFileName
 ${class.Name}

File: templates/class/CORBAservantImplementation.i.vm
 $class.Interfaces
 $class.Name
 $class.Name.getBaseName()
 $class.Name.toQualifiedName("RemoteServantMethods")
 $class.Name.toQualifiedName()
 $class.SuperClass
 $class.SuperClass.Name.toQualifiedName()
 $inf
 $inf.Name.toQualifiedName()
 $templateFileName
 RemoteServantMethods.h

<snip -- many more files>

Summary:
 $atEnd
 $attr
 $attr.Name
 $attr.Type.IDLtype
 $attr.Type.TDLtype
 $class.AllContainedClasses
 $class.AllInterfaces
 $class.AllInterfaces.size()
 $class.AllSuperClasses
 $class.AllSuperclasses
 $class.AllSuperclasses.size()
 $class.Attributes
 $class.Hierarchy
 $class.Interfaces
 $class.Name
 $cls
 $cls.Attributes.getAll($classFilter)
 $cls.Name.toPath()
 $implementationNamespace.toQualifiedName()
 $inf
 $inf.Name.toQualifiedName()
 $op
 $op.ArgList
 $templateFileName
 $utility.toPrefixName("${class.Name}","XMLlogStream.h")
 $utility.toPrefixName("${cls.Name}","Type.h")
 $utility.uncapitalize("$class.Name")
 $velocityCount
 ${OMname}
 ${attr.Name}
 ${class.Name}
 ${class.SuperClass}
 ${cls.Name}
 ${pubStateDispatcherRef}
 ${pubStatePtr}
 ${templateFileName}
 CachedPublicationStateViewController
 RemoteServantMethods.h
 Version
 _getPublicationState


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: improvements (perhaps) to TemplateTool

Posted by Bill Burton <bi...@progress.com>.
Hello,

Christoph.Reck@dlr.de wrote:
> Geir Magnusson Jr. wrote:
> 
>>
>> On Friday, February 7, 2003, at 04:10 AM, Christoph.Reck@dlr.de wrote:
>>
>>> I have a small dump.vm template that formats the context content (and
>>> some servlet/application specific stuff). All it needs is $context
>>> placed in the context and the call it.
>>>
>>> It would be very nice to have a #context()...#end directive that
>>> just puts the context into the context to get dumps of a local
>>> chained context (for example wihtin a #foreach loop or after a
>>> #local directive). Such a #context directive is *very* trivial.

Don't think an #end would be needed as that variable would be poped off 
the stack anyways and the end of the enclosing #foreach or #local.

>> I don't get it - what do you want it to do?  Couldn't you put the 
>> context in the context to start with?
> 
> 
> That's what I'm doing now. But if I have nested #foreachs and #locals
> and I want to debug and dump the state, that context is not the
> topmost, so it's missing some variables. A trivial #context directive
> would solve this restriction.

I think you're assumming #foreach and #local use a chained context. 
Don't think this is the case.  Both of these directives simply save any 
existing values in the context with the same name that would be 
overwriten and then restores them at the end.  The evidence of this is 
any other variables you set inside that block are available outside the 
block when it ends.

I suspect the real problem is that when you do something like this:
   #foreach( $item in $context.getKeys() )
      #set( $value = $context.get($item) )
      #set( $type = $value.Class.Name )
      $velocityCount: $item: $type: $value
   #end

You're getting the list of objects in the context at the start of the 
loop where getKeys() takes a "snapshot".  Any new variables set inside 
the loop will not show up because getKeys does not reevaluate on each 
iteration.  However, if you define the variables first outside the loop, 
then they will show up.

   #set( $value = "" )
   #set( $type = "" )
   #foreach( $item in $context.getKeys() )
      #set( $value = $context.get($item) )
      #set( $type = $value.Class.Name )
      $velocityCount: $item: $type: $value
   #end

To do this dynamically, you need to call $context.getKeys() just before 
#end so you'll have all the variables--but then you can't loop on it. 
So the only easy fix I can think of is to define all variables outside 
the loop.

>>
>>>
>>> Geir, is there some way of specifying the applicable directives
>>> outside of the vel.jar file, e.g. from the velocity.properties?
>>
>>
>>
>> Definitely.  DVSL does this.  It's 'userdirective'.
>>
>> so in code, DVSL does :
>>
>>         ve.setProperty("userdirective", 
>> "org.apache.tools.dvsl.directive.MatchDirective");
>>        ve.init();
> 
> 
> Thanks for this tip.
> Does this also apply to the standard VelocityEngine?

Yes, that's what DVSL is using.

> 
>>
>> geir
>>
> 

Hope this helps,
-Bill


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: improvements (perhaps) to TemplateTool

Posted by Ch...@dlr.de.
Geir Magnusson Jr. wrote:
> 
> On Friday, February 7, 2003, at 04:10 AM, Christoph.Reck@dlr.de wrote:
> 
>> I have a small dump.vm template that formats the context content (and
>> some servlet/application specific stuff). All it needs is $context
>> placed in the context and the call it.
>>
>> It would be very nice to have a #context()...#end directive that
>> just puts the context into the context to get dumps of a local
>> chained context (for example wihtin a #foreach loop or after a
>> #local directive). Such a #context directive is *very* trivial.
> 
> 
> I don't get it - what do you want it to do?  Couldn't you put the 
> context in the context to start with?

That's what I'm doing now. But if I have nested #foreachs and #locals
and I want to debug and dump the state, that context is not the
topmost, so it's missing some variables. A trivial #context directive
would solve this restriction.

> 
>>
>> Geir, is there some way of specifying the applicable directives
>> outside of the vel.jar file, e.g. from the velocity.properties?
> 
> 
> Definitely.  DVSL does this.  It's 'userdirective'.
> 
> so in code, DVSL does :
> 
>         ve.setProperty("userdirective", 
> "org.apache.tools.dvsl.directive.MatchDirective");
>        ve.init();

Thanks for this tip.
Does this also apply to the standard VelocityEngine?

> 
> geir
> 

-- 
:) Christoph Reck


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: improvements (perhaps) to TemplateTool

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On Friday, February 7, 2003, at 04:10 AM, Christoph.Reck@dlr.de wrote:

> I have a small dump.vm template that formats the context content (and
> some servlet/application specific stuff). All it needs is $context
> placed in the context and the call it.
>
> It would be very nice to have a #context()...#end directive that
> just puts the context into the context to get dumps of a local
> chained context (for example wihtin a #foreach loop or after a
> #local directive). Such a #context directive is *very* trivial.

I don't get it - what do you want it to do?  Couldn't you put the 
context in the context to start with?

>
> Geir, is there some way of specifying the applicable directives
> outside of the vel.jar file, e.g. from the velocity.properties?

Definitely.  DVSL does this.  It's 'userdirective'.

so in code, DVSL does :

         ve.setProperty("userdirective", 
"org.apache.tools.dvsl.directive.MatchDirective");
	   ve.init();

geir

-- 
Geir Magnusson Jr                                   203-956-2604(w)
Adeptra, Inc.                                       203-247-1713(m)
geirm@adeptra.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: improvements (perhaps) to TemplateTool

Posted by Ch...@dlr.de.
I have a small dump.vm template that formats the context content (and
some servlet/application specific stuff). All it needs is $context
placed in the context and the call it.

It would be very nice to have a #context()...#end directive that
just puts the context into the context to get dumps of a local
chained context (for example wihtin a #foreach loop or after a
#local directive). Such a #context directive is *very* trivial.

Geir, is there some way of specifying the applicable directives
outside of the vel.jar file, e.g. from the velocity.properties?

I use a simple but effective switch stored in the session attributes
to switch on debugging, which the remains on and causes the layout
template to append the dump to every page, until it is switched off
again:

## ------------------------------------------------------------------------
## Decode dubug flag state
## ------------------------------------------------------------------------
## and save debug flag in session (not in the query string)
## get the debug flag state from the session (false is the default)
#if( $!session.getAttribute("debug") )
   #set( $debug = true )
#else
   #set( $debug = false )
#end
## overlay the debug flag with possible value from the QueryString
#set( $debug = $parameters.getBoolean("debug", $debug) )
## promote the state into the session
#call( $session.setAttribute("debug", $debug) )

And at the end of the layout template (also attached):

#if( $debug )
   <p align="right"><small><a href="$link/$page?debug=0">Disable Debug</a></small></p>
   #parse( "views/dump.vm" )
#else
   <p align="right"><small><a href="$link/$page?debug=1">Enable Debug</a></small></p>
#end

It would be nice to enhance the dump template (or create another one
along this line to display the contents of specific object (BeanInfo)

-- 
:) Christoph Reck


Marvin Greenberg wrote:
> I've made some minor changes to the template tool.  I got rid of the stuff
> that listed every (including repeat) reference, and changed it so that
> references are listed in a sorted order, and that a summary for all the
> template files is also generated.  I also plan to add an option to make all
> equivalent forms show up only once -- $class.Name and ${class.Name} and
> $class.getName(), and compress methods references to only the name and arg
> count.  Beyond that  I was thinking about a doclet to generate a bean
> description from a java class or set of classes (something exists perhaps?),
> which could then be used to actually validate the templates.
> 
> This little utility already pointed out to me the places I had misspelled
> the references  $class.Superclass...  BTW ignore what I'm actually using
> velocity for -- its certainly heretical...
>[snip]

-- 
:) Christoph Reck

Re: improvements (perhaps) to TemplateTool

Posted by marvin greenberg <mg...@dctd.saic.com>.
I'm going to make the simple enhancements I described, maybe a day or two.  But then,
sure.  I wasn't sure if the more correct approach was to feed it back into the CVS
repository through someone with checkin privledges...

----- Original Message -----
From: "Cort Schaefer" <co...@xmission.com>
To: "'Velocity Users List'" <ve...@jakarta.apache.org>
Sent: Thursday, February 06, 2003 5:15 PM
Subject: RE: improvements (perhaps) to TemplateTool


> Would you mind posting that to the list?
>
> -----Original Message-----
> From: Marvin Greenberg [mailto:mgreenberg@dctd.saic.com]
> Sent: Thursday, February 06, 2003 1:23 PM
> To: Velocity Users List
> Subject: improvements (perhaps) to TemplateTool
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: improvements (perhaps) to TemplateTool

Posted by Cort Schaefer <co...@xmission.com>.
Would you mind posting that to the list?

-----Original Message-----
From: Marvin Greenberg [mailto:mgreenberg@dctd.saic.com] 
Sent: Thursday, February 06, 2003 1:23 PM
To: Velocity Users List
Subject: improvements (perhaps) to TemplateTool

I've made some minor changes to the template tool.  I got rid of the
stuff
that listed every (including repeat) reference, and changed it so that
references are listed in a sorted order, and that a summary for all the
template files is also generated.  I also plan to add an option to make
all
equivalent forms show up only once -- $class.Name and ${class.Name} and
$class.getName(), and compress methods references to only the name and
arg
count.  Beyond that  I was thinking about a doclet to generate a bean
description from a java class or set of classes (something exists
perhaps?),
which could then be used to actually validate the templates.

This little utility already pointed out to me the places I had
misspelled
the references  $class.Superclass...  BTW ignore what I'm actually using
velocity for -- its certainly heretical...


java TemplateTool templates/class/*vm

File: templates/class/CORBAservantImplementation.cpp.vm
 $class.Name
 $class.Name.toQualifiedName()
 $templateFileName
 ${class.Name}

File: templates/class/CORBAservantImplementation.i.vm
 $class.Interfaces
 $class.Name
 $class.Name.getBaseName()
 $class.Name.toQualifiedName("RemoteServantMethods")
 $class.Name.toQualifiedName()
 $class.SuperClass
 $class.SuperClass.Name.toQualifiedName()
 $inf
 $inf.Name.toQualifiedName()
 $templateFileName
 RemoteServantMethods.h

<snip -- many more files>

Summary:
 $atEnd
 $attr
 $attr.Name
 $attr.Type.IDLtype
 $attr.Type.TDLtype
 $class.AllContainedClasses
 $class.AllInterfaces
 $class.AllInterfaces.size()
 $class.AllSuperClasses
 $class.AllSuperclasses
 $class.AllSuperclasses.size()
 $class.Attributes
 $class.Hierarchy
 $class.Interfaces
 $class.Name
 $cls
 $cls.Attributes.getAll($classFilter)
 $cls.Name.toPath()
 $implementationNamespace.toQualifiedName()
 $inf
 $inf.Name.toQualifiedName()
 $op
 $op.ArgList
 $templateFileName
 $utility.toPrefixName("${class.Name}","XMLlogStream.h")
 $utility.toPrefixName("${cls.Name}","Type.h")
 $utility.uncapitalize("$class.Name")
 $velocityCount
 ${OMname}
 ${attr.Name}
 ${class.Name}
 ${class.SuperClass}
 ${cls.Name}
 ${pubStateDispatcherRef}
 ${pubStatePtr}
 ${templateFileName}
 CachedPublicationStateViewController
 RemoteServantMethods.h
 Version
 _getPublicationState


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org