First you say:
I have looked into Velocity, I just don't need something as packed with all the loops, conditionals, etc... just simple ol' variable parsing. But then you say:
3) The template "row_body" is parsed in a while loop for each of the messages It looks like you *do* need looping. I agree that Velocity may be "more" than some systems would need. But on the other hand, what's simpler than this?:
Your parsing piece would create the appropriate authors ArrayList of author Maps. The template merging engine takes care of the rest.
One problem I see with using just a tag like <rowbody> is that it took me a couple reads of your numbered steps to understand that the <rowbody> is self-looping. That is, the parsing engine you're trying to code would understand that when it hits <rowbody> it should go find some data (which data?), and loop over the results, swapping and replacing anything found inside the <rowbody> node that begins with a $.
Worse, it should also be understood by your parser that $body means "go find that <rowbody> template and do it's logic". Does $body *always* mean that? Does it *always* mean use <rowbody> ?
This was a point I missed out on until the 2nd time I was editing this message
Either I'm thick tonight, or there is inherint confusion when mixing the invokation of parsing/merging functions between XML tags and "things beginning with $"
I don't like the idea of "baking in" the looping stuff into an XML tag. It starts to make XML look like a programming language, which it's not. (flame war ON!)
I suppose you could clarify this by naming the tag something like <repeatingRowBody>, and instead of $body, use <repeatingRow />. But then the issue for the first becomes "repeating on what", and remains for the second "using what template"? Where in the template is this specified? If you say "well that will be hardcoded by whatever uses the template"... what about the case where you have two $body or <repeatingRow /> tags in a single template? Which one is which? You either can't use this template for anything else, other than your exact hard-coded instance that says "the first time you see it, it means this, the next time, it means this other thing...) or you now need an attribute on the tag to let your parser know which tag is which.
Which brings me around to thinking that the looping should not be part of the tag. Looping should be invoked by a simple command (like #while or #foreach) and I don't feel this over-complicates matters for template designers (mostly HTML monkeys?)
And yes, I'm gonna make one last sale point... Velocity isn't tied to HTML output either, as I've demonstrated by using your XML tags. You can still continue on to do an XSL transform, although using plain <tr><td></td></tr> tags is of course, supported as well.
I've seen Velocity used in a commercial product to produce email messages from templates. And umm.. I kinda copied it just recently at my own job. The idea... not the code!
and p.s Velocity also has handy features like #parse and #include, for nested templates.
[ May 12, 2003: Message edited by: Mike Curwen ]