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.files;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.files.FileConstants;
038: import org.libresource.files.ejb.model.FileResourceValue;
039: import org.libresource.files.ejb.model.RepositoryResourceValue;
040: import org.libresource.files.interfaces.LibresourceFilesService;
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 RssRepositoryController implements Controller {
057: public Object process(URI uri, HttpServletRequest request,
058: HttpServletResponse response) throws Exception {
059: LibresourceFilesService libresourceFilesService = (LibresourceFilesService) Libresource
060: .getService(FileConstants.SERVICE);
061: RepositoryResourceValue repository = libresourceFilesService
062: .getRepository(uri);
063: FileResourceValue[] files = libresourceFilesService
064: .listFilesInRepository(uri);
065:
066: // max items in feed
067: int max;
068:
069: try {
070: max = Integer.parseInt(request.getParameter("max"));
071: } catch (Exception e) {
072: max = 10;
073: }
074:
075: // create feed
076: Feed feed = new Feed(repository.getUri(), repository.getName(),
077: repository.getDescription());
078:
079: // create items
080: Item[] items;
081:
082: if (files.length < 10) {
083: items = new Item[files.length];
084: } else {
085: items = new Item[max];
086: }
087:
088: for (int i = 0; i < items.length; i++) {
089: RenderContext renderContext = new LibresourceRenderContext(
090: files[i].getUri());
091: String content = new BaseRenderEngine().render(files[i]
092: .getDescription(), renderContext);
093: items[i] = new Item(files[i].getUri(), files[i]
094: .getDisplayName(), null, files[i].getDate(),
095: content);
096: }
097:
098: // redirect to generic feed page
099: request.setAttribute("feed", feed);
100: request.setAttribute("items", items);
101:
102: return "/pages/resource.rdf.jsp";
103: }
104: }
|