logo       

Re: Contexts and Profiling: msg#00213

jakarta.velocity.user

Subject: Re: Contexts and Profiling

I have created a context dump tool. See attachment.
I use a layout approach like turbine and the layout template does:

#if( $debug )
#parse( "dump.vm" )
#end

The debug flag is passed in as a query parameter and then cached in the
session attributes. This way I just have to switch on debugging and see
the dump attached to every page:
## ------------------------------------------------------------------------
## 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)
#set( $debug = false )
#set( $debug = $!app.get("debug") )
#if( !$debug )
#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( $app.put("debug", $debug) )
##

This has worked nice for me. Some improvements are possile:
* Add a #context directive to put the current context into the context
for dumping
* Add additional flags to tell the dumper to dump a specific object
content or its API.
* Output other formats... (I got a version for plain text)

Cheers,
Christoph

Michal Chmielewski wrote:
Clear DayThe velocity context is map of keys to objects. These objects have
methods and are possibly of quite varying complexity and are in fact the
only "contract" between the code that prepares them for the template and the
actual template.

Anyone written a tool/template that could be used as an initial template
that would show:

- all the context objects in the current context/parent context
- print out their public interfaces (ie. what the methods/fields are
available to reference)
- allow for integration of this with javadoc or source browser.

I am not talking here about an editor plugin of some sort, just a template
that would dump out the current context and pretty print the
objects/methods/fields of the context objects.

The other topic is profiling. Does Velocity have anything like this ?

-michal




--
To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx>
For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>



--
:) Christoph Reck
## ------------------------------------------------------------------------
## File: templates/wiews/dump.vm
##
## Description: emits a context variable dump
##
## Input: $context
##
## Output: a table with the context vairables listed
##
## Date: 2000-11-18
## Author: Christoph.Reck@xxxxxx
## Copyright: (c) 2000 Deutsches Zentrum fuer Luft und Raumfahrt
## ------------------------------------------------------------------------
##
##
<br>
<b>User '$username' roles:</b><tt>
#foreach( $name in $ACL.getRoles($username) )
$name,
#end
</tt>
<br>
<b>Session Variables:</b><tt>
#foreach( $name in $cache.keySet() )
$name,
#end
</tt>
<br>
<b>Global Variables:</b><tt>
#foreach( $name in $Context.sort($context.getChainedContext().getKeys()) )
$name,
#end
</tt>
<br>
#call( $context.remove("screen_placeholder") )
#set( $keys = $Context.sort( $context.getKeys() ) )
<b>Context Variables:</b><br>
<table cellspacing="0" cellpadding="0">
#foreach( $foo in $keys )
#**##set( $value = $context.get($foo) )
#**##set( $type = $value.getClass().getName() )
<tr>
<td><tt>$foo</tt></td>
#* *##if( $type.startsWith("java.lang.") )
#* *##if( $type == "java.lang.String" )
#* *##set( $EOL = $Context.formDecode("%0D%0A") )
#* *##set( $l_tokenizer = $Class.newInstance("java.util.StringTokenizer",
$value, $EOL) )
#* *##set( $l_count = $l_tokenizer.countTokens() )
#* *##set( $value = "" )
#* *##foreach( $l_dummy in $Context.newArray($l_count) )
#* *##set( $value =
"$value<br>$EOL$Context.encodeMarkup($l_tokenizer.nextElement())" )
#* *##end
#* *##if( $value != "" )
#* *##set( $value = "&quot;$value.substring(6)&quot;" )
#* *##else
#* *##set( $value = "&quot;&quot;" )
#* *##end
#* *##set( $value = $value.toString() )
#* *##end
#* *##set( $type = $type.substring(10) )
#* *##else
#* *##if( $type.endsWith(".ParameterParser") )
#* *##set( $value = $Context.encodeMarkup($value.toString()) )
#* *##set( $type = "pp" )
#* *##elseif( $type.endsWith(".DynamicURI") )
#* *##set( $value = $Context.encodeMarkup($value.toString()) )
#* *##set( $type = "uri" )
#* *##else
#* *##if( !$value )
#* *##set( $value = "NULL" )
#* *##elseif( $value.size() && ($value.size() >= 0) )
#* *##set( $value = "$type[$value.size()]" )
#* *##else
#* *##set( $value = $type )
#* *##end
#* *##set( $type = "=" )
#* *##end
#* *##end
### <td><tt>&nbsp;$type&nbsp;</tt></td>
<td><tt>$value</tt></td>
</tr>
#end
</table>
<font size="2">Done.<br></font>
--
To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx>
For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise