velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Llewellyn Falco" <isid...@setgame.com>
Subject Re: how to set null value
Date Mon, 02 May 2005 14:18:39 GMT
I just thought i might pipe in here with the way I do things, since there 
seems to be so much talk of the setting of nulls, and this has never been 
much of issue.

 * First, we have a small interface.

public interface ContextAware
{
  public void setupContext(Context context);
}

* next a convience class VelocityParser, with the main function being

public static String parseFile(String template, ContextAware process)

So the idea is code would look like such

public class SomeClass implements ContextAware
public String doSomething()
{
    getModelsReady();
    return VelocityParser.parseJarFile(template1, this);
}

public void setupContext(Context context)
  {
    context.put("firstThing", firstThing);
    context.put("secondThing", secondThing);
  }
}


The idea is VelocityParser is a centralize place that will do the 
configuration baised on your startup config then add run your setupContext()

So you can initalize VelocityParser to default any number of contextaware 
objects in. We currently add 2 to everything in our project, Config (the 
configuration of the Company) and Commons.

Which brings to nulls. here are some of the static functions in 
ParserCommons, which is auto added to everything. as you can see this makes 
it always trival to deal with nulls (plus a lot of other things)

public static object getNull()
public static boolean isNull(Object object)
public static String clearNull(Object object )
public static String clearNull(Object object, String replaceNullValueWith)
public static TemplateDate asDate(Date date)
public static TemplateDouble asDouble(double number)
public static TemplateDate getToday()
public static TemplateStringUtils getStringUtils()
public static TemplateNumberUtils getNumberUtils()
public static CurrencyAmount asCurrency(double number)
public static TemplateDouble sum(Object[] array, String methodName)
public static int getArrayLength(Object[] array)
public static Object get(Object[] array, int index)
public static void throwError(String errorString)

    if it helps....
    llewellyn falco 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message