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.web.Controller;
043: import org.libresource.web.rss.Feed;
044: import org.libresource.web.rss.Item;
045: import org.libresource.web.wiki.LibresourceRenderContext;
046:
047: import org.radeox.api.engine.context.RenderContext;
048:
049: import org.radeox.engine.BaseRenderEngine;
050:
051: import java.net.URI;
052:
053: import javax.servlet.http.HttpServletRequest;
054: import javax.servlet.http.HttpServletResponse;
055:
056: public class RssThreadController implements Controller {
057: public Object process(URI uri, HttpServletRequest request,
058: HttpServletResponse response) throws Exception {
059: LibresourceForumService libresourceForumService = (LibresourceForumService) Libresource
060: .getService(ForumConstants.SERVICE);
061: ThreadResourceValue thread = libresourceForumService
062: .getThread(uri);
063: MessageResourceValue[] messages = libresourceForumService
064: .listMessagesInThread(uri);
065:
066: for (int i = 0; i < messages.length; i++) {
067: if (messages[i].getTitle().length() == 0) {
068: messages[i].setTitle("No title");
069: }
070: }
071:
072: // create feed
073: Feed feed = new Feed(thread.getUri(), thread.getName(), thread
074: .getName());
075:
076: // create items
077: Item[] items;
078:
079: if (messages.length < 10) {
080: items = new Item[messages.length];
081: } else {
082: items = new Item[10];
083: }
084:
085: for (int i = 0; i < items.length; i++) {
086: RenderContext renderContext = new LibresourceRenderContext(
087: messages[i].getUri());
088: String content = new BaseRenderEngine().render(messages[i]
089: .getBody(), renderContext);
090: items[i] = new Item(messages[i].getUri(), messages[i]
091: .getTitle(), messages[i].getAuthorName(),
092: messages[i].getDate(), content);
093: }
094:
095: // redirect to generic feed page
096: request.setAttribute("feed", feed);
097: request.setAttribute("items", items);
098:
099: return "/pages/resource.rdf.jsp";
100: }
101: }
|