KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > business > library > struts > FindTopicAction


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: FindTopicAction.java,v $
31  * Revision 1.4 2005/04/29 02:48:16 colinmacleod
32  * Data bugfixes.
33  * Changed primary key back to Integer.
34  *
35  * Revision 1.3 2005/04/10 20:31:58 colinmacleod
36  * Added new themes.
37  * Changed id type to String.
38  * Changed i tag to em and b tag to strong.
39  * Improved PicoContainerFactory with NanoContainer scripts.
40  *
41  * Revision 1.2 2005/04/09 17:19:46 colinmacleod
42  * Changed copyright text to GPL v2 explicitly.
43  *
44  * Revision 1.1.1.1 2005/03/10 17:52:05 colinmacleod
45  * Restructured ivata op around Hibernate/PicoContainer.
46  * Renamed ivata groupware.
47  *
48  * Revision 1.10 2004/12/31 18:27:44 colinmacleod
49  * Added MaskFactory to constructor of MaskAction.
50  *
51  * Revision 1.9 2004/12/23 21:01:29 colinmacleod
52  * Updated Struts to v1.2.4.
53  * Changed base classes to use ivata masks.
54  *
55  * Revision 1.8 2004/11/12 18:19:15 colinmacleod
56  * Change action and form classes to extend MaskAction, MaskForm respectively.
57  *
58  * Revision 1.7 2004/11/12 15:57:16 colinmacleod
59  * Removed dependencies on SSLEXT.
60  * Moved Persistence classes to ivata masks.
61  *
62  * Revision 1.6 2004/11/03 15:31:51 colinmacleod
63  * Change method interfaces to remove log.
64  *
65  * Revision 1.5 2004/07/13 19:47:29 colinmacleod
66  * Moved project to POJOs from EJBs.
67  * Applied PicoContainer to services layer (replacing session EJBs).
68  * Applied Hibernate to persistence layer (replacing entity EJBs).
69  *
70  * Revision 1.4 2004/03/21 21:16:29 colinmacleod
71  * Shortened name to ivata op.
72  *
73  * Revision 1.3 2004/02/10 19:57:23 colinmacleod
74  * Changed email address.
75  *
76  * Revision 1.2 2004/02/01 22:07:31 colinmacleod
77  * Added full names to author tags
78  *
79  * Revision 1.1.1.1 2004/01/27 20:58:41 colinmacleod
80  * Moved ivata openportal to SourceForge..
81  *
82  * Revision 1.3 2003/10/28 13:16:14 jano
83  * commiting library,
84  * still fixing compile and building openGroupware project
85  *
86  * Revision 1.2 2003/10/15 14:16:53 colin
87  * fixing for XDoclet
88  *
89  * Revision 1.2 2003/03/03 16:57:12 colin
90  * converted localization to automatic paths
91  * added labels
92  * added mandatory fieldName attribute
93  *
94  * Revision 1.1 2003/02/24 19:09:24 colin
95  * moved to business
96  *
97  * Revision 1.9 2003/02/04 17:43:50 colin
98  * copyright notice
99  *
100  * Revision 1.8 2003/01/18 20:21:18 colin
101  * conversion to new MaskAction methods
102  * -----------------------------------------------------------------------------
103  */

104 package com.ivata.groupware.business.library.struts;
105
106 import java.lang.reflect.InvocationTargetException JavaDoc;
107
108 import javax.servlet.http.HttpServletRequest JavaDoc;
109 import javax.servlet.http.HttpServletResponse JavaDoc;
110 import javax.servlet.http.HttpSession JavaDoc;
111
112 import org.apache.commons.beanutils.PropertyUtils;
113 import org.apache.struts.action.ActionErrors;
114 import org.apache.struts.action.ActionForm;
115 import org.apache.struts.action.ActionMapping;
116
117 import com.ivata.groupware.admin.security.server.SecuritySession;
118 import com.ivata.groupware.business.addressbook.person.group.right.RightConstants;
119 import com.ivata.groupware.business.library.Library;
120 import com.ivata.groupware.business.library.right.LibraryRights;
121 import com.ivata.groupware.business.library.topic.TopicDO;
122 import com.ivata.mask.MaskFactory;
123 import com.ivata.mask.util.StringHandling;
124 import com.ivata.mask.util.SystemException;
125 import com.ivata.mask.web.struts.MaskAction;
126 import com.ivata.mask.web.struts.MaskAuthenticator;
127
128
129 /**
130  * <p><code>Action</code> invoked when you calling topicModify.jsp
131  * from topic.jsp.</p>
132  * <!--**********************************************************************-->
133  *
134  * @since 2002-11-22
135  * @author Jan Boros <janboros@sourceforge.net>
136  * @version $Revision: 1.4 $
137  */

