1 18 19 package cowsultants.itracker.web.taglib; 20 21 import java.io.*; 22 import java.util.*; 23 import java.text.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 import javax.servlet.jsp.*; 27 import javax.servlet.jsp.tagext.*; 28 29 import org.apache.struts.Globals; 30 import org.apache.struts.action.*; 31 import org.apache.struts.util.*; 32 33 import cowsultants.itracker.ejb.client.resources.*; 34 import cowsultants.itracker.ejb.client.util.*; 35 import cowsultants.itracker.web.util.*; 36 37 public class FormatDateTag extends TagSupport { 38 private String emptyKey = "itracker.web.generic.unavailable"; 39 private String format; 40 private Date date; 41 42 public String getFormat() { 43 return format; 44 } 45 46 public void setFormat(String value) { 47 format = value; 48 } 49 50 public Date getDate() { 51 return date; 52 } 53 54 public void setDate(Date value) { 55 date = value; 56 } 57 58 public String getEmptyKey() { 59 return emptyKey; 60 } 61 62 public void setEmptyKey(String value) { 63 emptyKey = value; 64 } 65 66 public int doStartTag() throws JspException { 67 return SKIP_BODY; 68 } 69 70 public int doEndTag() throws JspException { 71 String value = ""; 72 SimpleDateFormat sdf; 73 Locale currLocale = null; 74 75 HttpSession session = pageContext.getSession(); 76 if(session != null) { 77 currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY); 78 } 79 80 if(currLocale == null) { 81 currLocale = ITrackerResources.getLocale(); 82 } 83 84 if(date == null) { 85 value = ITrackerResources.getString(emptyKey, currLocale); 86 } else { 87 try { 88 if("short".equalsIgnoreCase(format)) { 89 sdf = new SimpleDateFormat(ITrackerResources.getString("itracker.dateformat.short", currLocale), currLocale); 90 } else if("notime".equalsIgnoreCase(format)) { 91 sdf = new SimpleDateFormat(ITrackerResources.getString("itracker.dateformat.dateonly", currLocale), currLocale); 92 } else { 93 sdf = new SimpleDateFormat(ITrackerResources.getString("itracker.dateformat.full", currLocale), currLocale); 94 } 95 value = sdf.format(date); 96 } catch(Exception e) { 97 value = ITrackerResources.getString(emptyKey, currLocale); 98 } 99 } 100 ResponseUtils.write(pageContext, value); 101 102 clearState(); 103 return EVAL_PAGE; 104 } 105 106 public void release() { 107 super.release(); 108 clearState(); 109 } 110 111 private void clearState() { 112 emptyKey = "itracker.web.generic.unavailable"; 113 format = null; 114 date = null; 115 } 116 117 } 118 | Popular Tags |