You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Jose Alberto Fernandez <JF...@viquity.com> on 2000/12/01 23:09:34 UTC

Output filters [was: RE: First timer]

> From: Jon Stevens [mailto:jon@latchkey.com]
> 
> 
> on 12/1/2000 12:58 PM, "Jose  Alberto Fernandez" 
> <JF...@viquity.com>
> wrote:
> 
> > Hummm, I wonder if at some point we could have implicit filtering
> > (i.e encoding) of the expansions generated from context information.
> > What I mean is that rather me writing in my template:
> > 
> > <element>$escape.getText($x.getFieldwithText())
> > $escape.getText($y)</element>
> > 
> > over and over all over the template. And instead The script 
> writer will do
> > 
> > <element>$x.getFieldwithText() $y</element>
> > 
> > and make the engine do the escaping as it does the expansion.
> > Do people see any value in something like that?
> 
> In that case, then that is what YOU should do in your object 
> code. You can
> call the Escape code from anywhere, so I would imagine that in your
> $x.getFieldwithText(), you would call that method.
> 

Well, I could argue that the need for encoding is part of the View and
not of the model or the controler. In other words, if I where in need to
generate some other text format, which I can do using Vel, I should not
need to change my model. I would expect I can use "$x.getFieldwithText()"
and this time getting not escaped output.

> The problem is that not everything should be filtered.

True, but what I am suggesting is that only "variable"/"method" output
be filtered. Not the template itself (the argument being that template 
encoding is for the writer of the template to do).

If the filters can be installed dynamically, it would be up to
the script to control it. For example, lets assume there is a directive
#filter the argument being an object implementing certain interface:

XMLScript.vtl

#filter($filter)
<?xml ...?>

<stuff>
 $x.getValue()
<cdatastuff>$filter.turnOff()<![CDATA[>
here goes unscaped stuff & this happens because I dynamically
switched off my filter, because I ddesigned it that way.
<!]]>$filter.turnOn()</cdatastuff>
More filtered stuff for $y here.
</stuff>

So what do you think, what I am asking is a definition and way
to set this filter interfaces, it is up to the developer to provide
the smarts required by it.

public class XMLFilter implements Filter
{
  private boolean off = false;

  public String process(String in) { //Filter interface
   if (off) return in;
   return Escape.getText(in);
  }

  public void turnOn() { off = false; }
  public void turnOff() { off = true; }
}


Jose Alberto

Re: Output filters [was: RE: First timer]

Posted by Jon Stevens <jo...@latchkey.com>.
on 12/1/2000 2:09 PM, "Jose  Alberto Fernandez" <JF...@viquity.com>
wrote:

> Well, I could argue that the need for encoding is part of the View and
> not of the model or the controler. In other words, if I where in need to
> generate some other text format, which I can do using Vel, I should not
> need to change my model. I would expect I can use "$x.getFieldwithText()"
> and this time getting not escaped output.

Ok, so then what is wrong with:

$escape.getText($x.getFieldWithText())

You just went full circle on yourself dude.

:-)

> True, but what I am suggesting is that only "variable"/"method" output
> be filtered. Not the template itself (the argument being that template
> encoding is for the writer of the template to do).
> 
> If the filters can be installed dynamically, it would be up to
> the script to control it. For example, lets assume there is a directive
> #filter the argument being an object implementing certain interface:
> 
> XMLScript.vtl
> 
> #filter($filter)
> <?xml ...?>
> 
> <stuff>
> $x.getValue()
> <cdatastuff>$filter.turnOff()<![CDATA[>
> here goes unscaped stuff & this happens because I dynamically
> switched off my filter, because I ddesigned it that way.
> <!]]>$filter.turnOn()</cdatastuff>
> More filtered stuff for $y here.
> </stuff>
> 
> So what do you think, what I am asking is a definition and way
> to set this filter interfaces, it is up to the developer to provide
> the smarts required by it.

You can do all of that without any modifications to Velocity.

> public class XMLFilter implements Filter
> {
> private boolean off = false;
> 
> public String process(String in) { //Filter interface
> if (off) return in;
> return Escape.getText(in);
> }
> 
> public void turnOn() { off = false; }
> public void turnOff() { off = true; }
> }

turnOn/turnOff? Huh? How about:

public void enabled(boolean value)

-jon

-- 
twice of not very much is still a lot more than not very much