package com.kiasoft.util.tools; /* ------------------------------------------------------------------ * Kiasoft, Inc. * http://kiasoft.com * * Copyright (c) 2004-2006 Kiasoft, Inc. All Rights Reserved. * ------------------------------------------------------------------ */ import java.util.Date; import org.apache.velocity.context.Context; import org.apache.turbine.services.pull.ApplicationTool; import org.apache.turbine.util.RunData; import org.apache.turbine.util.Log; import org.apache.turbine.util.pool.Recyclable; import com.kiasoft.util.LocalDate; /** * We are just extending the built in flux tool * */ public class DateTool implements Recyclable, ApplicationTool { /** The object containing request specific data */ private RunData data; public void init(Object data) { this.data = (RunData)data; } /** * nulls out the issue and user objects */ public void refresh() { // do not need since it is a request tool } /** * Constructor does initialization stuff */ public DateTool() { Log.info("Initializing DateTool"); } /** * Get a nicely formatted date for today */ public String getToday() { LocalDate ld = new LocalDate(); return ld.reportDate(); } /* get a date object for now */ public Date getTodayDate() { Date now = new Date(); return now; } /** * Get a nicely formatted date for reports */ public String reportDate(Date date) { LocalDate ld = new LocalDate(); if ( date != null ) { ld.setDate( date ); } else { ld.setDate(); } return ld.reportDate(); } /** * Get a nicely formatted date for display with time */ public String displayDate(Date date) { LocalDate ld = new LocalDate(); if ( date != null ) { ld.setDate( date ); } return ld.display(); } // ****************** Recyclable implementation ************************ private boolean disposed; /** * Recycles the object for a new client. Recycle methods with * parameters must be added to implementing object and they will be * automatically called by pool implementations when the object is * taken from the pool for a new client. The parameters must * correspond to the parameters of the constructors of the object. * For new objects, constructors can call their corresponding recycle * methods whenever applicable. * The recycle methods must call their super. */ public void recycle() { disposed = false; } /** * Disposes the object after use. The method is called * when the object is returned to its pool. * The dispose method must call its super. */ public void dispose() { data = null; disposed = true; } /** * Checks whether the recyclable has been disposed. * @return true, if the recyclable is disposed. */ public boolean isDisposed() { return disposed; } }