KickJava   Java API By Example, From Geeks To Geeks.

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


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: SubmitAction.java,v $
31  * Revision 1.6 2005/04/30 13:04:14 colinmacleod
32  * Fixes reverting id type from String to Integer.
33  *
34  * Revision 1.5 2005/04/29 02:48:16 colinmacleod
35  * Data bugfixes.
36  * Changed primary key back to Integer.
37  *
38  * Revision 1.4 2005/04/26 15:07:07 colinmacleod
39  * Consolidated print JSP into display pages (eliminating need for separate print pages).
40  * Renamed Faq to FAQ.
41  *
42  * Revision 1.3 2005/04/10 20:31:58 colinmacleod
43  * Added new themes.
44  * Changed id type to String.
45  * Changed i tag to em and b tag to strong.
46  * Improved PicoContainerFactory with NanoContainer scripts.
47  *
48  * Revision 1.2 2005/04/09 17:19:46 colinmacleod
49  * Changed copyright text to GPL v2 explicitly.
50  *
51  * Revision 1.1.1.1 2005/03/10 17:52:04 colinmacleod
52  * Restructured ivata op around Hibernate/PicoContainer.
53  * Renamed ivata groupware.
54  *
55  * Revision 1.12 2004/12/31 18:27:44 colinmacleod
56  * Added MaskFactory to constructor of MaskAction.
57  *
58  * Revision 1.11 2004/12/23 21:01:29 colinmacleod
59  * Updated Struts to v1.2.4.
60  * Changed base classes to use ivata masks.
61  *
62  * Revision 1.10 2004/11/12 18:19:15 colinmacleod
63  * Change action and form classes to extend MaskAction, MaskForm respectively.
64  *
65  * Revision 1.9 2004/11/12 15:57:16 colinmacleod
66  * Removed dependencies on SSLEXT.
67  * Moved Persistence classes to ivata masks.
68  *
69  * Revision 1.8 2004/11/03 15:31:51 colinmacleod
70  * Change method interfaces to remove log.
71  *
72  * Revision 1.7 2004/08/01 11:45:19 colinmacleod
73  * Restructured search engine into separate subproject.
74  *
75  * Revision 1.6 2004/07/19 22:00:46 colinmacleod
76  * Fixed pages for note.
77  *
78  * Revision 1.5 2004/07/13 19:47:29 colinmacleod
79  * Moved project to POJOs from EJBs.
80  * Applied PicoContainer to services layer (replacing session EJBs).
81  * Applied Hibernate to persistence layer (replacing entity EJBs).
82  *
83  * Revision 1.4 2004/03/21 21:16:29 colinmacleod
84  * Shortened name to ivata op.
85  *
86  * Revision 1.3 2004/03/21 20:30:34 colinmacleod
87  * Changed session variable called mailSession to securityServerSession.
88  *
89  * Revision 1.2 2004/02/01 22:07:31 colinmacleod
90  * Added full names to author tags
91  *
92  * Revision 1.1.1.1 2004/01/27 20:58:42 colinmacleod
93  * Moved ivata openportal to SourceForge..
94  *
95  * Revision 1.4 2004/01/12 14:01:03 jano
96  * fixing bugs
97  *
98  * Revision 1.3 2003/10/28 13:16:14 jano
99  * commiting library,
100  * still fixing compile and building openGroupware project
101  *
102  * Revision 1.2 2003/10/15 14:16:53 colin
103  * fixing for XDoclet
104  *
105  * Revision 1.20 2003/09/05 07:19:42 peter
106  * changes in drive methods
107  * Revision 1.19 2003/08/26 15:16:29 jano
108  * fixing bug with new item
109  *
110  * Revision 1.18 2003/08/20 08:35:08 peter
111  * directory issues fixed
112  *
113  * Revision 1.17 2003/08/18 11:38:55 peter
114  * findByPath replaced by findByParentIdName
115  *
116  * Revision 1.16 2003/07/11 15:08:12 peter
117  * version control comment added
118  *
119  * Revision 1.15 2003/07/08 13:24:25 jano
120  * we have library items in CVS
121  *
122  * Revision 1.14 2003/06/20 13:22:15 jano
123  * we want deleteFile button in list of attached files
124  *
125  * Revision 1.13 2003/06/20 06:56:50 jano
126  * fixing removing uploading files
127  *
128  * Revision 1.12 2003/06/03 05:08:00 peter
129  * changes due to posibility to change filelist from display mode
130  *
131  * Revision 1.11 2003/05/22 10:07:03 jano
132  * we have difrent directory, we are not using "item" but "drive" for uploading files
133  *
134  * Revision 1.10 2003/05/20 08:29:40 jano
135  * maintaing attaching files to libray item
136  *
137  * Revision 1.9 2003/05/13 15:41:00 jano
138  * new methods in DriveBean
139  *
140  * Revision 1.8 2003/04/14 07:14:19 peter
141  * helpKey logic
142  *
143  * Revision 1.7 2003/03/12 14:14:48 jano
144  * renaming newHeading -> newPoint
145  * fixing problem arround that
146  *
147  * Revision 1.6 2003/03/04 00:25:58 colin
148  * added type after clear to save for new form after clear button
149  *
150  * Revision 1.5 2003/03/03 20:56:19 colin
151  * added checking for null meeting/category
152  *
153  * Revision 1.4 2003/03/03 19:06:16 colin
154  * fixed changed keys to key suffces for summary field
155  *
156  * Revision 1.3 2003/02/28 10:32:14 colin
157  * fixed bug when cancel is pressed in library submit
158  *
159  * Revision 1.2 2003/02/28 07:30:22 colin
160  * implemented editing/displaying of faqs & notes
161  *
162  * Revision 1.1 2003/02/24 19:09:24 colin
163  * moved to business
164  * -----------------------------------------------------------------------------
165  */

