Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
36   122   18   3.6
14   84   0.5   10
10     1.8  
1    
 
 
  FormatDateTag       Line # 33 36 18 0% 0.0
 
No Tests
 
1    /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10    * the Free Software Foundation; either version 2 of the License, or
11    * (at your option) any later version.
12    *
13    * This program is distributed in the hope that it will be useful,
14    * but WITHOUT ANY WARRANTY; without even the implied warranty of
15    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    * GNU General Public License for more details.
17    */
18   
19    package org.itracker.web.taglib;
20   
21    import java.text.SimpleDateFormat;
22    import java.util.Date;
23    import java.util.Locale;
24   
25    import javax.servlet.http.HttpServletRequest;
26    import javax.servlet.jsp.JspException;
27    import javax.servlet.jsp.tagext.TagSupport;
28   
29    import org.apache.struts.taglib.TagUtils;
30    import org.itracker.core.resources.ITrackerResources;
31    import org.itracker.web.util.LoginUtilities;
32   
 
33    public class FormatDateTag extends TagSupport {
34    /**
35    *
36    */
37    private static final long serialVersionUID = 1L;
38    private String emptyKey = "itracker.web.generic.unavailable";
39    private String format;
40    private Date date;
41   
 
42  0 toggle public String getFormat() {
43  0 return format;
44    }
45   
 
46  0 toggle public void setFormat(String value) {
47  0 format = value;
48    }
49   
 
50  0 toggle public Date getDate() {
51  0 if (null == date)
52  0 return null;
53  0 return new Date(date.getTime());
54    }
55   
 
56  0 toggle public void setDate(Date value) {
57  0 if (null == value)
58  0 this.date = null;
59    else
60  0 date = new Date(value.getTime());
61    }
62   
 
63  0 toggle public String getEmptyKey() {
64  0 return emptyKey;
65    }
66   
 
67  0 toggle public void setEmptyKey(String value) {
68  0 emptyKey = value;
69    }
70   
 
71  0 toggle public int doStartTag() throws JspException {
72  0 return SKIP_BODY;
73    }
74   
 
75  0 toggle public int doEndTag() throws JspException {
76  0 String value = "";
77  0 SimpleDateFormat sdf;
78  0 Locale locale = null;
79  0 if (pageContext.getRequest() instanceof HttpServletRequest) {
80  0 locale = LoginUtilities.getCurrentLocale((HttpServletRequest)pageContext.getRequest());
81    }
82  0 if (locale == null) {
83  0 locale = ITrackerResources.getLocale();
84    }
85   
86  0 if (date == null) {
87  0 value = ITrackerResources.getString(emptyKey, locale);
88    } else {
89  0 try {
90  0 if ("short".equalsIgnoreCase(format)) {
91  0 sdf = new SimpleDateFormat(ITrackerResources.getString(
92    "itracker.dateformat.short", locale), locale);
93  0 } else if ("notime".equalsIgnoreCase(format)) {
94  0 sdf = new SimpleDateFormat(ITrackerResources.getString(
95    "itracker.dateformat.dateonly", locale), locale);
96    } else {
97  0 sdf = new SimpleDateFormat(ITrackerResources.getString(
98    "itracker.dateformat.full", locale), locale);
99    }
100  0 value = sdf.format(date);
101    } catch (Exception e) {
102  0 value = ITrackerResources.getString(emptyKey, locale);
103    }
104    }
105    // ResponseUtils.write(pageContext, value);
106  0 TagUtils.getInstance().write(pageContext, value);
107  0 clearState();
108  0 return EVAL_PAGE;
109    }
110   
 
111  0 toggle public void release() {
112  0 super.release();
113  0 clearState();
114    }
115   
 
116  0 toggle private void clearState() {
117  0 emptyKey = "itracker.web.generic.unavailable";
118  0 format = null;
119  0 date = null;
120    }
121   
122    }