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.files.ejb.model.FileResourceValue;
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 java.util.Arrays;
055: import java.util.Comparator;
056:
057: import javax.servlet.http.HttpServletRequest;
058: import javax.servlet.http.HttpServletResponse;
059:
060: public class RssFilesInIssueController implements Controller {
061: public Object process(URI uri, HttpServletRequest request,
062: HttpServletResponse response) throws Exception {
063: LibresourceBugTrackerService libresourceBugTrackerService = (LibresourceBugTrackerService) Libresource
064: .getService(BugTrackerConstants.SERVICE);
065: IssueResourceValue issue = libresourceBugTrackerService
066: .getIssue(uri);
067: FileResourceValue[] files = (FileResourceValue[]) libresourceBugTrackerService
068: .listFilesInIssue(uri);
069:
070: Comparator compFile = new Comparator() {
071: public int compare(Object f1, Object f2) {
072: if (!(f1 instanceof FileResourceValue)) {
073: throw new ClassCastException();
074: }
075:
076: return (((FileResourceValue) f1).getName())
077: .compareTo(((FileResourceValue) f2).getName());
078: }
079: };
080:
081: Arrays.sort(files, compFile);
082:
083: // max items in feed
084: int max;
085:
086: try {
087: max = Integer.parseInt(request.getParameter("max"));
088: } catch (Exception e) {
089: max = 10;
090: }
091:
092: // create feed
093: Feed feed = new Feed(issue.getUri(), issue.getSummary(), issue
094: .getBody());
095:
096: // create items
097: Item[] items;
098:
099: if (files.length < 10) {
100: items = new Item[files.length];
101: } else {
102: items = new Item[max];
103: }
104:
105: for (int i = 0; i < items.length; i++) {
106: RenderContext renderContext = new LibresourceRenderContext(
107: files[i].getUri());
108: String content = new BaseRenderEngine().render(files[i]
109: .getDescription(), renderContext);
110: items[i] = new Item(files[i].getUri(), files[i]
111: .getDisplayName(), null, files[i].getDate(),
112: content);
113: }
114:
115: // redirect to generic feed page
116: request.setAttribute("feed", feed);
117: request.setAttribute("items", items);
118:
119: return "/pages/resource.rdf.jsp";
120: }
121: }
|