/*
* Copyright (c) 2001 - 2005 ivata limited.
* All rights reserved.
* -----------------------------------------------------------------------------
* ivata masks may be redistributed under the GNU General Public
* License as published by the Free Software Foundation;
* version 2 of the License.
*
* These programs are free software; you can redistribute them and/or
* modify them under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of the License.
*
* These programs are distributed in the hope that they will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License in the file LICENSE.txt for more
* details.
*
* If you would like a copy of the GNU General Public License write to
*
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA.
*
*
* To arrange commercial support and licensing, contact ivata at
* http://www.ivata.com/contact.jsp
* -----------------------------------------------------------------------------
* $Log: FormatDateTag.java,v $
* Revision 1.4 2005/10/02 14:06:34 colinmacleod
* Added/improved log4j logging.
*
* Revision 1.3 2005/09/14 13:23:58 colinmacleod
* Added serialVersionUID.
*
* Revision 1.2 2005/04/09 18:04:19 colinmacleod
* Changed copyright text to GPL v2 explicitly.
*
* Revision 1.1 2005/01/19 12:58:20 colinmacleod
* Moved from ivata groupware.
*
* Revision 1.4 2004/07/13 19:41:15 colinmacleod
* Moved project to POJOs from EJBs.
* Applied PicoContainer to services layer (replacing session EJBs).
* Applied Hibernate to persistence layer (replacing entity EJBs).
*
* Revision 1.3 2004/03/21 21:16:09 colinmacleod
* Shortened name to ivata op.
*
* Revision 1.2 2004/02/01 22:00:34 colinmacleod
* Added full names to author tags
*
* Revision 1.1.1.1 2004/01/27 20:57:58 colinmacleod
* Moved ivata openportal to SourceForge..
* -----------------------------------------------------------------------------
*/
package com.ivata.mask.web.tag.format;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.ivata.mask.web.format.DateFormatter;
import com.ivata.mask.web.format.DateFormatterException;
/**
* <p>This class wraps the <code>DateFormatter</code> class, so that
* you can call {@link com.ivata.groupware.util.DateFormatter#format
* DateFormatter.format} as a JSP tag.</p>
* <p><b>Tag attributes:</b><br/>
* <table cellpadding='2' cellspacing='5' border='0' align='center'
* width='85%'>
* <tr class='TableHeadingColor'>
* <th>attribute</th>
* <th>reqd.</th>
* <th>param. class</th>
* <th width='100%'>description</th>
* </tr>
* <tr class='TableRowColor'>
* <td>date</td>
* <td>true</td>
* <td><code>com.ivata.util.DateFormatter</code></td>
* <td>Sets the date to be formatted into a string.</td>
* </tr>
* <tr class='TableRowColor'>
* <td>formatter</td>
* <td>true</td>
* <td><code>com.ivata.util.DateFormatter</code></td>
* <td>Sets the formatter which actually does the formatting.</td>
* </tr>
* </table>
* </p>
*
* @since ivata masks 0.5 (2002-06-22)
* @author Colin MacLeod
* <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
* @version $Revision: 1.4 $
*/
public class FormatDateTag extends TagSupport {
/**
* Logger for this class.
*/
private static final Logger logger = Logger.getLogger(FormatDateTag.class);
/**
* Serialization version (for <code>Serializable</code> interface).
*/
private static final long serialVersionUID = 1L;
/**
* <p>This date will be formatted into a string when this tag is used.</p>
*/
private Date date;
/**
* <p>
* This date formatter will do all the hard work.
* </p>
*/
private DateFormatter formatter;
/**
* <p>This method is called when the JSP engine encounters the start tag,
* after the attributes are processed.<p>
*
* <p>Scripting variables (if any) have their values set here.</p>
*
* @exception JspException if any of the attributes have invalid values.
* @exception JspException if there is any excpetion calling
* <code>out.print</code>.
* @return <code>SKIP_BODY</code> since this tag has no body.
*/
public int doStartTag() throws JspException {
if (logger.isDebugEnabled()) {
logger.debug("doStartTag() - start");
}
// check what we got
assert (formatter != null);
assert (date != null);
JspWriter out = pageContext.getOut();
try {
out.print(formatter.format(date));
} catch (DateFormatterException e) {
logger.error("doStartTag()", e);
throw new RuntimeException(e);
} catch (IOException e) {
logger.error("doStartTag()", e);
throw new RuntimeException(e);
}
// singin' >>I don't have no body...<<
if (logger.isDebugEnabled()) {
logger.debug("doStartTag() - end - return value = " + SKIP_BODY);
}
return SKIP_BODY;
}
/**
* <p>Get the date which will be formatted into a string when this tag is
* used.</p>
*
* @return the current value of the date to be formatted into a string.
*/
public final Date getDate() {
if (logger.isDebugEnabled()) {
logger.debug("getDate() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getDate() - end - return value = " + date);
}
return date;
}
/**
* <p>
* This date formatter will do all the hard work.
* </p>
*
* @return current value of dateFormatter.
*/
public final DateFormatter getFormatter() {
if (logger.isDebugEnabled()) {
logger.debug("getFormatter() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getFormatter() - end - return value = " + formatter);
}
return formatter;
}
/**
* <p>Set the date which will be formatted into a string when this tag is
* used.</p>
*
* @param dateParam the new value of the date to be formatted into a string.
*/
public final void setDate(final Date dateParam) {
if (logger.isDebugEnabled()) {
logger.debug("setDate(Date dateParam = " + dateParam + ") - start");
}
this.date = dateParam;
if (logger.isDebugEnabled()) {
logger.debug("setDate(Date) - end");
}
}
/**
* <p>
* This date formatter will do all the hard work.
* </p>
*
* @param formatterParam new value of date formatter.
*/
public final void setFormatter(final DateFormatter formatterParam) {
if (logger.isDebugEnabled()) {
logger.debug("setFormatter(DateFormatter formatterParam = "
+ formatterParam + ") - start");
}
this.formatter = formatterParam;
if (logger.isDebugEnabled()) {
logger.debug("setFormatter(DateFormatter) - end");
}
}
}
|