org.apache.velocity.tools.generic
Class NullTool

java.lang.Object
  extended by org.apache.velocity.tools.generic.NullTool
Direct Known Subclasses:
ViewNullTool

public class NullTool
extends java.lang.Object

Tool for working with null in Velocity templates. It provides a method to set a VTL reference back to null. Also provides methods to check if a VTL reference is null or not.

NOTE: These examples assume you have placed an instance of the current context within itself as 'ctx'. And, of course, the NullTool is assumed to be available as 'null'.

 Example uses:
  $foo                              -> bar
  $null.isNull($foo)                -> false
  $null.isNotNull($foo)             -> true

  $null.setNull($ctx, "foo")
  $foo                              -> $foo (null)
  $null.isNull($foo)                -> true
  $null.isNotNull($foo)             -> false

  $null.set($ctx, $foo, "hoge")
  $foo                              -> hoge
  $null.set($ctx, $foo, $null.null)
  $foo                              -> $foo (null)
 

This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application).

Version:
$Id: $
Author:
Shinobu Kawai

Constructor Summary
NullTool()
          Default constructor.
 
Method Summary
 java.lang.Object getNull()
          A convinient method which returns null.
 boolean isNotNull(java.lang.Object object)
          Checks if a VTL reference is not null.
 boolean isNull(java.lang.Object object)
          Checks if a VTL reference is null.
 void set(org.apache.velocity.context.Context context, java.lang.String key, java.lang.Object value)
          Sets the given VTL reference to the given value.
 void setNull(org.apache.velocity.context.Context context, java.lang.String key)
          Sets the given VTL reference back to null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullTool

public NullTool()
Default constructor.

Method Detail

setNull

public void setNull(org.apache.velocity.context.Context context,
                    java.lang.String key)
Sets the given VTL reference back to null.

Parameters:
context - the current Context
key - the VTL reference to set back to null.

set

public void set(org.apache.velocity.context.Context context,
                java.lang.String key,
                java.lang.Object value)
Sets the given VTL reference to the given value. If the value is null, the VTL reference is set to null.

Parameters:
context - the current Context
key - the VTL reference to set.
value - the value to set the VTL reference to.

isNull

public boolean isNull(java.lang.Object object)
Checks if a VTL reference is null.

Parameters:
object - the VTL reference to check.
Returns:
true if the VTL reference is null, false if otherwise.

isNotNull

public boolean isNotNull(java.lang.Object object)
Checks if a VTL reference is not null.

Parameters:
object - the VTL reference to check.
Returns:
true if the VTL reference is not null, false if otherwise.

getNull

public java.lang.Object getNull()
A convinient method which returns null. Actually, this tool will work the same without this method, because Velocity treats non-existing methods as null. :)

Returns:
null


Copyright © 2002-2005 org.ieee.shinobu. All Rights Reserved.