KickJava   Java API By Example, From Geeks To Geeks.

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


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: IndexAction.java,v $
31  * Revision 1.4 2005/05/01 08:47:32 colinmacleod
32  * Cosmetic (line length) changes.
33  *
34  * Revision 1.3 2005/04/10 18:47:39 colinmacleod
35  * Changed i tag to em and b tag to strong.
36  *
37  * Revision 1.2 2005/04/09 17:19:46 colinmacleod
38  * Changed copyright text to GPL v2 explicitly.
39  *
40  * Revision 1.1.1.1 2005/03/10 17:51:59 colinmacleod
41  * Restructured ivata op around Hibernate/PicoContainer.
42  * Renamed ivata groupware.
43  *
44  * Revision 1.6 2004/12/31 18:27:44 colinmacleod
45  * Added MaskFactory to constructor of MaskAction.
46  *
47  * Revision 1.5 2004/12/23 21:01:29 colinmacleod
48  * Updated Struts to v1.2.4.
49  * Changed base classes to use ivata masks.
50  *
51  * Revision 1.4 2004/11/12 18:19:15 colinmacleod
52  * Change action and form classes to extend MaskAction, MaskForm respectively.
53  *
54  * Revision 1.3 2004/11/12 15:57:16 colinmacleod
55  * Removed dependencies on SSLEXT.
56  * Moved Persistence classes to ivata masks.
57  *
58  * Revision 1.2 2004/11/03 15:31:51 colinmacleod
59  * Change method interfaces to remove log.
60  *
61  * Revision 1.1 2004/07/13 19:47:29 colinmacleod
62  * Moved project to POJOs from EJBs.
63  * Applied PicoContainer to services layer (replacing session EJBs).
64  * Applied Hibernate to persistence layer (replacing entity EJBs).
65  * -----------------------------------------------------------------------------
66  */

67 package com.ivata.groupware.business.library.struts;
68
69 import java.lang.reflect.InvocationTargetException JavaDoc;
70 import java.util.Collection JavaDoc;
71 import java.util.HashMap JavaDoc;
72 import java.util.Iterator JavaDoc;
73 import java.util.Map JavaDoc;
74
75 import javax.servlet.http.HttpServletRequest JavaDoc;
76 import javax.servlet.http.HttpServletResponse JavaDoc;
77 import javax.servlet.http.HttpSession JavaDoc;
78
79 import org.apache.commons.beanutils.PropertyUtils;
80 import org.apache.struts.action.ActionErrors;
81 import org.apache.struts.action.ActionForm;
82 import org.apache.struts.action.ActionMapping;
83 import org.picocontainer.PicoContainer;
84
85 import com.ivata.groupware.admin.security.server.SecuritySession;
86 import com.ivata.groupware.admin.setting.Settings;
87 import com.ivata.groupware.business.addressbook.AddressBook;
88 import com.ivata.groupware.business.addressbook.person.group.right.RightConstants;
89 import com.ivata.groupware.business.library.Library;
90 import com.ivata.groupware.business.library.item.LibraryItemDO;
91 import com.ivata.groupware.business.mail.Mail;
92 import com.ivata.mask.MaskFactory;
93 import com.ivata.mask.persistence.PersistenceManager;
94 import com.ivata.mask.util.SystemException;
95 import com.ivata.mask.web.format.HTMLFormatter;
96 import com.ivata.mask.web.struts.MaskAction;
97 import com.ivata.mask.web.struts.MaskAuthenticator;
98
99
100 /**
101  * <p>
102  * Retrieves a list of recent library items.
103  * </p>
104  *
105  * @since 2004-06-27
106  * @author Colin MacLeod
107  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
108  * @version $Revision: 1.4 $
109  */

