KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > web > tag > SetSettingTag


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware 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: SetSettingTag.java,v $
31  * Revision 1.3 2005/04/10 18:47:42 colinmacleod
32  * Changed i tag to em and b tag to strong.
33  *
34  * Revision 1.2 2005/04/09 17:19:59 colinmacleod
35  * Changed copyright text to GPL v2 explicitly.
36  *
37  * Revision 1.1.1.1 2005/03/10 17:51:35 colinmacleod
38  * Restructured ivata op around Hibernate/PicoContainer.
39  * Renamed ivata groupware.
40  *
41  * Revision 1.2 2004/11/12 15:57:20 colinmacleod
42  * Removed dependencies on SSLEXT.
43  * Moved Persistence classes to ivata masks.
44  *
45  * Revision 1.1 2004/09/30 15:16:02 colinmacleod
46  * Split off addressbook elements into security subproject.
47  *
48  * Revision 1.4 2004/07/13 19:41:15 colinmacleod
49  * Moved project to POJOs from EJBs.
50  * Applied PicoContainer to services layer (replacing session EJBs).
51  * Applied Hibernate to persistence layer (replacing entity EJBs).
52  *
53  * Revision 1.3 2004/03/21 21:16:08 colinmacleod
54  * Shortened name to ivata op.
55  *
56  * Revision 1.2 2004/02/01 22:00:34 colinmacleod
57  * Added full names to author tags
58  *
59  * Revision 1.1.1.1 2004/01/27 20:57:58 colinmacleod
60  * Moved ivata openportal to SourceForge..
61  *
62  * Revision 1.1.1.1 2003/10/13 20:50:10 colin
63  * Restructured portal into subprojects
64  *
65  * Revision 1.1 2003/02/24 19:33:33 colin
66  * moved to jsp
67  *
68  * Revision 1.7 2003/02/04 17:43:51 colin
69  * copyright notice
70  *
71  * Revision 1.6 2002/08/19 12:24:38 colin
72  * tidied documentation; removed Hungarian notation
73  *
74  * Revision 1.5 2002/06/13 07:44:07 colin
75  * first version of rose model: code tidied up/added javadoc
76  *
77  * Revision 1.4 2002/05/11 18:32:41 colin
78  * changed the name of the remote settings instance in the
79  * session from "SettingsRemote" to "settings" for easier
80  * usage in JSP files
81  *
82  * Revision 1.3 2002/05/11 08:54:06 colin
83  * updated and extended javadoc
84  *
85  * Revision 1.1 2002/02/03 19:41:11 colin
86  * corrected misspellt getSetting to GetSetting in class names
87  *
88  * Revision 1.1 2002/02/03 01:00:46 colin
89  * first version for shop
90  * -----------------------------------------------------------------------------
91  */

92 package com.ivata.groupware.web.tag;
93
94 import javax.servlet.http.HttpSession JavaDoc;
95 import javax.servlet.jsp.JspException JavaDoc;
96 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
97
98 import org.picocontainer.PicoContainer;
99
100 import com.ivata.groupware.admin.security.Security;
101 import com.ivata.groupware.admin.security.server.SecuritySession;
102 import com.ivata.groupware.admin.security.user.UserDO;
103 import com.ivata.groupware.admin.setting.Settings;
104 import com.ivata.mask.util.SystemException;
105
106
107 /**
108  * <p>This tag tries to set the setting for the user specified by the
109  * attribute 'userName'. If that has not been set, then the default
110  * setting is
111  * altered.</p>
112  *
113  * <p>Normally there is a settings object in the session called
114  * 'SettingsRemote'
115  * and this is used internally to access the ivata groupware settings
116  * system.</p>
117  *
118  * <p><strong>Tag attributes:</strong><br/>
119  * <table cellpadding='2' cellspacing='5' border='0' align='center'
120  * width='85%'>
121  * <tr class='TableHeadingColor'>
122  * <th>attribute</th>
123  * <th>reqd.</th>
124  * <th>param. class</th>
125  * <th width='100%'>description</th>
126  * </tr>
127  * <tr class='TableRowColor'>
128  * <td>setting</td>
129  * <td>true</td>
130  * <td><code>String</code></td>
131  * <td>The name of the setting to change in the ivata groupware
132  * system.</td>
133  * </tr>
134  * <tr class='TableRowColor'>
135  * <td>userName</td>
136  * <td>false</td>
137  * <td><code>String</code></td>
138  * <td>The name of the user for whom the setting will be make. If
139  * this
140  * attribute is not set, then the default setting is altered.</td>
141  * </tr>
142  * <tr class='TableRowColor'>
143  * <td>value</td>
144  * <td>true</td>
145  * <td><code>Object</code></td>
146  * <td>The new value for the setting specified. This object
147  * should
148  * be
149  * of type <code>Integer</code> or
150  * <code>String</code>
151  * or <code>Boolean</code> and the type will be noted in
152  * the
153  * ivata groupware settings.</td>
154  * </tr>
155  * </table>
156  * </p>
157  *
158  * @since 2002-02-02
159  * @author Colin MacLeod
160  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
161  * @version $Revision: 1.3 $
162  */

