1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 package com.ivata.mask.web.tag.format;
53
54 import java.io.IOException;
55 import java.util.Date;
56
57 import javax.servlet.jsp.JspException;
58 import javax.servlet.jsp.JspWriter;
59 import javax.servlet.jsp.tagext.TagSupport;
60
61 import com.ivata.mask.web.format.DateFormatter;
62 import com.ivata.mask.web.format.DateFormatterException;
63
64
65 /***
66 * <p>This class wraps the <code>DateFormatter</code> class, so that
67 * you can call {@link com.ivata.groupware.util.DateFormatter#format
68 * DateFormatter.format} as a JSP tag.</p>
69 * <p><b>Tag attributes:</b><br/>
70 * <table cellpadding='2' cellspacing='5' border='0' align='center'
71 * width='85%'>
72 * <tr class='TableHeadingColor'>
73 * <th>attribute</th>
74 * <th>reqd.</th>
75 * <th>param. class</th>
76 * <th width='100%'>description</th>
77 * </tr>
78 * <tr class='TableRowColor'>
79 * <td>date</td>
80 * <td>true</td>
81 * <td><code>com.ivata.util.DateFormatter</code></td>
82 * <td>Sets the date to be formatted into a string.</td>
83 * </tr>
84 * <tr class='TableRowColor'>
85 * <td>formatter</td>
86 * <td>true</td>
87 * <td><code>com.ivata.util.DateFormatter</code></td>
88 * <td>Sets the formatter which actually does the formatting.</td>
89 * </tr>
90 * </table>
91 * </p>
92 *
93 * @since ivata masks 0.5 (2002-06-22)
94 * @author Colin MacLeod
95 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
96 * @version $Revision: 1.2 $
97 */
98 public class FormatDateTag extends TagSupport {
99 /***
100 * <p>This date will be formatted into a string when this tag is used.</p>
101 */
102 private Date date;
103
104 /***
105 * <p>
106 * This date formatter will do all the hard work.
107 * </p>
108 */
109 private DateFormatter formatter;
110
111 /***
112 * <p>This method is called when the JSP engine encounters the start tag,
113 * after the attributes are processed.<p>
114 *
115 * <p>Scripting variables (if any) have their values set here.</p>
116 *
117 * @exception JspException if any of the attributes have invalid values.
118 * @exception JspException if there is any excpetion calling
119 * <code>out.print</code>.
120 * @return <code>SKIP_BODY</code> since this tag has no body.
121 */
122 public int doStartTag() throws JspException {
123
124 assert (formatter != null);
125 assert (date != null);
126
127 JspWriter out = pageContext.getOut();
128
129 try {
130 out.print(formatter.format(date));
131 } catch (DateFormatterException e) {
132 throw new RuntimeException(e);
133 } catch (IOException e) {
134 throw new RuntimeException(e);
135 }
136
137
138 return SKIP_BODY;
139 }
140
141 /***
142 * <p>Get the date which will be formatted into a string when this tag is
143 * used.</p>
144 *
145 * @return the current value of the date to be formatted into a string.
146 */
147 public final Date getDate() {
148 return date;
149 }
150 /***
151 * <p>
152 * This date formatter will do all the hard work.
153 * </p>
154 *
155 * @return current value of dateFormatter.
156 */
157 public final DateFormatter getFormatter() {
158 return formatter;
159 }
160
161 /***
162 * <p>Set the date which will be formatted into a string when this tag is
163 * used.</p>
164 *
165 * @param dateParam the new value of the date to be formatted into a string.
166 */
167 public final void setDate(final Date dateParam) {
168 this.date = dateParam;
169 }
170 /***
171 * <p>
172 * This date formatter will do all the hard work.
173 * </p>
174 *
175 * @param formatterParam new value of date formatter.
176 */
177 public final void setFormatter(final DateFormatter formatterParam) {
178 this.formatter = formatterParam;
179 }
180 }