110 public class IndexAction extends MaskAction {
111     private Library library;
112     private Settings settings;
113     /**
114      * TODO
115      * @param securitySession
116      * @param settings
117      * @param maskFactory This factory is needed to access the masks and groups
118      * of masks.
119      * @param authenticator used to confirm whether or not the
120      * user should be allowed to continue, in the <code>execute</code> method.
121      */

122     public IndexAction(SecuritySession securitySession, Settings settings,
123             MaskFactory maskFactory, MaskAuthenticator authenticator) {
124         super(maskFactory, authenticator);
125         PicoContainer container = securitySession.getContainer();
126         Object JavaDoc object = container.getComponentInstance(PersistenceManager.class);
127         object = container.getComponentInstance(AddressBook.class);
128         object = container.getComponentInstance(Mail.class);
129         object = container.getComponentInstance(Settings.class);
130         object = container.getComponentInstance(HTMLFormatter.class);
131         this.library = (Library) container.getComponentInstance(Library.class);
132 // this.library = library;
133
this.settings = settings;
134     }
135
136
137     /**
138      * <p>
139      * Retrieves a list of recent library items.
140      * </p>
141      *
142      * @param mapping current action mapping from <em>Struts</em> config.
143      * @param log valid logging object to write messages to.
144      * @param errors valid errors object to append errors to. If there are
145      * any errors, the action will return to the input.
146      * @param form optional ActionForm bean for this request (if any)
147      * @param request non-HTTP request we are processing
148      * @param response The non-HTTP response we are creating
149      * @param session returned from the <code>request</code> parameter.
150      * @param userName current user name from session. .
151      * @param settings valid, non-null settings from session.
152      * @exception SystemException if there is any problem which
153      * prevents processing. It will result in the webapp being forwarded
154      * to
155      * the standard error page.
156      * @return this method returns the string used to identify the correct
157      * <em>Struts</em> <code>ActionForward</code> which should follow this
158      * page, or <code>null</code> if it should return to the input.
159      *
160      */

161     public String JavaDoc execute(final ActionMapping mapping,
162             final ActionErrors errors,
163             final ActionForm form,
164             final HttpServletRequest JavaDoc request,
165             final HttpServletResponse JavaDoc response,
166             final HttpSession JavaDoc session) throws SystemException {
167         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
168
169         try {
170             Integer JavaDoc libraryHome = settings.getIntegerSetting(securitySession,
171                     "libraryHome", securitySession.getUser());
172             Integer JavaDoc libraryRecent = settings.getIntegerSetting(securitySession,
173                     "libraryRecent", securitySession.getUser());
174             int numberOfItems = libraryHome.intValue();
175             int numberOfRecent = libraryRecent.intValue();
176             int numberToRead = (numberOfRecent > numberOfItems) ? numberOfRecent : numberOfItems;
177
178             Collection JavaDoc items = library.findRecentItems(securitySession, new Integer JavaDoc(numberToRead),
179                     RightConstants.ACCESS_VIEW, null);
180             PropertyUtils.setProperty(form, "items", items);
181
182             Iterator JavaDoc itemIterator = items.iterator();
183
184             Map JavaDoc commentsForItem = new HashMap JavaDoc();
185             while(itemIterator.hasNext()) {
186                 LibraryItemDO item = (LibraryItemDO) itemIterator.next();
187                 int commentCount = library.countCommentsForItem(securitySession,
188                         item.getId());
189                 commentsForItem.put(item.getId(), new Integer JavaDoc(commentCount));
190             }
191             PropertyUtils.setProperty(form, "commentsForItem", commentsForItem);
192
193             Collection JavaDoc unacknowledgedComments = library.findUnacknowledgedComments(securitySession, new Integer JavaDoc(10));
194             PropertyUtils.setProperty(form, "unacknowledgedComments", unacknowledgedComments);
195         } catch (IllegalAccessException JavaDoc e) {
196             throw new SystemException(e);
197         } catch (InvocationTargetException JavaDoc e) {
198             throw new SystemException(e);
199         } catch (NoSuchMethodException JavaDoc e) {
200             throw new SystemException(e);
201         }
202
203         // this list always goes to the same page
204
return null;
205     }
206 }
207
Popular Tags