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.bugtracker;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.bugtracker.BugTrackerConstants;
038: import org.libresource.bugtracker.ejb.model.IssueResourceValue;
039: import org.libresource.bugtracker.interfaces.LibresourceBugTrackerService;
040:
041: import org.libresource.forum.ejb.model.MessageResourceValue;
042:
043: import org.libresource.web.Controller;
044: import org.libresource.web.rss.Feed;
045: import org.libresource.web.rss.Item;
046: import org.libresource.web.wiki.LibresourceRenderContext;
047:
048: import org.radeox.api.engine.context.RenderContext;
049:
050: import org.radeox.engine.BaseRenderEngine;
051:
052: import java.net.URI;
053:
054: import javax.servlet.http.HttpServletRequest;
055: import javax.servlet.http.HttpServletResponse;
056:
057: public class RssCommentsInIssueController implements Controller {
058: public Object process(URI uri, HttpServletRequest request,
059: HttpServletResponse response) throws Exception {
060: LibresourceBugTrackerService libresourceBugTrackerService = (LibresourceBugTrackerService) Libresource
061: .getService(BugTrackerConstants.SERVICE);
062: IssueResourceValue issue = libresourceBugTrackerService
063: .getIssue(uri);
064: MessageResourceValue[] comments = (MessageResourceValue[]) libresourceBugTrackerService
065: .listCommentsInIssue(uri);
066:
067: // max items in feed
068: int max;
069:
070: try {
071: max = Integer.parseInt(request.getParameter("max"));
072: } catch (Exception e) {
073: max = 10;
074: }
075:
076: // create feed
077: Feed feed = new Feed(issue.getUri(), issue.getSummary(), issue
078: .getBody());
079:
080: // create items
081: Item[] items;
082:
083: if (comments.length < 10) {
084: items = new Item[comments.length];
085: } else {
086: items = new Item[max];
087: }
088:
089: for (int i = 0; i < items.length; i++) {
090: RenderContext renderContext = new LibresourceRenderContext(
091: comments[i].getUri());
092: String content = new BaseRenderEngine().render(comments[i]
093: .getBody(), renderContext);
094: items[i] = new Item(comments[i].getUri(), comments[i]
095: .getTitle(), comments[i].getAuthorName(),
096: comments[i].getDate(), content);
097: }
098:
099: // redirect to generic feed page
100: request.setAttribute("feed", feed);
101: request.setAttribute("items", items);
102:
103: return "/pages/resource.rdf.jsp";
104: }
105: }
|