I see what you are saying, and I understand what you need.

But I wonder if we are misusing the $! as that says 'don't render the
literal if not in the context'. 

So do we want:

1) Status quo : don't do anything and use the logging switch?  Christoph
has a point that it isn't enough.

2) Make it :
   #set ($foo = $!splarg )
  as Christoph suggests

3)  Make it :

   #set ( $!foo = $splarg )

  because you are saying don't log if the assignment to $foo is null

4) something else?

geir


Christoph Reck wrote:
> 
> Something is screwed up about the list-server or SMTP forwarding...
> I sent this and another mail on friday, but I did not seem to
> reach the list. I got responses from the list of later emails
> but never from this one.
> 
> Geir, your propety switch is not sufficiently nice. I do want
> logs when nulls show up unintentionally, but no logs when I know
> it may return null - so I bang it then:
>   #set( $foo = $!bar.Temp("cachedXML") )
>   #if( !$foo )
>     ## create another one...
>     #set( $foo = $Xml.load("complex/file.xml") )
>     ## cache it
>     #set( $bar.Temp("cachedXML", $foo) )
>   #end
> And I dont want the initial $foo logged together with other real
> accidentall nulls, which I do care for!
> 
> Here it is again...
> -------- Original Message --------
> Subject: [PATCH] ASTSetDirective to handle a bang
> Date: Fri, 12 Jan 2001 15:34:27 +0100
> From: Christoph Reck <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> 
> The following patch allows ASTSetDirective to handle a bang and
> thus supress messages into the logs file.
> 
> Note that the AbstractContext must yet be updated for it to be
> completely silent.
> 
> This has no performace impact and makes the bang usage more
> orthogonal.
> 
> -----------------------------------------------------------------
> --- 
>Apache-Velocity-20010109/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
>      Wed Jan  3 06:27:04 2001
> +++ 
>Apache-Velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java 
>      Tue Jan  9 11:58:42 2001
> @@ -77,6 +77,7 @@
>  {
>      private Node right;
>      private ASTReference left;
> +    private boolean quietReference = false;
>      boolean bDeprecated = true;
>      String lit = "";
> 
> @@ -110,6 +111,11 @@
>          right = getRightHandSide();
>          left = getLeftHandSide();
> 
> +        if ( right.getFirstToken().image.startsWith("$!") )
> +        {
> +            quietReference = true;
> +        }
> +
>          /*
>           *   yechy but quick : so we can warn users they are using what will be
>           *  the deprecated version of #set
> @@ -151,13 +157,11 @@
>           * it's an error if we don't have a value of some sort
>           */
> 
> -        if ( value  == null)
> +        if ( (value == null) && !quietReference )
>          {
> -            Runtime.error("RHS of #set statement is null. Context will not be 
>modified. "
> +            Runtime.error("RHS of #set statement is null. "
>                            + context.getCurrentTemplateName() + " [line " + getLine()
>                            + ", column " + getColumn() + "]");
> -
> -            return false;
>          }
> -----------------------------------------------------------------
> 
> :) Christoph

-- 
Geir Magnusson Jr.                               [EMAIL PROTECTED]
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Reply via email to