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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 package com.ivata.mask.web.tag.html;
86 import java.io.IOException;
87 import javax.servlet.jsp.JspException;
88 import javax.servlet.jsp.JspWriter;
89 /***
90 * <p>
91 * Overrides an HTML <code><input type=password></code> tag, by
92 * overriding the class from <strong>Struts </strong>.
93 * </p>
94 *
95 * <p>
96 * <b>Tag attributes: </b> <br/><table cellpadding='2' cellspacing='5'
97 * border='0' align='center' width='85%'>
98 * <tr class='TableHeadingColor'>
99 * <th>attribute</th>
100 * <th>reqd.</th>
101 * <th>param. class</th>
102 * <th width='100%'>description</th>
103 * </tr>
104 * <tr>
105 * <td>fieldName</td>
106 * <td>true</td>
107 * <td><code>java.lang.String</code></td>
108 * <td>The field name is used to default the following attributes of the tag:
109 * <br/>
110 * <ul>
111 * <li><code>styleId</code></li>
112 * <li><code>titleKey</code></li>
113 * <li><code>valueKey</code></li>
114 * </ul>.</td>
115 * </tr>
116 * <tr>
117 * <td>mandatory</td>
118 * <td>false</td>
119 * <td><code>boolean</code></td>
120 * <td>Specifies data for this tag must be entered when the form is submitted.
121 * </td>
122 * </tr>
123 * <tr>
124 * <td>readOnly</td>
125 * <td>false</td>
126 * <td><code>boolean</code></td>
127 * <td>Specifies the form elements should be displayed only and cannot be
128 * altered.</td>
129 * </tr>
130 * </table>
131 * </p>
132 *
133 * <p>
134 * <b>Note: </b> all the tag attributes from {@link
135 * org.apache.struts.taglib.PasswordTag Stuts} are also included.
136 * </p>
137 *
138 * @since ivata masks 0.4 (2003-01-15)
139 * @author Colin MacLeod
140 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
141 * @version $Revision: 1.3 $
142 */
143 public class PasswordTag extends org.apache.struts.taglib.html.PasswordTag {
144 /***
145 * <p>
146 * Stores and maintains <strong>ivata op </strong> specific mask properties.
147 * </p>
148 */
149 private MaskProperties maskProperties = new MaskProperties();
150 /***
151 * <p>
152 * Overridden to set <code>title</code> and <code>value</code>
153 * attributes from keys.
154 * </p>
155 *
156 * @return value returned by superclass method.
157 *
158 * @throws JspException
159 * if there is an error wrting to <code>out.print()</code>
160 */
161 public int doEndTag() throws JspException {
162 if (maskProperties.getReadOnly()) {
163 try {
164
165
166 JspWriter out = pageContext.getOut();
167 out.print("********");
168 return EVAL_PAGE;
169 } catch (IOException e) {
170 throw new JspException("ERROR in PasswordTag: IOException: "
171 + e.getMessage());
172 }
173 }
174 int returnValue = super.doEndTag();
175 maskProperties.reset(this);
176 return returnValue;
177 }
178 /***
179 * <p>
180 * Overridden to remove any value from the password.
181 * </p>
182 *
183 * @return value returned by superclass method, or <code>SKIP_BODY</code>
184 * if this tag is read-only.
185 *
186 * @throws JspException
187 * if either <code>valueKey</code> or <code>titleKey</code>
188 * have not been set, or as thrown by superclass method.
189 */
190 public int doStartTag() throws JspException {
191 maskProperties.doStartTag(this, pageContext);
192
193 this.setValue("");
194 if (maskProperties.getReadOnly()) {
195 return SKIP_BODY;
196 } else {
197
198 return super.doStartTag();
199 }
200 }
201 /***
202 * <p>
203 * Stores and maintains <strong>ivata op </strong> specific mask properties.
204 * </p>
205 *
206 * @return the current value of maskProperties.
207 */
208 public MaskProperties getMaskProperties() {
209 return maskProperties;
210 }
211 /***
212 * <p>
213 * >Name of the field to which this label refers. This is used in
214 * conjunction with the <code>resourceFieldPath</code> to retrieve the
215 * correct message resources path.
216 * </p>
217 *
218 * @param fieldName
219 * the new value of fieldName.
220 */
221 public void setFieldName(final String fieldName) {
222 maskProperties.setFieldName(fieldName);
223 }
224 /***
225 * <p>
226 * Set whether or not the value this control must be entered.
227 * </p>
228 *
229 * @param mandatory
230 * <code>true</code> if this field must be entered, otherwise
231 * <code>false</code> if the field is optional.
232 */
233 public void setMandatory(final boolean mandatory) {
234 maskProperties.setMandatory(mandatory);
235 }
236 /***
237 * <p>
238 * Stores and maintains <strong>ivata op </strong> specific mask properties.
239 * </p>
240 *
241 * @param maskPropertiesParam
242 * the new value of maskProperties.
243 */
244 public void setMaskProperties(final MaskProperties maskPropertiesParam) {
245 this.maskProperties = maskPropertiesParam;
246 }
247 /***
248 * <p>
249 * Specifies whether or not the input values can be altered.
250 * </p>
251 *
252 * @param readOnly
253 * <code>true</code> if the input of this field can be changed,
254 * otherwise <code>false</code> to only display the current
255 * value.
256 */
257 public void setReadOnly(final boolean readOnly) {
258 maskProperties.setReadOnly(readOnly);
259 }
260 }
261