001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers.forum;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.forum.ForumConstants;
038: import org.libresource.forum.ejb.model.MessageResourceValue;
039: import org.libresource.forum.ejb.model.ThreadResourceValue;
040: import org.libresource.forum.interfaces.LibresourceForumService;
041:
042: import org.libresource.kernel.KernelConstants;
043: import org.libresource.kernel.LibresourceSecurityException;
044: import org.libresource.kernel.interfaces.KernelService;
045:
046: import org.libresource.web.Controller;
047:
048: import java.net.URI;
049:
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052:
053: public class PostInThreadController implements Controller {
054: public Object process(URI uri, HttpServletRequest request,
055: HttpServletResponse response) throws Exception {
056: if (request.getParameter("cancel") != null) {
057: return uri;
058: }
059:
060: if (request.getParameter("title") == null) {
061: KernelService kernelService = (KernelService) Libresource
062: .getService(KernelConstants.SERVICE);
063:
064: if (!kernelService.checkSecurity(uri,
065: ForumConstants.SECURITY_POST)) {
066: throw new LibresourceSecurityException(uri,
067: ForumConstants.SECURITY_POST);
068: }
069:
070: LibresourceForumService libresourceForumService = (LibresourceForumService) Libresource
071: .getService(ForumConstants.SERVICE);
072: ThreadResourceValue threadResourceValue = libresourceForumService
073: .getThread(uri);
074: request.setAttribute("title", "RE : "
075: + threadResourceValue.getName());
076:
077: if (request.getParameter("quote") != null) {
078: request.setAttribute("body", "{quoteMessage:"
079: + request.getParameter("quote") + "}\n\n");
080: }
081:
082: // Ajout des messages en pour la jsp afin de l'afficher en fin de page
083: MessageResourceValue[] messages = libresourceForumService
084: .listMessagesInThread(uri);
085:
086: for (int i = 0; i < messages.length; i++) {
087: if (messages[i].getTitle().length() == 0) {
088: messages[i].setTitle("No title");
089: }
090: }
091:
092: request.setAttribute("messages", messages);
093:
094: return "/pages/modules/forum/postInThread.jsp";
095: }
096:
097: LibresourceForumService libresourceForumService = (LibresourceForumService) Libresource
098: .getService(ForumConstants.SERVICE);
099: libresourceForumService.replyToThread(uri, request
100: .getParameter("title"), request.getParameter("body"));
101:
102: return uri;
103: }
104: }
|