View Javadoc

1   /*
2    * Copyright (c) 2001 - 2005 ivata limited.
3    * All rights reserved.
4    * -----------------------------------------------------------------------------
5    * ivata masks may be redistributed under the GNU General Public
6    * License as published by the Free Software Foundation;
7    * version 2 of the License.
8    *
9    * These programs are free software; you can redistribute them and/or
10   * modify them under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; version 2 of the License.
12   *
13   * These programs are distributed in the hope that they will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   *
17   * See the GNU General Public License in the file LICENSE.txt for more
18   * details.
19   *
20   * If you would like a copy of the GNU General Public License write to
21   *
22   * Free Software Foundation, Inc.
23   * 59 Temple Place - Suite 330
24   * Boston, MA 02111-1307, USA.
25   *
26   *
27   * To arrange commercial support and licensing, contact ivata at
28   *                  http://www.ivata.com/contact.jsp
29   * -----------------------------------------------------------------------------
30   * $Log: SetPropertyTag.java,v $
31   * Revision 1.2  2005/04/09 18:04:20  colinmacleod
32   * Changed copyright text to GPL v2 explicitly.
33   *
34   * Revision 1.1  2005/01/19 12:58:20  colinmacleod
35   * Moved from ivata groupware.
36   *
37   * Revision 1.1  2004/09/30 15:16:03  colinmacleod
38   * Split off addressbook elements into security subproject.
39   *
40   * Revision 1.2  2004/03/21 21:16:18  colinmacleod
41   * Shortened name to ivata op.
42   *
43   * Revision 1.1.1.1  2004/01/27 20:57:58  colinmacleod
44   * Moved ivata openportal to SourceForge..
45   *
46   * Revision 1.1.1.1  2003/10/13 20:50:13  colin
47   * Restructured portal into subprojects
48   *
49   * Revision 1.1  2003/02/25 08:15:50  colin
50   * moved to jsp category
51   *
52   * Revision 1.2  2003/02/04 17:43:51  colin
53   * copyright notice
54   *
55   * Revision 1.1  2002/07/01 10:39:05  colin
56   * moved from webgui to util tag library
57   *
58   * Revision 1.4  2002/06/13 15:45:24  peter
59   * brought over to peter, fixed bugs in webgui property-settings
60   *
61   * Revision 1.2  2002/05/11 17:39:21  colin
62   * updated and extended javadoc
63   *
64   * Revision 1.1  2002/04/27 17:37:48  colin
65   * first compliling version in EJB/JBuilder project
66   *
67   * Revision 1.3  2002/01/24 13:19:40  colin
68   * consolidated hanlding of theme and properties tags acoss webgui tag
69   * library
70   *
71   * Revision 1.2  2002/01/20 19:28:25  colin
72   * added tab and tree tags
73   * implemented address book functionality
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         // look before you leap
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 }