166 package com.ivata.groupware.business.library.struts;
167
168 import java.util.HashMap JavaDoc;
169 import java.util.Iterator JavaDoc;
170 import java.util.List JavaDoc;
171 import java.util.Map JavaDoc;
172 import java.util.Set JavaDoc;
173 import java.util.Vector JavaDoc;
174
175 import javax.servlet.http.HttpServletRequest JavaDoc;
176 import javax.servlet.http.HttpServletResponse JavaDoc;
177 import javax.servlet.http.HttpSession JavaDoc;
178
179 import org.apache.struts.Globals;
180 import org.apache.struts.action.ActionErrors;
181 import org.apache.struts.action.ActionForm;
182 import org.apache.struts.action.ActionMapping;
183 import org.apache.struts.action.ActionMessage;
184 import org.apache.struts.util.MessageResources;
185
186 import com.ivata.groupware.admin.security.server.SecuritySession;
187 import com.ivata.groupware.admin.security.user.UserDO;
188 import com.ivata.groupware.admin.setting.Settings;
189 import com.ivata.groupware.business.library.Library;
190 import com.ivata.groupware.business.library.NotificationException;
191 import com.ivata.groupware.business.library.faq.FAQDO;
192 import com.ivata.groupware.business.library.faq.category.FAQCategoryDO;
193 import com.ivata.groupware.business.library.item.LibraryItemConstants;
194 import com.ivata.groupware.business.library.item.LibraryItemDO;
195 import com.ivata.groupware.business.library.page.PageDO;
196 import com.ivata.groupware.business.library.right.LibraryRights;
197 import com.ivata.groupware.business.library.topic.TopicDO;
198 import com.ivata.mask.MaskFactory;
199 import com.ivata.mask.util.StringHandling;
200 import com.ivata.mask.util.SystemException;
201 import com.ivata.mask.util.ThrowableHandling;
202 import com.ivata.mask.web.struts.MaskAuthenticator;
203
204
205 /**
206  * <p><code>Action</code> invoked whenever a library item is
207  * entered new, or changed.</p>
208  *
209  * @since 2003-02-22
210  * @author Colin MacLeod
211  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
212  * @version $Revision: 1.6 $
213  */

