|
Re: Contexts and Profiling: msg#00213jakarta.velocity.user
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 -- :) 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 = ""$value.substring(6)"" ) #* *##else #* *##set( $value = """" ) #* *##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> $type </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> |
|---|---|---|
| Previous by Date: | Contexts and Profiling: 00213, Michal Chmielewski |
|---|---|
| Next by Date: | Re: Default to quiet references: 00213, Serge Knystautas |
| Previous by Thread: | Contexts and Profilingi: 00213, Michal Chmielewski |
| Next by Thread: | 2 macros with the same name allowed?: 00213, Rodney Schneider |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |