001: /*
002: * Copyright (c) 2001 - 2005 ivata limited.
003: * All rights reserved.
004: * -----------------------------------------------------------------------------
005: * ivata groupware may be redistributed under the GNU General Public
006: * License as published by the Free Software Foundation;
007: * version 2 of the License.
008: *
009: * These programs are free software; you can redistribute them and/or
010: * modify them under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; version 2 of the License.
012: *
013: * These programs are distributed in the hope that they will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: *
017: * See the GNU General Public License in the file LICENSE.txt for more
018: * details.
019: *
020: * If you would like a copy of the GNU General Public License write to
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place - Suite 330
024: * Boston, MA 02111-1307, USA.
025: *
026: *
027: * To arrange commercial support and licensing, contact ivata at
028: * http://www.ivata.com/contact.jsp
029: * -----------------------------------------------------------------------------
030: * $Log: SubmitAction.java,v $
031: * Revision 1.6 2005/04/30 13:04:14 colinmacleod
032: * Fixes reverting id type from String to Integer.
033: *
034: * Revision 1.5 2005/04/29 02:48:16 colinmacleod
035: * Data bugfixes.
036: * Changed primary key back to Integer.
037: *
038: * Revision 1.4 2005/04/26 15:07:07 colinmacleod
039: * Consolidated print JSP into display pages (eliminating need for separate print pages).
040: * Renamed Faq to FAQ.
041: *
042: * Revision 1.3 2005/04/10 20:31:58 colinmacleod
043: * Added new themes.
044: * Changed id type to String.
045: * Changed i tag to em and b tag to strong.
046: * Improved PicoContainerFactory with NanoContainer scripts.
047: *
048: * Revision 1.2 2005/04/09 17:19:46 colinmacleod
049: * Changed copyright text to GPL v2 explicitly.
050: *
051: * Revision 1.1.1.1 2005/03/10 17:52:04 colinmacleod
052: * Restructured ivata op around Hibernate/PicoContainer.
053: * Renamed ivata groupware.
054: *
055: * Revision 1.12 2004/12/31 18:27:44 colinmacleod
056: * Added MaskFactory to constructor of MaskAction.
057: *
058: * Revision 1.11 2004/12/23 21:01:29 colinmacleod
059: * Updated Struts to v1.2.4.
060: * Changed base classes to use ivata masks.
061: *
062: * Revision 1.10 2004/11/12 18:19:15 colinmacleod
063: * Change action and form classes to extend MaskAction, MaskForm respectively.
064: *
065: * Revision 1.9 2004/11/12 15:57:16 colinmacleod
066: * Removed dependencies on SSLEXT.
067: * Moved Persistence classes to ivata masks.
068: *
069: * Revision 1.8 2004/11/03 15:31:51 colinmacleod
070: * Change method interfaces to remove log.
071: *
072: * Revision 1.7 2004/08/01 11:45:19 colinmacleod
073: * Restructured search engine into separate subproject.
074: *
075: * Revision 1.6 2004/07/19 22:00:46 colinmacleod
076: * Fixed pages for note.
077: *
078: * Revision 1.5 2004/07/13 19:47:29 colinmacleod
079: * Moved project to POJOs from EJBs.
080: * Applied PicoContainer to services layer (replacing session EJBs).
081: * Applied Hibernate to persistence layer (replacing entity EJBs).
082: *
083: * Revision 1.4 2004/03/21 21:16:29 colinmacleod
084: * Shortened name to ivata op.
085: *
086: * Revision 1.3 2004/03/21 20:30:34 colinmacleod
087: * Changed session variable called mailSession to securityServerSession.
088: *
089: * Revision 1.2 2004/02/01 22:07:31 colinmacleod
090: * Added full names to author tags
091: *
092: * Revision 1.1.1.1 2004/01/27 20:58:42 colinmacleod
093: * Moved ivata openportal to SourceForge..
094: *
095: * Revision 1.4 2004/01/12 14:01:03 jano
096: * fixing bugs
097: *
098: * Revision 1.3 2003/10/28 13:16:14 jano
099: * 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;
169: import java.util.Iterator;
170: import java.util.List;
171: import java.util.Map;
172: import java.util.Set;
173: import java.util.Vector;
174:
175: import javax.servlet.http.HttpServletRequest;
176: import javax.servlet.http.HttpServletResponse;
177: import javax.servlet.http.HttpSession;
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: * <p><code>Action</code> invoked whenever a library item is
206: * entered new, or changed.</p>
207: *
208: * @since 2003-02-22
209: * @author Colin MacLeod
210: * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
211: * @version $Revision: 1.6 $
212: */
213: public class SubmitAction extends DisplayAction {
214: private Library library;
215: private LibraryRights libraryRights;
216:
217: /**
218: * TODO
219: * @param library
220: * @param libraryRights
221: * @param settings
222: * @param maskFactory This factory is needed to access the masks and groups
223: * of masks.
224: * @param authenticator used to confirm whether or not the
225: * user should be allowed to continue, in the <code>execute</code> method.
226: */
227: public SubmitAction(Library library, LibraryRights libraryRights,
228: Settings settings, MaskFactory maskFactory,
229: MaskAuthenticator authenticator) {
230: super (library, settings, maskFactory, authenticator);
231: this .library = library;
232: this .libraryRights = libraryRights;
233: }
234:
235: /**
236: * <p>Called when the clear button is pressed, or after an ok or
237: * delete button, where the session should be restored to its default
238: * state.</p>
239: *
240: * @param mapping The ActionMapping used to select this instance.
241: * @param log valid logging object to write messages to.
242: * @param errors valid errors object to append errors to. If there are
243: * any errors, the action will return to the input.
244: * @param form optional ActionForm bean for this request (if any)
245: * @param request non-HTTP request we are processing
246: * @param response The non-HTTP response we are creating
247: * @param session returned from the <code>request</code> parameter.
248: * @param userName valid, non-null user name from session.
249: * @param settings valid, non-null settings from session.
250: * @exception SystemException if there is any problem which
251: * prevents processing. It will result in the webapp being forwarded
252: * to
253: * the standard error page.
254: */
255: public void clear(final ActionMapping mapping,
256: final ActionErrors errors, final ActionForm form,
257: final HttpServletRequest request,
258: final HttpServletResponse response,
259: final HttpSession session) throws SystemException {
260: // so we don't lose the type when clear is pressed
261: request.setAttribute("type", ((ItemForm) form).getItem()
262: .getType());
263: ItemForm itemForm = (ItemForm) form;
264: itemForm.clear();
265: }
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 execute(final ActionMapping mapping,
291: final ActionErrors errors, final ActionForm form,
292: final HttpServletRequest request,
293: final HttpServletResponse response,
294: final HttpSession session) throws SystemException {
295: ItemForm itemForm = (ItemForm) form;
296: LibraryItemDO item = itemForm.getItem();
297:
298: // if there is no item yet, or we are told to make a new one, make a new
299: // empty one
300: Integer requestType = StringHandling.integerValue(request
301: .getParameter("type"));
302:
303: if (requestType == null) {
304: requestType = (Integer) request.getAttribute("type");
305: }
306:
307: if ((requestType != null) || (item == null)) {
308: itemForm.reset(mapping, request);
309: itemForm.setPreview(null);
310: itemForm.setSubmitIncludePage(null);
311: itemForm.setItem(item = new LibraryItemDO());
312: }
313:
314: SecuritySession securitySession = (SecuritySession) session
315: .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,
321: item.getTopic().getId()) || user.equals(item
322: .getCreatedBy()))) {
323: errors.add(Globals.ERROR_KEY, new ActionMessage(
324: "errors.library.item.amend.rights"));
325:
326: return "libraryIndex";
327: }
328:
329: // default the item type to plain old document
330: if (item.getType() == null) {
331: if (requestType != null) {
332: item.setType(requestType);
333: } else {
334: item.setType(LibraryItemConstants.ITEM_DOCUMENT);
335: }
336: }
337:
338: // if the item doesn't contain a meetingDO and it is meeting Item,
339: // then try to find the DO from a request parameter
340: Integer meetingId = StringHandling.integerValue(request
341: .getParameter("meetingId"));
342:
343: // only note is different
344: itemForm.setSummaryPromptKey("");
345:
346: if ((meetingId != null)
347: || item.getType().equals(
348: LibraryItemConstants.ITEM_MEETING)) {
349:
350: /*
351: * TODO: fix this via subclassing/events
352: MeetingDO meeting;
353:
354:
355: if (meetingId != null) {
356: CalendarRemote calendar;
357:
358: if ((calendar = (CalendarRemote) session.getAttribute(
359: "calendar")) == null) {
360: try {
361: CalendarRemoteHome home = (CalendarRemoteHome) ApplicationServer.findRemoteHome("CalendarRemote",
362: CalendarRemoteHome.class);
363:
364: calendar = home.create();
365: session.setAttribute("calendar", calendar);
366: } catch (SystemException e) {
367: throw new SystemException(e);
368: } catch (NamingException e) {
369: throw new SystemException(e);
370: } catch (CreateException e) {
371: throw new SystemException(e);
372: }
373: }
374:
375: try {
376: meeting = calendar.findMeetingByPrimaryKey(meetingId);
377: } catch (SystemException e) {
378: throw new SystemException(e);
379: }
380:
381: itemForm.setItem(item = new LibraryItemDO());
382: item.setType(LibraryItemConstants.ITEM_MEETING);
383: item.setMeeting(meeting);
384: item.setSummary(meeting.getEvent().getDescription());
385: item.setTitle(meeting.getEvent().getSubject());
386: } else {
387: meeting = item.getMeeting();
388: }
389:
390: if (meeting == null) {
391: item.setMeeting(meeting = new MeetingDO());
392: }
393:
394: // strip out categories which are empty
395: stripEmptyMeetingCategories(item, request);
396:
397: // if the new arrays are empty, or the add button was pressed
398: // add a new category
399: if ((meeting.getCategories().size() == 0) ||
400: !StringHandling.isNullOrEmpty(itemForm.getNewPage())) {
401: MessageResources calendarMessages = getResources(request,
402: "calendar");
403:
404: meeting.addCategory(calendarMessages.getMessage(
405: (Locale) session.getAttribute(Globals.LOCALE_KEY),
406: "default.category",
407: String.valueOf(meeting.getCategories().size() + 1)),
408: new Vector(), new Vector());
409: }
410: */
411:
412: // see if we should add new agenda points to any of the categories
413: // parameter Integer(0) is a TRICK
414: String newHeading = itemForm.getNewPoint(0);
415: int index = 0;
416:
417: /* TODO: fix this via subclassing/events
418: for (Iterator i = meeting.getCategories().iterator(); i.hasNext();
419: ++index) {
420: i.next();
421:
422: // if we have more categories as AgendaPoints, Minutes -> create new Vector
423: while (meeting.getAgendaPoints().size() <= index) {
424: meeting.getAgendaPoints().add(new Vector());
425: }
426:
427: while (meeting.getMinuteTexts().size() <= index) {
428: meeting.getMinuteTexts().add(new Vector());
429: }
430:
431: // if you pressed the button...
432: if (((newHeading != null) &&
433: (index == (Integer.valueOf(newHeading)).intValue())) ||
434: (((Vector) meeting.getAgendaPoints().get(index)).size() == 0)) {
435: ((Vector) meeting.getAgendaPoints().get(index)).add("");
436: ((Vector) meeting.getMinuteTexts().get(index)).add("");
437: }
438: }
439: */
440: // meetings have their own include
441: itemForm.setSubmitIncludePage("/library/submitMeeting.jsp");
442: itemForm
443: .setSummaryTitleKey("submit.title.itemDetails.meeting");
444: itemForm.setHelpKey("library.submit.meeting");
445:
446: // TODO:
447: throw new RuntimeException(
448: "ERROR: illegal dependency on calendar from library");
449:
450: // frequently asked question stuff here
451: } else if (item.getType().equals(LibraryItemConstants.ITEM_FAQ)) {
452: // strip out pages which are empty
453: stripEmptyFaqCategories(item, request);
454:
455: // if the new arrays are empty, or the add button was pressed
456: // add a new category
457: if ((item.getFAQCategories().size() == 0)
458: || !StringHandling.isNullOrEmpty(itemForm
459: .getNewPage())) {
460: FAQCategoryDO faqCategory = new FAQCategoryDO();
461: faqCategory.setFAQs(new Vector());
462: item.getFAQCategories().add(faqCategory);
463: }
464:
465: // see if we should add questions to any of the categories
466: // parameter Integer(0) is a TRICK
467: String newHeading = itemForm.getNewPoint(0);
468: int index = 0;
469:
470: for (Iterator i = item.getFAQCategories().iterator(); i
471: .hasNext(); ++index) {
472: FAQCategoryDO faqCategory = (FAQCategoryDO) i.next();
473:
474: // if you pressed the button...
475: if (((newHeading != null) && (index == (Integer
476: .valueOf(newHeading)).intValue()))
477: || (faqCategory.getFAQs().size() == 0)) {
478: faqCategory.getFAQs().add(new FAQDO());
479: }
480: }
481:
482: // faqs have their own include
483: itemForm.setSubmitIncludePage("/library/submitFAQ.jsp");
484: itemForm.setSummaryTitleKey("submit.title.itemDetails.faq");
485: itemForm.setHelpKey("library.submit.faq");
486:
487: // Normal document stuff here
488: } else {
489: // strip out pages which are empty
490: stripEmptyPages(item, request);
491:
492: // notes don't have an include page - only documents
493: if (item.getType().equals(LibraryItemConstants.ITEM_NOTE)) {
494: itemForm
495: .setSummaryTitleKey("submit.title.itemDetails.note");
496: itemForm.setSummaryPromptKey("note");
497: itemForm.setHelpKey("library.submit.note");
498: } else {
499: itemForm
500: .setSubmitIncludePage("/library/submitDocument.jsp");
501: itemForm
502: .setSummaryTitleKey("submit.title.itemDetails.document");
503: itemForm.setHelpKey("library.submit.document");
504:
505: // make sure there is at least one page - unless this is a note
506: if ((item.getPages().size() == 0)
507: || !StringHandling.isNullOrEmpty(itemForm
508: .getNewPage())) {
509: item.getPages().add(new PageDO());
510: }
511: }
512: }
513:
514: // set up display information based on the item type
515: chooseItemType(itemForm);
516:
517: // set the display page for the preview
518: setPageNumber("/library/submit.action", request, response,
519: itemForm);
520:
521: /*TODO try {
522: // setUp uploadingFileList and attachedFileList
523: itemForm.setUploadingFileList((java.util.Vector) drive.getUploads(
524: "drive", userName));
525:
526: if (item.getId() == null) {
527: itemForm.setFileList(new Vector());
528: } else {
529: itemForm.setFileList((java.util.Vector) drive.findFilesByPath(
530: "/library/" + item.getId().toString(), userName));
531: }
532:
533: // is user selected any file to remove and he did click on deleteFile button
534: if (!StringHandling.isNullOrEmpty(itemForm.getDeleteFileButton())) {
535: //remove uploads
536: if (itemForm.getSelectedNewFilesIds().length > 0) {
537: itemForm.setUploadingFileList(new Vector(
538: drive.removeUploads(Arrays.asList(
539: itemForm.getSelectedNewFilesIds()),
540: "drive", userName)));
541: }
542:
543: //remove attached files
544: for (Iterator i = itemForm.getFileList().iterator();
545: i.hasNext();) {
546: DriveFileDO tmpFile = (DriveFileDO) i.next();
547:
548: if (itemForm.getSelectedAttachedFilesIds(
549: tmpFile.getId().toString()) != null) {
550: drive.removeFile(tmpFile.getId(), userName);
551: }
552: }
553:
554: itemForm.setDeleteFileButton("");
555: }
556:
557: // change the drive files only when it's an existing item
558: if (item.getId() != null) {
559: // add files to repository
560: java.util.Vector uploadedFileNames = new java.util.Vector();
561:
562: try {
563: DirectoryDO attachmentDirectoryDO = drive.findDirectoryByParentIdName(DirectoryConstants.LIBRARY_DIRECTORY,
564: item.getId().toString(), userName);
565:
566: for (Iterator i = itemForm.getUploadingFileList().iterator();
567: i.hasNext();) {
568: FileDO fileDO = (FileDO) i.next();
569:
570: // carefull, maybe we did remove this new file
571: if ((Arrays.asList(itemForm.getSelectedNewFilesIds())).contains(
572: fileDO.getFileName())) {
573: continue;
574: }
575:
576: DriveFileDO driveFileDO = new DriveFileDO();
577:
578: driveFileDO.setFileName(fileDO.getFileName());
579: driveFileDO.setDirectoryId(attachmentDirectoryDO.getId());
580: driveFileDO.setHeadRevision(new FileRevisionDO());
581: driveFileDO.getHeadRevision().setComment(fileDO.getComment());
582: driveFileDO.setCreatedBy(userName);
583: driveFileDO.setMimeType(fileDO.getMimeType());
584: driveFileDO.setSize(fileDO.getSize());
585: uploadedFileNames.add(fileDO.getFileName());
586:
587: drive.commitFile(driveFileDO, userName, null);
588: }
589: } catch (SystemException e) {
590: throw new SystemException(e);
591: }
592:
593: // we add files to CVS -> to item, so ...
594: // remove uploaded files
595: try {
596: itemForm.setUploadingFileList(new Vector(
597: drive.removeUploads(uploadedFileNames, "drive",
598: userName)));
599: } catch (SystemException e) {
600: throw new SystemException(e);
601: }
602:
603: // no wonder that we request back the current attachment list....
604: itemForm.setFileList((java.util.Vector) drive.findFilesByPath(
605: "/library/" + item.getId().toString(), userName));
606: }
607: } catch (SystemException e) {
608: throw new SystemException(e);
609: }
610: */
611: // get all the topics we can enter items in
612: List topics = library.findTopics(securitySession);
613: Iterator topicIterator = topics.iterator();
614: Map topicCaptions = new HashMap();
615: Map topicImages = new HashMap();
616: while (topicIterator.hasNext()) {
617: TopicDO topic = (TopicDO) topicIterator.next();
618: Integer id = topic.getId();
619: topicCaptions.put(id, topic.getCaption());
620: topicImages.put(id, topic.getImage());
621: }
622:
623: itemForm.setTopicCaptions(topicCaptions);
624: Set topicIds = topicCaptions.keySet();
625: itemForm.setTopicIds(topicIds);
626: itemForm.setTopicImages(topicImages);
627:
628: // if there are no topics for you, return to the index
629: if (topicIds.size() == 0) {
630: errors.add(Globals.ERROR_KEY, new ActionMessage(
631: "errors.library.item.submit.noTopicRights"));
632:
633: return "libraryIndex";
634: }
635:
636: return null;
637: }
638:
639: /**
640: * <p>This method is called if the ok or apply buttons are
641: * pressed.</p>
642: *
643: * @param mapping current action mapping from <em>Struts</em> config.
644: * @param log valid logging object to write messages to.
645: * @param errors valid errors object to append errors to. If there are
646: * any errors, the action will return to the input.
647: * @param form optional ActionForm bean for this request (if any)
648: * @param request non-HTTP request we are processing
649: * @param response The non-HTTP response we are creating
650: * @param session returned from the <code>request</code> parameter.
651: * @param userName valid, non-null user name from session.
652: * @param settings valid, non-null settings from session.
653: * @param defaultForward Refer to
654: * {@link com.ivata.mask.web.struts.MaskAction#onConfirm}.
655: * @exception SystemException if there is any problem which
656: * prevents processing. It will result in the webapp being forwarded
657: * to
658: * the standard error page.
659: * @return this method returns the string used to identify the correct
660: * <em>Struts</em> <code>ActionForward</code> which should follow this
661: * page, or <code>null</code> if it should return to the input.
662: *
663: */
664: public String onConfirm(final ActionMapping mapping,
665: final ActionErrors errors, final ActionForm form,
666: final HttpServletRequest request,
667: final HttpServletResponse response,
668: final HttpSession session, final String defaultForward)
669: throws SystemException {
670: ItemForm itemForm = (ItemForm) form;
671: LibraryItemDO item = itemForm.getItem();
672: SecuritySession securitySession = (SecuritySession) session
673: .getAttribute("securitySession");
674:
675: if (item.getType().equals(LibraryItemConstants.ITEM_MEETING)) {
676: stripEmptyMeetingCategories(item, request);
677: } else if (item.getType().equals(LibraryItemConstants.ITEM_FAQ)) {
678: stripEmptyFaqCategories(item, request);
679: } else {
680: stripEmptyPages(item, request);
681: }
682:
683: // insert a new item
684: try {
685: if (item.getId() == null) {
686: item = library.addItem(securitySession, item, itemForm
687: .getComment());
688:
689: // update an existing item
690: } else {
691: library.amendItem(securitySession, item, itemForm
692: .getComment());
693: }
694: } catch (NotificationException e) {
695: // handle any mail exceptions separately
696: Throwable cause = ThrowableHandling.getCause(e);
697: // this will get picked up by the library notice board page
698: session.setAttribute("libraryNotificationException", e);
699: }
700: /*TODO
701: // now maintain files
702: // add files to repository
703: java.util.Vector uploadedFileNames = new java.util.Vector();
704:
705: try {
706: DirectoryDO attachmentDirectoryDO = drive.findDirectoryByParentIdName(DirectoryConstants.LIBRARY_DIRECTORY,
707: item.getId().toString(), userName);
708:
709: for (Iterator i = itemForm.getUploadingFileList().iterator();
710: i.hasNext();) {
711: FileDO fileDO = (FileDO) i.next();
712: DriveFileDO driveFileDO = new DriveFileDO();
713:
714: driveFileDO.setFileName(fileDO.getFileName());
715: driveFileDO.setDirectoryId(attachmentDirectoryDO.getId());
716: driveFileDO.setHeadRevision(new FileRevisionDO());
717: driveFileDO.getHeadRevision().setComment(fileDO.getComment());
718: driveFileDO.setCreatedBy(userName);
719: driveFileDO.setMimeType(fileDO.getMimeType());
720: driveFileDO.setSize(fileDO.getSize());
721: uploadedFileNames.add(fileDO.getFileName());
722:
723: drive.commitFile(driveFileDO, userName, null);
724: }
725:
726: // remove uploaded files
727: drive.removeUploads(uploadedFileNames, "drive", userName);
728: } catch (SystemException e) {
729: throw new SystemException(e);
730: }
731: */
732: return defaultForward;
733: }
734:
735: /**
736: * <p>Helper method. Strip empty FAQ categories from the item.</p>
737: *
738: * @param item item to remove empty pages from.
739: * @param request valid request.
740: */
741: private void stripEmptyFaqCategories(final LibraryItemDO item,
742: final HttpServletRequest request) {
743: List newFaqCategories = new Vector();
744:
745: if (item.getFAQCategories() != null) {
746: for (Iterator i = item.getFAQCategories().iterator(); i
747: .hasNext();) {
748: FAQCategoryDO faqCategory = (FAQCategoryDO) i.next();
749: List newFaqs = new Vector();
750: Iterator faqIterator = faqCategory.getFAQs().iterator();
751:
752: while (faqIterator.hasNext()) {
753: FAQDO faq = (FAQDO) faqIterator.next();
754: String question = (String) faq.getQuestion();
755: String answer = (String) faq.getAnswer();
756:
757: if (!StringHandling.isNullOrEmpty(question)
758: || !StringHandling.isNullOrEmpty(answer)) {
759: newFaqs.add(faq);
760: }
761: }
762:
763: if ((newFaqs.size() != 0)
764: || !StringHandling.isNullOrEmpty(faqCategory
765: .getName())) {
766: faqCategory.setFAQs(newFaqs);
767: newFaqCategories.add(faqCategory);
768: }
769: }
770: }
771:
772: item.setFAQCategories(newFaqCategories);
773: }
774:
775: /**
776: * <p>Helper method. Strip empty meeting categories from the item.</p>
777: *
778: * @param item item to remove empty pages from.
779: * @param request valid request.
780: */
781: private void stripEmptyMeetingCategories(final LibraryItemDO item,
782: final HttpServletRequest request) {
783: Vector newCategories = new Vector();
784: Vector newAgendaPoints = new Vector();
785: Vector newMinuteTexts = new Vector();
786: MessageResources calendarMessages = this .getResources(request,
787: "calendar");
788: int count = 0;
789:
790: /*
791: * TODO: fix this via subclassing/fire events
792: MeetingDO meeting = item.getMeeting();
793: for (int i = 0;
794: (meeting.getCategories() != null) &&
795: (i < meeting.getCategories().size()); ++i) {
796: String defaultName = calendarMessages.getMessage((Locale) request.getSession()
797: .getAttribute(Globals.LOCALE_KEY),
798: "default.category", new Integer(++count));
799: String category = meeting.getCategory(i);
800: Vector agendaPoints = (Vector) meeting.getAgendaPoints().get(i);
801: Vector minuteTexts = (Vector) meeting.getMinuteTexts().get(i);
802:
803: if (StringHandling.isNullOrEmpty(category)) {
804: // see if there are points or minutes
805: // go throw all points because if there is not text in input boxes -> there is a empty String in Vector :-(((
806: // checking !!!! ONLY !!!! agenda points
807: boolean empty = true;
808:
809: for (Iterator api = agendaPoints.iterator(); api.hasNext();) {
810: if (!StringHandling.isNullOrEmpty((String) api.next())) {
811: empty = false;
812:
813: break;
814: }
815: }
816:
817: if (!empty) {
818: // default the text to heading + number
819: category = defaultName;
820: } else {
821: --count;
822:
823: continue;
824: }
825: }
826:
827: // only add if it is not-empty or was set above
828: Vector newSubAgendaPoints = new Vector();
829: Vector newSubMinuteTexts = new Vector();
830: Iterator minuteTextsIterator = minuteTexts.iterator();
831:
832: for (Iterator agendaPointsIterator = agendaPoints.iterator();
833: agendaPointsIterator.hasNext();) {
834: String agendaPoint = (String) agendaPointsIterator.next();
835: String minuteText = (String) minuteTextsIterator.next();
836:
837: if (!StringHandling.isNullOrEmpty(agendaPoint) ||
838: !StringHandling.isNullOrEmpty(minuteText)) {
839: newSubAgendaPoints.add(StringHandling.getNotNull(
840: agendaPoint));
841: newSubMinuteTexts.add(StringHandling.getNotNull(minuteText));
842: }
843: }
844:
845: newCategories.add(category);
846: newAgendaPoints.add(newSubAgendaPoints);
847: newMinuteTexts.add(newSubMinuteTexts);
848: }
849:
850: meeting.setCategories(newCategories);
851: meeting.setAgendaPoints(newAgendaPoints);
852: meeting.setMinuteTexts(newMinuteTexts);
853: */
854: }
855:
856: /**
857: * <p>Helper method. Strip empty pages from the item.</p>
858: *
859: * @param item item to remove empty pages from.
860: * @param request valid request.
861: */
862: private void stripEmptyPages(final LibraryItemDO item,
863: final HttpServletRequest request) {
864: List newPages = new Vector();
865:
866: if (item.getPages() != null) {
867: for (Iterator i = item.getPages().iterator(); i.hasNext();) {
868: PageDO page = (PageDO) i.next();
869: String pageText = page.getText();
870:
871: if (pageText.trim().length() > 0) {
872: newPages.add(page);
873: }
874: }
875: }
876: item.setPages(newPages);
877:
878: }
879: }
|