163 public class SetSettingTag extends TagSupport JavaDoc {
164     /**
165      * <p>Property declaration for tag attribute: setting.</p>
166      */

167     private String JavaDoc setting = null;
168     /**
169      * <p>Property declaration for tag attribute: userName.</p>
170      */

171     private String JavaDoc userName = null;
172     /**
173      * <p>Property declaraion for tag attribute: value.</p>
174      */

175     private Object JavaDoc value = null;
176
177     /**
178      * <p>Default constructor.</p>
179
180      */

181     public SetSettingTag() {
182         super();
183     }
184
185     /**
186      * <p>This method is called after the JSP engine finished processing
187      * the tag.</p>
188      *
189      * @return <code>EVAL_PAGE</code> since we always want to evaluate the
190      * rest of the page
191      */

192     public int doEndTag() {
193         // we want the rest of the page after this tag to be evaluated...
194
return EVAL_PAGE;
195     }
196
197     /**
198      * <p>This method is called when the JSP engine encounters the start
199      * tag, after the attributes are processed.<p>
200      *
201      * <p>Scripting variables (if any) have their values set here.</p>
202      *
203      * @return <code>SKIP_BODY</code> since this tag has no body
204      * @throws JspException if there is no attribute in the session
205      * called 'SettingsRemote'
206      * @throws JspException if there is a
207      * <code>java.rmi.RemoteException</code> assigning the setting
208      */

209     public int doStartTag() throws JspException JavaDoc {
210         // before we do anything else, get the session
211
HttpSession JavaDoc session = pageContext.getSession();
212         SecuritySession securitySession = (SecuritySession)
213             session.getAttribute("securitySession");
214
215         if(securitySession == null) {
216             throw new JspException JavaDoc("Error in SetSettingTag: no security session object was set in the servlet session");
217         }
218         PicoContainer container = securitySession.getContainer();
219         Settings settings = (Settings) container.getComponentInstance(Settings.class);
220         Security security = (Security) container.getComponentInstance(Security.class);
221
222         try {
223             UserDO user = userName == null ? null : security.findUserByName(securitySession, userName);
224             settings.amendSetting(securitySession, setting, value, user);
225         } catch(SystemException e) {
226             throw new JspException JavaDoc(e);
227         }
228         // indicates that the body should not be evaluated - this tag has no body
229
return SKIP_BODY;
230     }
231
232     /**
233      * <p>Get the value supplied to the attribute 'setting'.</p>
234      *
235      * <p>This attribute represents the name of the setting to change in
236      * the ivata groupware system.</p>
237      *
238      * @return the value supplied to the attribute 'setting'
239      */

240     public final String JavaDoc getSetting() {
241         return setting;
242     }
243
244     /**
245      * <p>Get the value supplied to the attribute 'userName'.</p>
246      *
247      * <p>This attribute represents the name of the user for whom the
248      * setting will be made. If this attribute is not set, then the
249      * default setting is altered.</p>
250      *
251      * @return the value supplied to the tag attribute 'userName'
252      */

253     public final String JavaDoc getUserName() {
254         return userName;
255     }
256
257     /**
258      * <p>Get the value supplied to the attribute 'value'.</p>
259      *
260      * <p>This attribute represents the new value for the setting
261      * specified. This object should be of type
262      * <code>Integer</code>, <code>String</code> or
263      * <code>Boolean</code> and the type will be noted in the
264      * ivata groupware settings.</p>
265      *
266      * @return the value supplied to the attribute 'value'
267      */

268     public final Object JavaDoc getValue() {
269         return value;
270     }
271
272     /**
273      * <p>Set the value supplied to the attribute 'setting'.</p>
274      *
275      * <p>This attribute represents the name of the setting to change in
276      * the ivata groupware system.</p>
277      *
278      * @param setting the value supplied to the attribute 'setting'
279      */

280     public final void setSetting(final String JavaDoc setting) {
281         this.setting = setting;
282     }
283
284     /**
285      * <p>Set the value supplied to the tag attribute 'userName'</p>
286      *
287      * <p>This attribute represents the name of the user for whom the
288      * setting will be made. If this attribute is not set, then the
289      * default setting is altered.</p>
290      *
291      * @param userName the value supplied to the tag attribute 'userName'
292      */

293     public final void setUserName(final String JavaDoc userName) {
294         this.userName = userName;
295     }
296
297     /**
298      * <p>Set the value supplied to the attribute 'value'.</p>
299      *
300      * <p>This attribute represents the new value for the setting
301      * specified. This object should be of type
302      * <code>Integer</code>, <code>String</code> or
303      * <code>Boolean</code> and the type will be noted in the
304      * ivata groupware settings.</p>
305      *
306      * @param value the value supplied to the attribute 'value'
307      */

308     public final void setValue(final Object JavaDoc value) {
309         this.value = value;
310     }
311 }
312
Popular Tags