> From: Geir Magnusson Jr. [mailto:[EMAIL PROTECTED]]
>
>
> Leon Messerschmidt [mailto:[EMAIL PROTECTED]]
>
> > For what it is worth - I like this approach best.  It gives
> > you the power to
> > escape everything that you would like to do, but in the
> > exceptional cases
> > you are still able to switch the escaping of in a template.
>
> Since you now have to sprinkle Velocimacros around every
> single use of the
> technique you want to use :
>
>  #macro(ident, $value)$xml.turnOff(true)$value$xml.turnOff(false)#end
>
> Why not just do the escaping in the Velocimacro itself?  Or use a
> context-based tool directly?
>

Did I mentioned the 95%-5% rule before. I think the whole point of the
argument requesting a listener is that it is useful in cases where you need
to performe replacements more times than not.

Using escaping in the velocimacro is fine, when you need few things escaped,
but it becomes very error prone when you, or actually a non XML expert,
needs to call escape on almost everything.

Just to make clear we are all in the same page, in my example, you only need
to use #ident($blah) in those rare cases in which you do not want escaping.

True, you still need to call something sometimes, but we are back in balance
in the sense of only requiring action for the exception and not the rule.

> I still don't get it.  The example solution seems to be
> agreeing with my
> contention that  just having a listener isn't sufficient to solve the
> problem, and you have to add somthing in the template for
> each instance of
> the escaping function.
>

Not for each instance of the escaping, just for the few cases in which you
do not want to escape.

> Now, if you have to surround each insertion with the
> 'switches', why not
> just do the escaping directly, and avoid the overhead and complexity?
>

Read above.

> geir
>
> > ~ Leon
> >
> > > The way I see it, from the point of view of velocity,
> > whether the listener
> > > is intelligent or not is irrelevant. It is upto the
> > implementor of the
> > > listener to decide how to proceed. The beauty here is that
> > from velocity's
> > > point of view you are just providing an entry point in which the
> > application
> > > can add its own processing logic.
> > >
> > > I could probably write a small listener and acompaning
> > macro utilities to
> > do
> > > that.
> > >
> > > public class XMLEscape implements InsersionListener
> > > {
> > >   private boolean off = false;
> > >   public String beforeInsert(String value)
> > >   {
> > > if (off) return value;
> > > return escape(value);
> > >   }
> > >
> > >   public void turnOff(boolean v)
> > >   {
> > > off = v;
> > >   }
> > >   ....
> > > }
> > >
> > > #macro(ident,
> $value)$xml.turnOff(true)$value$xml.turnOff(false)#end
> > >
> > > Assume the same XMLEscape object is set as the listener and
> > the putin the
> > > context as "xml".
> > >
> >
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

Reply via email to