commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Nichols <>
Subject [jelly] Taglib best practices for nested elements?
Date Thu, 23 Jan 2003 14:34:25 GMT
Good day,

I'm implementing a custom tag library, trying to learn some lessons
from earlier attempts. This library needs to use nested elements - a
top-level "munge" tag contains children and grandchldren. I.e.
     level 0 : munge etc.
     level 1 : input tag, output tag etc. - "parameters"
     level 2 : "document" tags - currently FileTag (has name attr), URLTag 
(has href attr) Workfile (creates a temporary file).

Question: what are the preferred ways to implement this?
My priorities:
     - extensibility : must be easy to add new tags at each level
     - simplicity : must be easy to understand
     - Jelly compliance :)  this stuff may get integrated into existing 
Jelly environments, it must play well with existing tag libraries.
     1. Each tag is a JellyTag in my namespace.
     2. Level 0 tags are JellyTags, the remainder are extracted from the 
tag body.
     3. Use BeanTagLibrary etc?

==== Option 1 ====
MungeTag.doTag() calls invokeBody(), triggers InputTag.doTag() which triggers
FileTag.doTag() { // Level 2.
     // Use attributes to set file name (standard Jelly mechanics).
     // Attach self to parent (level 1)  tag.

Level1Tag.doTag() {
     // Attach self to parent (level 0) tag.
Level0Tag.doTag() {
     // Process child "level 1" tag(s), e.g:
     URL url = level1Tag.getLevel2Tag.getURL();
Effectively, I'm manually duplicating the structure of the XML within
Java - ugh.

==== Option 2 ====
Something like:
MungeTag.doTag() {
     Element mungeEl = JellyUtils.tagToDom4jElement (this);    // :-)
     // Plain sailing - I can use dom4j to walk the tree.

So... how could I implement a generic tagToDom4jElement method? What are 
pros and cons of each approach? If feasible, the dom4j solution is clearly 
far simpler, but it's using Jelly only as a framework to deliver me a chunk 
of XML that is in my own syntax. Since supporting other taglibs is a 
priority, I'd need to invokeBody() anyway since the XML fragment may 
contain embedded tags for other taglibs.

Would the "BeanTagLibrary" approach be a better fit?
A consequence of having such a powerful and flexible framework is having to 
make such decisions - I've found several other approaches which I haven't 
discussed here. Please let me know if anyone can think of another contender?

Any and all feedback gratefully received.

Best Regards,

View raw message