From: Marc P. <ma...@an...> - 2003-04-19 16:25:18
|
Here, I've tightened up the example a bit, and made it so #visitChildren does not call itself directly - to deflect accusations regarding the inability of a #macro to build itself given that it calls itself and hence cannot hope to complete. Still it doesn't work, but I suspect still for this reason, due to the way macros are built internally. We definitely need this fixed IMO. At the very least recursion, if it cannot be supported, should be trapped and an exception thrown before your servlet log becomes 500KB in one second! However, I can't believe that we can't support macro recursion. Without it, any kind of DOM/XML based processing in WM templates is pretty much impossible / extremely ugly (using recursive #includes). ## ******************************************************** ## This is all just to set up a trivial tree structure ## ******************************************************** #bean $rootNode = "java.util.Hashtable" #set $rootNode.Text="root" #bean $wmdocNode = "java.util.Hashtable" #set $wmdocNode.Text="wmdoc" #bean $titleNode1 = "java.util.Hashtable" #set $titleNode1.Text="title1" #bean $paraNode1 = "java.util.Hashtable" #set $paraNode1.Text="para1" #bean $titleNode2 = "java.util.Hashtable" #set $titleNode2.Text="title2" #bean $paraNode2 = "java.util.Hashtable" #set $paraNode2.Text="para2" #bean $paraNode3 = "java.util.Hashtable" #set $paraNode3.Text="para3" #set $rootNode.Children = [ $wmdocNode] #set $paraNode1.Children = [$titleNode2, $paraNode2] #set $wmdocNode.Children = [$titleNode1, $paraNode1, $paraNode3] ## ******************************************************** ## Here is the code ## ******************************************************** #macro visitChildren( $node) #if ($node.Children) #foreach $n in $node.Children $n.Text<br> #doIt( $n) #end #end #end ## Added this so visitChildren does not -directly-call itself #macro doIt( $node) #visitChildren($node) #end ## ******************************************************** ## Call the code ## ******************************************************** #visitChildren( $rootNode) -- Marc Palmer (Wangjammer5) http://www.wangjammers.org Java Consultants |