> XMLOutput uses aggregation to work with any SAX ContentHandler or
> LexicalHandler so no need to derive.
> 
> XMLParser is a ContentHandler and LexicalHandler. So you 
> could do something
> like this in pseudo code
> 
> public class EvalTag extends TagSupport {
>     private String var;
> 
>     public void doTag(XMLOutput output) throws JellyTagException {
>         XMLParser parser = new XMLParser();
>         XMLOutput newOutput = new XMLOutput( parser );
> 
>         // invoke body, redirecting SAX events into the Jelly parser
>         invokeBody( newOutput );
>         Script script = parser.getScript();
> 
>         if (var != null) {
>             context.setVariable(var, script);
>         }
>         else {
>             // lets just execute the new script
>             script.run(context, output);
>         }
>     }
> }
> 

Looks great!

Just an alternative to have the "var" attribute: The tag could have a
"script" or "xml" attribute, then you could use it in conjunction with
<j:set/> to achieve the same effect.  E.g.

<j:set var="foo">
 <my:script-producing-script/>
</j:set>
<j:eval script="${foo}"/>

or would even the following work without an attribute?

<j:eval>
 ${foo}
</j:eval>

But maybe an additional boolean attribute "inheritContext" for the <j:eval/>
tag could be useful.  Then the context of the tag occurence would be set on
the XMLParser.  I.e.

if (inheritContext) {
        parser.setContext(context);
}

Cheers,

--
knut

Reply via email to