KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > formatter > DateFormatter


1 package fr.improve.struts.taglib.layout.formatter;
2
3 import java.text.DateFormat JavaDoc;
4 import java.util.Date JavaDoc;
5
6 import javax.servlet.jsp.PageContext JavaDoc;
7
8
9 /**
10  * Example of a formatter. This one only knows how to format a date.
11  *
12  * @version 1.0
13  * @author JN Ribette
14  */

15 public class DateFormatter extends DispatchFormatter {
16     /**
17      * If in_value is not null,
18      * cast in_value in a java.util.Date object and format it
19      * according to the DateFormat.SHORT pattern and the request locale.
20      */

21     public String JavaDoc date(Object JavaDoc in_value, PageContext JavaDoc in_pageContext) {
22         Date JavaDoc lc_date = (Date JavaDoc) in_value;
23         if (lc_date==null) {
24             return null;
25         } else {
26             DateFormat JavaDoc lc_format = DateFormat.getDateInstance(DateFormat.SHORT, in_pageContext.getRequest().getLocale());
27             return lc_format.format(lc_date);
28         }
29     }
30 }
31
Popular Tags