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
53
54
55
56
57
58
59
60 package com.ivata.mask.web.tag.format;
61
62 import java.io.IOException;
63
64 import javax.servlet.jsp.JspException;
65 import javax.servlet.jsp.JspWriter;
66 import javax.servlet.jsp.tagext.BodyContent;
67 import javax.servlet.jsp.tagext.BodyTagSupport;
68
69 import com.ivata.mask.web.format.HTMLFormatter;
70
71
72 /***
73 * <p>This class wraps the <code>HTMLFormatter</code> class, so that
74 * you can call {@link com.ivata.groupware.web.format.HTMLFormatter#format
75 * HTMLFormatter.format} as a JSP tag.</p>
76 * <p><b>Tag attributes:</b><br/>
77 * <table cellpadding='2' cellspacing='5' border='0' align='center'
78 * width='85%'>
79 * <tr class='TableHeadingColor'>
80 * <th>attribute</th>
81 * <th>reqd.</th>
82 * <th>param. class</th>
83 * <th width='100%'>description</th>
84 * </tr>
85 * <tr class='TableRowColor'>
86 * <td>formatter</td>
87 * <td>false</td>
88 * <td><code>com.ivata.html.format.HTMLFormatter</code></td>
89 * <td>Sets the formatter which actually does the formatting.</td>
90 * </tr>
91 * </table>
92 * </p>
93 *
94 * @since 2002-06-20
95 * @author Colin MacLeod
96 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
97 * @version $Revision: 1.2 $
98 */
99 public class FormatTag extends BodyTagSupport {
100 /***
101 * <p>This is the object which actually does all the hard work. We just wrap
102 * <code>HTMLFormatter.format</code> in a JSP tag.</p>
103 */
104 private HTMLFormatter formatter = null;
105
106 /***
107 * <p>Here the contents of the tag are formatted using the
108 * <code>HTMLFormatter</code> provided.</p>
109 * <p>This method is called after the JSP engine processes the body content
110 * of the tag.</p>
111 *
112 * @return <code>SKIP_BODY</code> since the JSP engine should not evaluate
113 * the tag body again.
114 * @throws JspException encapsulates any exception when calling
115 * <code>out.println</code>.
116 * writeTagBodyContent}.
117 *
118 */
119 public int doAfterBody() throws JspException {
120 try {
121 JspWriter out = getPreviousOut();
122 BodyContent bodyContent = getBodyContent();
123 out.print(formatter.format(bodyContent.getString()));
124 } catch (IOException ex) {
125 throw new JspException("ERROR in FormatTag: " + ex);
126 }
127
128
129 return SKIP_BODY;
130 }
131
132 /***
133 * <p>This method is called when the JSP engine encounters the start tag,
134 * after the attributes are processed.<p>
135 *
136 * <p>Scripting variables (if any) have their values set here.</p>
137 *
138 * @return <code>EVAL_BODY_BUFFERED</code> since the body is always
139 * evaluated once.
140 */
141 public int doStartTag() {
142
143 return EVAL_BODY_BUFFERED;
144 }
145
146 /***
147 * <p>Set the {@link com.ivata.groupware.web.format.HTMLFormatter
148 * HTMLFormatter}
149 * object which actually does all the hard work. We just wrap
150 * <code>HTMLFormatter.format</code> in a JSP tag.</p>
151 * @param formatterParam <code>HTMLFormatter</code> used to format the tag
152 * body.
153 */
154 public void setFormatter(final HTMLFormatter formatterParam) {
155 this.formatter = formatterParam;
156 }
157 }