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 package com.ivata.mask.web.tag.util;
77
78
79 import java.util.Properties;
80
81 import javax.servlet.jsp.JspException;
82 import javax.servlet.jsp.PageContext;
83 import javax.servlet.jsp.tagext.TagSupport;
84
85
86 /***
87 * <p>This tag is used as a simple way to set an property value on the class
88 * <code>java.util.Property</code> as used by all the webgui tabs</p>
89 *
90 * <p><b>Tag attributes:</b><br/>
91 * <table cellpadding='2' cellspacing='5' border='0' align='center'
92 * width='85%'>
93 * <tr class='TableHeadingColor'>
94 * <th>attribute</th>
95 * <th>reqd.</th>
96 * <th>param. class</th>
97 * <th width='100%'>description</th>
98 * </tr>
99 * <tr class='TableRowColor'>
100 * <td>name</td>
101 * <td>true</td>
102 * <td><code>String</code></td>
103 * <td>The name of the <code>java.util.Properties</code> where the property
104 * should be set.</td>
105 * </tr>
106 * <tr class='TableRowColor'>
107 * <td>property</td>
108 * <td>true</td>
109 * <td><code>String</code></td>
110 * <td>The name of the property to set.</td>
111 * </tr>
112 * <tr class='TableRowColor'>
113 * <td>value</td>
114 * <td>true</td>
115 * <td><code>String</code></td>
116 * <td>The new value for the property.</td>
117 * </tr>
118 * </table>
119 * </p>
120 *
121 * @since ivata masks 0.5 (2001-12-16)
122 * @author Colin MacLeod
123 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
124 * @version $Revision: 1.2 $
125 */
126 public class SetPropertyTag extends TagSupport {
127
128 /***
129 * <p>Property declaration for tag attribute: name.</p>
130 */
131 private String name;
132
133 /***
134 * <p>This variable contains the referenced properties instance.</p>
135 */
136 private Properties properties = null;
137
138 /***
139 * <p>Property declaration for tag attribute: property.</p>
140 */
141 private String property;
142
143 /***
144 * <p>Property declaration for tag attribute: value.</p>
145 */
146 private String value;
147
148 /***
149 * <p>Default constructor.</p>
150 *
151 */
152 public SetPropertyTag() {
153 super();
154 }
155
156 /***
157 * <p>This is where the property actually gets set, whent the class
158 * encounters
159 * the closed, start tag.</p>
160 *
161 * <p>This method is called when the JSP engine encounters the start tag,
162 * after the attributes are processed.<p>
163 *
164 * <p>Scripting variables (if any) have their values set here.</p>
165 *
166 * @exception JspException thrown if there is no valid
167 * <code>Properties</code>
168 * in this object.
169 * @return <code>SKIP_BODY</code> since this tag has no body
170 */
171 public int doStartTag() throws JspException {
172 super.doStartTag();
173
174 if (properties == null) {
175 throw new JspException(
176 "Error in SetPropertyTag: no properties object set");
177 }
178 properties.setProperty(property, value);
179 return SKIP_BODY;
180 }
181
182 /***
183 * <p>Get the value supplied to the attribute 'name'.</p>
184 *
185 * <p>This attribute represents the name of the
186 * <code>java.util.Properties</code>
187 * where the property should be set.</p>
188 *
189 * @return the value supplied to the tag attribute 'name'
190 *
191 */
192 public final String getName() {
193 return name;
194 }
195
196 /***
197 * <p>Get the actual properties in which the value will be set.</p>
198 *
199 * @return the current value of properties.
200 */
201 public final Properties getProperties() {
202 return properties;
203 }
204
205 /***
206 * <p>Get the value supplied to the attribute 'property'.</p>
207 *
208 * <p>This attribute represents the name of the property to set.</p>
209 *
210 * @return the value supplied to the tag attribute 'property'
211 *
212 */
213 public final String getProperty() {
214 return property;
215 }
216
217 /***
218 * <p>Get the value supplied to the attribute 'value'.</p>
219 *
220 * <p>This attribute represents the new value for the property.</p>
221 *
222 * @return the value supplied to the tag attribute 'value'
223 *
224 */
225 public final String getValue() {
226 return value;
227 }
228
229 /***
230 * <p>Set the value supplied to the attribute 'name'.</p>
231 *
232 * <p>This attribute represents the name of the
233 * <code>java.util.Properties</code>
234 * where the property should be set. Calling this method will cause the
235 * class to
236 * look for a new properties objec with this name first at page and then
237 * session
238 * scope. If none is found an exception is thrown.</p>
239 *
240 * @exception JspException thrown if there is no properties instance
241 * with this name at either page or session scope.
242 * @param nameParam the new value supplied to the tag attribute 'name'
243 */
244 public final void setName(final String nameParam) throws JspException {
245 this.name = nameParam;
246 properties = (Properties) pageContext.getAttribute(nameParam,
247 PageContext.PAGE_SCOPE);
248 if (properties == null) {
249 properties = (Properties) pageContext.getAttribute(nameParam,
250 PageContext.SESSION_SCOPE);
251 if (properties == null) {
252 throw new JspException(
253 "Error in SetPropertyTag: no properties found at page "
254 + "or session scope for this name: '"
255 + nameParam
256 + "'");
257 }
258 }
259 }
260
261 /***
262 * <p>Set the actual properties in which the value will be set.</p>
263 *
264 * @param propertiesParam the new value of properties instance for which the
265 * value should be set.
266 */
267 public final void setProperties(final Properties propertiesParam) {
268 this.properties = propertiesParam;
269 }
270
271 /***
272 * <p>Set the value supplied to the attribute 'property'.</p>
273 *
274 * <p>This attribute represents the name of the property to set.</p>
275 *
276 * @param propertyParam the name or key of the property to set in the
277 * properties.
278 */
279 public final void setProperty(final String propertyParam) {
280 this.property = propertyParam;
281 }
282
283 /***
284 * <p>Set the value supplied to the attribute 'value'.</p>
285 *
286 * <p>This attribute represents the new value for the property.</p>
287 *
288 * @param valueParam the new value supplied to the tag attribute 'value'
289 */
290 public final void setValue(final String valueParam) {
291 this.value = valueParam;
292 }
293 }