138 public class FindTopicAction extends MaskAction {
139     Library library;
140     LibraryRights libraryRights;
141
142     /**
143      * TODO
144      * @param library
145      * @param libraryRights
146      * @param maskFactory This factory is needed to access the masks and groups
147      * of masks.
148      * @param authenticator used to confirm whether or not the
149      * user should be allowed to continue, in the <code>execute</code> method.
150      */

151     public FindTopicAction(Library library, LibraryRights libraryRights,
152             MaskFactory maskFactory, MaskAuthenticator authenticator) {
153         super(maskFactory, authenticator);
154         this.library = library;
155         this.libraryRights = libraryRights;
156     }
157
158     /**
159      * <p>Submit or cancel the form in
160      * <code>/library/topicModify.jsp</code>.</p>
161      *
162      * @param mapping current action mapping from <em>Struts</em> config.
163      * @param log valid logging object to write messages to.
164      * @param errors valid errors object to append errors to. If there are
165      * any errors, the action will return to the input.
166      * @param form optional ActionForm bean for this request (if any)
167      * @param request non-HTTP request we are processing
168      * @param response The non-HTTP response we are creating
169      * @param session returned from the <code>request</code> parameter.
170      * @param userName current user name from session. .
171      * @param settings valid, non-null settings from session.
172      * @exception SystemException if there is any problem which
173      * prevents processing. It will result in the webapp being forwarded
174      * to
175      * the standard error page.
176      * @return this method returns the string used to identify the correct
177      * <em>Struts</em> <code>ActionForward</code> which should follow this
178      * page, or <code>null</code> if it should return to the input.
179      *
180      */

181     public String JavaDoc execute(final ActionMapping mapping,
182             final ActionErrors errors,
183             final ActionForm form,
184             final HttpServletRequest JavaDoc request,
185             final HttpServletResponse JavaDoc response,
186             final HttpSession JavaDoc session) throws SystemException {
187         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
188         try {
189             TopicForm libraryTopicForm = new TopicForm(library);
190
191             // request parameter overrides
192
String JavaDoc requestId = request.getParameter(
193                         "id");
194             Integer JavaDoc id;
195             if (requestId != null) {
196                 id = StringHandling.integerValue(requestId);
197             } else {
198                 id = (Integer JavaDoc) PropertyUtils.getSimpleProperty(form, "id");
199             }
200
201             TopicDO topic = library.findTopicByPrimaryKey(securitySession, id);
202
203             libraryTopicForm.setTopic(topic);
204
205             // set view rights to ITEM in the form
206
java.util.Collection JavaDoc rights = libraryRights.findRightsForItemsInTopic(
207                     securitySession,
208                     id,
209                     RightConstants.ACCESS_VIEW);
210             Integer JavaDoc[] tmp = new Integer JavaDoc[rights.size()];
211             int a = 0;
212
213             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
214                 tmp[a] = (Integer JavaDoc) i.next();
215                 a++;
216             }
217
218             libraryTopicForm.setRightsViewItem(tmp);
219
220             // set add rights to ITEM in the form
221
rights = libraryRights.findRightsForItemsInTopic(securitySession,
222                     id,
223                     RightConstants.ACCESS_ADD);
224             tmp = new Integer JavaDoc[rights.size()];
225             a = 0;
226
227             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
228                 tmp[a] = (Integer JavaDoc) i.next();
229                 a++;
230             }
231
232             libraryTopicForm.setRightsAddItem(tmp);
233
234             // set amend rights to ITEM in the form
235
rights = libraryRights.findRightsForItemsInTopic(securitySession,
236                     id,
237                     RightConstants.ACCESS_AMEND);
238             tmp = new Integer JavaDoc[rights.size()];
239             a = 0;
240
241             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
242                 tmp[a] = (Integer JavaDoc) i.next();
243                 a++;
244             }
245
246             libraryTopicForm.setRightsAmendItem(tmp);
247
248             // set delete rights to ITEM in the form
249
rights = libraryRights.findRightsForItemsInTopic(securitySession,
250                     id,
251                     RightConstants.ACCESS_REMOVE);
252             tmp = new Integer JavaDoc[rights.size()];
253             a = 0;
254
255             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
256                 tmp[a] = (Integer JavaDoc) i.next();
257                 a++;
258             }
259
260             libraryTopicForm.setRightsRemoveItem(tmp);
261
262             // set view rights to TOPIC in the form
263
rights = libraryRights.findRightsForTopic(securitySession,
264                     id,
265                     RightConstants.ACCESS_VIEW);
266             tmp = new Integer JavaDoc[rights.size()];
267             a = 0;
268
269             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
270                 tmp[a] = (Integer JavaDoc) i.next();
271                 a++;
272             }
273
274             libraryTopicForm.setRightsView(tmp);
275
276             // set amend rights to TOPIC in the form
277
rights = libraryRights.findRightsForTopic(securitySession,
278                     id,
279                     RightConstants.ACCESS_AMEND);
280             tmp = new Integer JavaDoc[rights.size()];
281             a = 0;
282
283             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
284                 tmp[a] = (Integer JavaDoc) i.next();
285                 a++;
286             }
287
288             libraryTopicForm.setRightsAmend(tmp);
289
290             // set delete rights to TOPIC in the form
291
rights = libraryRights.findRightsForTopic(securitySession,
292                     id,
293                     RightConstants.ACCESS_REMOVE);
294             tmp = new Integer JavaDoc[rights.size()];
295             a = 0;
296
297             for (java.util.Iterator JavaDoc i = rights.iterator(); i.hasNext();) {
298                 tmp[a] = (Integer JavaDoc) i.next();
299                 a++;
300             }
301
302             libraryTopicForm.setRightsRemove(tmp);
303             libraryTopicForm.setTopicTab_activeTab(new Integer JavaDoc(0));
304             session.setAttribute("libraryTopicForm", libraryTopicForm);
305             session.removeAttribute("topicTab_activeTab");
306
307             // Forward control to the topicModify.jsp - FORM for add new or modify existing TOPIC
308
return "libraryTopic";
309         } catch (NoSuchMethodException JavaDoc e) {
310             throw new SystemException(e);
311         } catch (InvocationTargetException JavaDoc e) {
312             throw new SystemException(e);
313         } catch (IllegalAccessException JavaDoc e) {
314             throw new SystemException(e);
315         }
316     }
317 }
318
Popular Tags