214 public class SubmitAction extends DisplayAction {
215     private Library library;
216     private LibraryRights libraryRights;
217
218     /**
219      * TODO
220      * @param library
221      * @param libraryRights
222      * @param settings
223      * @param maskFactory This factory is needed to access the masks and groups
224      * of masks.
225      * @param authenticator used to confirm whether or not the
226      * user should be allowed to continue, in the <code>execute</code> method.
227      */

228     public SubmitAction(Library library, LibraryRights libraryRights,
229             Settings settings, MaskFactory maskFactory,
230             MaskAuthenticator authenticator) {
231         super(library, settings, maskFactory, authenticator);
232         this.library = library;
233         this.libraryRights = libraryRights;
234     }
235
236     /**
237      * <p>Called when the clear button is pressed, or after an ok or
238      * delete button, where the session should be restored to its default
239      * state.</p>
240      *
241      * @param mapping The ActionMapping used to select this instance.
242      * @param log valid logging object to write messages to.
243      * @param errors valid errors object to append errors to. If there are
244      * any errors, the action will return to the input.
245      * @param form optional ActionForm bean for this request (if any)
246      * @param request non-HTTP request we are processing
247      * @param response The non-HTTP response we are creating
248      * @param session returned from the <code>request</code> parameter.
249      * @param userName valid, non-null user name from session.
250      * @param settings valid, non-null settings from session.
251      * @exception SystemException if there is any problem which
252      * prevents processing. It will result in the webapp being forwarded
253      * to
254      * the standard error page.
255      */

256     public void clear(final ActionMapping mapping,
257             final ActionErrors errors,
258             final ActionForm form,
259             final HttpServletRequest JavaDoc request,
260             final HttpServletResponse JavaDoc response,
261             final HttpSession JavaDoc session) throws SystemException {
262         // so we don't lose the type when clear is pressed
263
request.setAttribute("type", ((ItemForm) form).getItem().getType());
264         ItemForm itemForm = (ItemForm) form;
265         itemForm.clear();
266     }
267     /**
268      * <p>Overridden to TODO:.</p>
269      *
270      * @param mapping current action mapping from <em>Struts</em> config.
271      * @param log valid logging object to write messages to.
272      * @param errors valid errors object to append errors to. If there are
273      * any errors, the action will return to the input.
274      * @param form optional ActionForm bean for this request (if any)
275      * @param request non-HTTP request we are processing
276      * @param response The non-HTTP response we are creating
277      * @param session returned from the <code>request</code> parameter.
278      * @param userName current user name from session. .
279      * @param settings valid, non-null settings from session.
280      * @exception SystemException if there is any problem which
281      * prevents processing. It will result in the webapp being forwarded
282      * to
283      * the standard error page.
284      * @return this method returns the string used to identify the correct
285      * <em>Struts</em> <code>ActionForward</code> which should follow this
286      * page, or <code>null</code> if it should return to the input.
287      *
288      *
289      */

290     public String JavaDoc execute(final ActionMapping mapping,
291             final ActionErrors errors,
292             final ActionForm form,
293             final HttpServletRequest JavaDoc request,
294             final HttpServletResponse JavaDoc response,
295             final HttpSession JavaDoc session) throws SystemException {
296         ItemForm itemForm = (ItemForm) form;
297         LibraryItemDO item = itemForm.getItem();
298
299         // if there is no item yet, or we are told to make a new one, make a new
300
// empty one
301
Integer JavaDoc requestType = StringHandling.integerValue(request.getParameter(
302                     "type"));
303
304         if (requestType == null) {
305             requestType = (Integer JavaDoc) request.getAttribute("type");
306         }
307
308         if ((requestType != null) || (item == null)) {
309             itemForm.reset(mapping, request);
310             itemForm.setPreview(null);
311             itemForm.setSubmitIncludePage(null);
312             itemForm.setItem(item = new LibraryItemDO());
313         }
314
315         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
316         UserDO user = securitySession.getUser();
317         // if we are amending an existing item, check this is ok
318
// we can only amend it if we are the owner or we were given the right to do so
319
if ((item.getId() != null) &&
320                 !(libraryRights.canAmendInTopic(securitySession, item.getTopic().getId()) ||
321                 user.equals(item.getCreatedBy()))) {
322             errors.add(Globals.ERROR_KEY,
323                 new ActionMessage("errors.library.item.amend.rights"));
324
325             return "libraryIndex";
326         }
327
328         // default the item type to plain old document
329
if (item.getType() == null) {
330             if (requestType != null) {
331                 item.setType(requestType);
332             } else {
333                 item.setType(LibraryItemConstants.ITEM_DOCUMENT);
334             }
335         }
336
337         // if the item doesn't contain a meetingDO and it is meeting Item,
338
// then try to find the DO from a request parameter
339
Integer JavaDoc meetingId = StringHandling.integerValue(request.getParameter(
340                     "meetingId"));
341
342         // only note is different
343
itemForm.setSummaryPromptKey("");
344
345         if ((meetingId != null) ||
346                 item.getType().equals(LibraryItemConstants.ITEM_MEETING)) {
347
348             /*
349              * TODO: fix this via subclassing/events
350             MeetingDO meeting;
351
352
353             if (meetingId != null) {
354                 CalendarRemote calendar;
355
356                 if ((calendar = (CalendarRemote) session.getAttribute(
357                                 "calendar")) == null) {
358                     try {
359                         CalendarRemoteHome home = (CalendarRemoteHome) ApplicationServer.findRemoteHome("CalendarRemote",
360                                 CalendarRemoteHome.class);
361
362                         calendar = home.create();
363                         session.setAttribute("calendar", calendar);
364                     } catch (SystemException e) {
365                         throw new SystemException(e);
366                     } catch (NamingException e) {
367                         throw new SystemException(e);
368                     } catch (CreateException e) {
369                         throw new SystemException(e);
370                     }
371                 }
372
373                 try {
374                     meeting = calendar.findMeetingByPrimaryKey(meetingId);
375                 } catch (SystemException e) {
376                     throw new SystemException(e);
377                 }
378
379                 itemForm.setItem(item = new LibraryItemDO());
380                 item.setType(LibraryItemConstants.ITEM_MEETING);
381                 item.setMeeting(meeting);
382                 item.setSummary(meeting.getEvent().getDescription());
383                 item.setTitle(meeting.getEvent().getSubject());
384             } else {
385                 meeting = item.getMeeting();
386             }
387
388             if (meeting == null) {
389                 item.setMeeting(meeting = new MeetingDO());
390             }
391
392             // strip out categories which are empty
393             stripEmptyMeetingCategories(item, request);
394
395             // if the new arrays are empty, or the add button was pressed
396             // add a new category
397             if ((meeting.getCategories().size() == 0) ||
398                     !StringHandling.isNullOrEmpty(itemForm.getNewPage())) {
399                 MessageResources calendarMessages = getResources(request,
400                         "calendar");
401
402                 meeting.addCategory(calendarMessages.getMessage(
403                         (Locale) session.getAttribute(Globals.LOCALE_KEY),
404                         "default.category",
405                         String.valueOf(meeting.getCategories().size() + 1)),
406                     new Vector(), new Vector());
407             }
408              */

409
410             // see if we should add new agenda points to any of the categories
411
// parameter Integer(0) is a TRICK
412
String JavaDoc newHeading = itemForm.getNewPoint(0);
413             int index = 0;
414
415             /* TODO: fix this via subclassing/events
416             for (Iterator i = meeting.getCategories().iterator(); i.hasNext();
417                     ++index) {
418                 i.next();
419
420                 // if we have more categories as AgendaPoints, Minutes -> create new Vector
421                 while (meeting.getAgendaPoints().size() <= index) {
422                     meeting.getAgendaPoints().add(new Vector());
423                 }
424
425                 while (meeting.getMinuteTexts().size() <= index) {
426                     meeting.getMinuteTexts().add(new Vector());
427                 }
428
429                 // if you pressed the button...
430                 if (((newHeading != null) &&
431                         (index == (Integer.valueOf(newHeading)).intValue())) ||
432                         (((Vector) meeting.getAgendaPoints().get(index)).size() == 0)) {
433                     ((Vector) meeting.getAgendaPoints().get(index)).add("");
434                     ((Vector) meeting.getMinuteTexts().get(index)).add("");
435                 }
436             }
437             */

438             // meetings have their own include
439
itemForm.setSubmitIncludePage("/library/submitMeeting.jsp");
440             itemForm.setSummaryTitleKey("submit.title.itemDetails.meeting");
441             itemForm.setHelpKey("library.submit.meeting");
442
443
444             // TODO:
445
throw new RuntimeException JavaDoc("ERROR: illegal dependency on calendar from library");
446
447
448             // frequently asked question stuff here
449
} else if (item.getType().equals(LibraryItemConstants.ITEM_FAQ)) {
450             // strip out pages which are empty
451
stripEmptyFaqCategories(item, request);
452
453             // if the new arrays are empty, or the add button was pressed
454
// add a new category
455
if ((item.getFAQCategories().size() == 0) ||
456                     !StringHandling.isNullOrEmpty(itemForm.getNewPage())) {
457                 FAQCategoryDO faqCategory = new FAQCategoryDO();
458                 faqCategory.setFAQs(new Vector JavaDoc());
459                 item.getFAQCategories().add(faqCategory);
460             }
461
462             // see if we should add questions to any of the categories
463
// parameter Integer(0) is a TRICK
464
String JavaDoc newHeading = itemForm.getNewPoint(0);
465             int index = 0;
466
467             for (Iterator JavaDoc i = item.getFAQCategories().iterator(); i.hasNext();
468                     ++index) {
469                 FAQCategoryDO faqCategory = (FAQCategoryDO) i.next();
470
471                 // if you pressed the button...
472
if (((newHeading != null) &&
473                         (index == (Integer.valueOf(newHeading)).intValue())) ||
474                         (faqCategory.getFAQs().size() == 0)) {
475                     faqCategory.getFAQs().add(new FAQDO());
476                 }
477             }
478
479             // faqs have their own include
480
itemForm.setSubmitIncludePage("/library/submitFAQ.jsp");
481             itemForm.setSummaryTitleKey("submit.title.itemDetails.faq");
482             itemForm.setHelpKey("library.submit.faq");
483
484             // Normal document stuff here
485
} else {
486             // strip out pages which are empty
487
stripEmptyPages(item, request);
488
489             // notes don't have an include page - only documents
490
if (item.getType().equals(LibraryItemConstants.ITEM_NOTE)) {
491                 itemForm.setSummaryTitleKey("submit.title.itemDetails.note");
492                 itemForm.setSummaryPromptKey("note");
493                 itemForm.setHelpKey("library.submit.note");
494             } else {
495                 itemForm.setSubmitIncludePage("/library/submitDocument.jsp");
496                 itemForm.setSummaryTitleKey("submit.title.itemDetails.document");
497                 itemForm.setHelpKey("library.submit.document");
498
499                 // make sure there is at least one page - unless this is a note
500
if ((item.getPages().size() == 0) ||
501                         !StringHandling.isNullOrEmpty(itemForm.getNewPage())) {
502                     item.getPages().add(new PageDO());
503                 }
504             }
505         }
506
507         // set up display information based on the item type
508
chooseItemType(itemForm);
509
510         // set the display page for the preview
511
setPageNumber("/library/submit.action", request, response, itemForm);
512
513 /*TODO try {
514             // setUp uploadingFileList and attachedFileList
515             itemForm.setUploadingFileList((java.util.Vector) drive.getUploads(
516                     "drive", userName));
517
518             if (item.getId() == null) {
519                 itemForm.setFileList(new Vector());
520             } else {
521                 itemForm.setFileList((java.util.Vector) drive.findFilesByPath(
522                         "/library/" + item.getId().toString(), userName));
523             }
524
525             // is user selected any file to remove and he did click on deleteFile button
526             if (!StringHandling.isNullOrEmpty(itemForm.getDeleteFileButton())) {
527                 //remove uploads
528                 if (itemForm.getSelectedNewFilesIds().length > 0) {
529                     itemForm.setUploadingFileList(new Vector(
530                             drive.removeUploads(Arrays.asList(
531                                     itemForm.getSelectedNewFilesIds()),
532                                 "drive", userName)));
533                 }
534
535                 //remove attached files
536                 for (Iterator i = itemForm.getFileList().iterator();
537                         i.hasNext();) {
538                     DriveFileDO tmpFile = (DriveFileDO) i.next();
539
540                     if (itemForm.getSelectedAttachedFilesIds(
541                                 tmpFile.getId().toString()) != null) {
542                         drive.removeFile(tmpFile.getId(), userName);
543                     }
544                 }
545
546                 itemForm.setDeleteFileButton("");
547             }
548
549             // change the drive files only when it's an existing item
550             if (item.getId() != null) {
551                 // add files to repository
552                 java.util.Vector uploadedFileNames = new java.util.Vector();
553
554                 try {
555                     DirectoryDO attachmentDirectoryDO = drive.findDirectoryByParentIdName(DirectoryConstants.LIBRARY_DIRECTORY,
556                             item.getId().toString(), userName);
557
558                     for (Iterator i = itemForm.getUploadingFileList().iterator();
559                             i.hasNext();) {
560                         FileDO fileDO = (FileDO) i.next();
561
562                         // carefull, maybe we did remove this new file
563                         if ((Arrays.asList(itemForm.getSelectedNewFilesIds())).contains(
564                                     fileDO.getFileName())) {
565                             continue;
566                         }
567
568                         DriveFileDO driveFileDO = new DriveFileDO();
569
570                         driveFileDO.setFileName(fileDO.getFileName());
571                         driveFileDO.setDirectoryId(attachmentDirectoryDO.getId());
572                         driveFileDO.setHeadRevision(new FileRevisionDO());
573                         driveFileDO.getHeadRevision().setComment(fileDO.getComment());
574                         driveFileDO.setCreatedBy(userName);
575                         driveFileDO.setMimeType(fileDO.getMimeType());
576                         driveFileDO.setSize(fileDO.getSize());
577                         uploadedFileNames.add(fileDO.getFileName());
578
579                         drive.commitFile(driveFileDO, userName, null);
580                     }
581                 } catch (SystemException e) {
582                     throw new SystemException(e);
583                 }
584
585                 // we add files to CVS -> to item, so ...
586                 // remove uploaded files
587                 try {
588                     itemForm.setUploadingFileList(new Vector(
589                             drive.removeUploads(uploadedFileNames, "drive",
590                                 userName)));
591                 } catch (SystemException e) {
592                     throw new SystemException(e);
593                 }
594
595                 // no wonder that we request back the current attachment list....
596                 itemForm.setFileList((java.util.Vector) drive.findFilesByPath(
597                         "/library/" + item.getId().toString(), userName));
598             }
599         } catch (SystemException e) {
600             throw new SystemException(e);
601         }
602 */

603         // get all the topics we can enter items in
604
List JavaDoc topics = library.findTopics(securitySession);
605         Iterator JavaDoc topicIterator = topics.iterator();
606         Map JavaDoc topicCaptions = new HashMap JavaDoc();
607         Map JavaDoc topicImages = new HashMap JavaDoc();
608         while (topicIterator.hasNext()) {
609             TopicDO topic = (TopicDO) topicIterator.next();
610             Integer JavaDoc id = topic.getId();
611             topicCaptions.put(id, topic.getCaption());
612             topicImages.put(id, topic.getImage());
613         }
614
615         itemForm.setTopicCaptions(topicCaptions);
616         Set JavaDoc topicIds = topicCaptions.keySet();
617         itemForm.setTopicIds(topicIds);
618         itemForm.setTopicImages(topicImages);
619
620         // if there are no topics for you, return to the index
621
if (topicIds.size() == 0) {
622             errors.add(Globals.ERROR_KEY,
623                 new ActionMessage("errors.library.item.submit.noTopicRights"));
624
625             return "libraryIndex";
626         }
627
628         return null;
629     }
630
631     /**
632      * <p>This method is called if the ok or apply buttons are
633      * pressed.</p>
634      *
635      * @param mapping current action mapping from <em>Struts</em> config.
636      * @param log valid logging object to write messages to.
637      * @param errors valid errors object to append errors to. If there are
638      * any errors, the action will return to the input.
639      * @param form optional ActionForm bean for this request (if any)
640      * @param request non-HTTP request we are processing
641      * @param response The non-HTTP response we are creating
642      * @param session returned from the <code>request</code> parameter.
643      * @param userName valid, non-null user name from session.
644      * @param settings valid, non-null settings from session.
645      * @param defaultForward Refer to
646      * {@link com.ivata.mask.web.struts.MaskAction#onConfirm}.
647      * @exception SystemException if there is any problem which
648      * prevents processing. It will result in the webapp being forwarded
649      * to
650      * the standard error page.
651      * @return this method returns the string used to identify the correct
652      * <em>Struts</em> <code>ActionForward</code> which should follow this
653      * page, or <code>null</code> if it should return to the input.
654      *
655      */

656     public String JavaDoc onConfirm(final ActionMapping mapping,
657             final ActionErrors errors,
658             final ActionForm form,
659             final HttpServletRequest JavaDoc request,
660             final HttpServletResponse JavaDoc response,
661             final HttpSession JavaDoc session,
662             final String JavaDoc defaultForward) throws SystemException {
663         ItemForm itemForm = (ItemForm) form;
664         LibraryItemDO item = itemForm.getItem();
665         SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession");
666
667         if (item.getType().equals(LibraryItemConstants.ITEM_MEETING)) {
668             stripEmptyMeetingCategories(item, request);
669         } else if (item.getType().equals(LibraryItemConstants.ITEM_FAQ)) {
670             stripEmptyFaqCategories(item, request);
671         } else {
672             stripEmptyPages(item, request);
673         }
674
675         // insert a new item
676
try {
677             if (item.getId() == null) {
678                 item = library.addItem(securitySession, item,
679                         itemForm.getComment());
680
681                 // update an existing item
682
} else {
683                 library.amendItem(securitySession, item,
684                     itemForm.getComment());
685             }
686         } catch(NotificationException e) {
687             // handle any mail exceptions separately
688
Throwable JavaDoc cause = ThrowableHandling.getCause(e);
689             // this will get picked up by the library notice board page
690
session.setAttribute("libraryNotificationException", e);
691         }
692 /*TODO
693         // now maintain files
694         // add files to repository
695         java.util.Vector uploadedFileNames = new java.util.Vector();
696
697         try {
698             DirectoryDO attachmentDirectoryDO = drive.findDirectoryByParentIdName(DirectoryConstants.LIBRARY_DIRECTORY,
699                     item.getId().toString(), userName);
700
701             for (Iterator i = itemForm.getUploadingFileList().iterator();
702                     i.hasNext();) {
703                 FileDO fileDO = (FileDO) i.next();
704                 DriveFileDO driveFileDO = new DriveFileDO();
705
706                 driveFileDO.setFileName(fileDO.getFileName());
707                 driveFileDO.setDirectoryId(attachmentDirectoryDO.getId());
708                 driveFileDO.setHeadRevision(new FileRevisionDO());
709                 driveFileDO.getHeadRevision().setComment(fileDO.getComment());
710                 driveFileDO.setCreatedBy(userName);
711                 driveFileDO.setMimeType(fileDO.getMimeType());
712                 driveFileDO.setSize(fileDO.getSize());
713                 uploadedFileNames.add(fileDO.getFileName());
714
715                 drive.commitFile(driveFileDO, userName, null);
716             }
717
718             // remove uploaded files
719             drive.removeUploads(uploadedFileNames, "drive", userName);
720         } catch (SystemException e) {
721             throw new SystemException(e);
722         }
723 */

724         return defaultForward;
725     }
726
727     /**
728      * <p>Helper method. Strip empty FAQ categories from the item.</p>
729      *
730      * @param item item to remove empty pages from.
731      * @param request valid request.
732      */

733     private void stripEmptyFaqCategories(final LibraryItemDO item,
734             final HttpServletRequest JavaDoc request) {
735         List JavaDoc newFaqCategories = new Vector JavaDoc();
736
737         if (item.getFAQCategories() != null) {
738             for (Iterator JavaDoc i = item.getFAQCategories().iterator(); i.hasNext();) {
739                 FAQCategoryDO faqCategory = (FAQCategoryDO) i.next();
740                 List JavaDoc newFaqs = new Vector JavaDoc();
741                 Iterator JavaDoc faqIterator = faqCategory.getFAQs().iterator();
742
743                 while (faqIterator.hasNext()) {
744                     FAQDO faq = (FAQDO) faqIterator.next();
745                     String JavaDoc question = (String JavaDoc) faq.getQuestion();
746                     String JavaDoc answer = (String JavaDoc) faq.getAnswer();
747
748                     if (!StringHandling.isNullOrEmpty(question) ||
749                             !StringHandling.isNullOrEmpty(answer)) {
750                         newFaqs.add(faq);
751                     }
752                 }
753
754                 if ((newFaqs.size() != 0) ||
755                         !StringHandling.isNullOrEmpty(faqCategory.getName())) {
756                     faqCategory.setFAQs(newFaqs);
757                     newFaqCategories.add(faqCategory);
758                 }
759             }
760         }
761
762         item.setFAQCategories(newFaqCategories);
763     }
764
765     /**
766      * <p>Helper method. Strip empty meeting categories from the item.</p>
767      *
768      * @param item item to remove empty pages from.
769      * @param request valid request.
770      */

771     private void stripEmptyMeetingCategories(final LibraryItemDO item,
772             final HttpServletRequest JavaDoc request) {
773         Vector JavaDoc newCategories = new Vector JavaDoc();
774         Vector JavaDoc newAgendaPoints = new Vector JavaDoc();
775         Vector JavaDoc newMinuteTexts = new Vector JavaDoc();
776         MessageResources calendarMessages = this.getResources(request,
777                 "calendar");
778         int count = 0;
779
780         /*
781          * TODO: fix this via subclassing/fire events
782         MeetingDO meeting = item.getMeeting();
783         for (int i = 0;
784                 (meeting.getCategories() != null) &&
785                 (i < meeting.getCategories().size()); ++i) {
786             String defaultName = calendarMessages.getMessage((Locale) request.getSession()
787                                                                              .getAttribute(Globals.LOCALE_KEY),
788                     "default.category", new Integer(++count));
789             String category = meeting.getCategory(i);
790             Vector agendaPoints = (Vector) meeting.getAgendaPoints().get(i);
791             Vector minuteTexts = (Vector) meeting.getMinuteTexts().get(i);
792
793             if (StringHandling.isNullOrEmpty(category)) {
794                 // see if there are points or minutes
795                 // go throw all points because if there is not text in input boxes -> there is a empty String in Vector :-(((
796                 // checking !!!! ONLY !!!! agenda points
797                 boolean empty = true;
798
799                 for (Iterator api = agendaPoints.iterator(); api.hasNext();) {
800                     if (!StringHandling.isNullOrEmpty((String) api.next())) {
801                         empty = false;
802
803                         break;
804                     }
805                 }
806
807                 if (!empty) {
808                     // default the text to heading + number
809                     category = defaultName;
810                 } else {
811                     --count;
812
813                     continue;
814                 }
815             }
816
817             // only add if it is not-empty or was set above
818             Vector newSubAgendaPoints = new Vector();
819             Vector newSubMinuteTexts = new Vector();
820             Iterator minuteTextsIterator = minuteTexts.iterator();
821
822             for (Iterator agendaPointsIterator = agendaPoints.iterator();
823                     agendaPointsIterator.hasNext();) {
824                 String agendaPoint = (String) agendaPointsIterator.next();
825                 String minuteText = (String) minuteTextsIterator.next();
826
827                 if (!StringHandling.isNullOrEmpty(agendaPoint) ||
828                         !StringHandling.isNullOrEmpty(minuteText)) {
829                     newSubAgendaPoints.add(StringHandling.getNotNull(
830                             agendaPoint));
831                     newSubMinuteTexts.add(StringHandling.getNotNull(minuteText));
832                 }
833             }
834
835             newCategories.add(category);
836             newAgendaPoints.add(newSubAgendaPoints);
837             newMinuteTexts.add(newSubMinuteTexts);
838         }
839
840         meeting.setCategories(newCategories);
841         meeting.setAgendaPoints(newAgendaPoints);
842         meeting.setMinuteTexts(newMinuteTexts);
843          */

844     }
845
846     /**
847      * <p>Helper method. Strip empty pages from the item.</p>
848      *
849      * @param item item to remove empty pages from.
850      * @param request valid request.
851      */

852     private void stripEmptyPages(final LibraryItemDO item,
853             final HttpServletRequest JavaDoc request) {
854         List JavaDoc newPages = new Vector JavaDoc();
855
856         if (item.getPages() != null) {
857             for (Iterator JavaDoc i = item.getPages().iterator(); i.hasNext();) {
858                 PageDO page = (PageDO) i.next();
859                 String JavaDoc pageText = page.getText();
860
861                 if (pageText.trim().length() > 0) {
862                     newPages.add(page);
863                 }
864             }
865         }
866         item.setPages(newPages);
867
868     }
869 }
870
Popular Tags