public int doEndTag()
throws JspException
{
actualName = findString( nameAttr );
String msg = null;
OgnlValueStack stack = getStack();
//find the name on the valueStack, and cast it to a date
Object dateObj = stack.findValue( actualName );
if ( dateObj != null )
{
if ( dateObj instanceof Date )
{
date = (Date) dateObj;
}
else if ( dateObj instanceof Long )
{
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis( ( (Long) dateObj ).longValue() );
date = cal.getTime();
}
else
{
throw new JspException( "Could not cast the requested object " + nameAttr + " to a java.util.Date" );
}
}
if ( date != null && date.getTime() > 0 )
{
tp = findProviderInStack();
if ( tp == null )
{
throw new JspException( "Could not find a TextProvider on the stack." );
}
if ( nice )
{
msg = formatTime( date );
}
else
{
if ( format == null )
{
String globalFormat = null;
//if the format is not specified, fall back using the defined
// property DATETAG_PROPERTY
globalFormat = tp.getText( DATETAG_PROPERTY );
if ( globalFormat != null )
{
msg =
new SimpleDateFormat( globalFormat, ActionContext.getContext().getLocale() ).format( date );
}
else
{
//fall back using the xwork date format ?
}
}
else
{
msg = new SimpleDateFormat( format, ActionContext.getContext().getLocale() ).format( date );
}
}
}
if ( msg != null )
{
try
{
//if we used the id attribute, we will store the formatted date
// in the valuestack, otherwise, we write it to the
// outputstream.
if ( getId() == null )
{
pageContext.getOut().write( msg );
}
else
{
stack.getContext().put( getId(), msg );
}
}
catch ( IOException e )
{
throw new JspException( e );