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.interfaces.LibresourceFilesService;
040:
041: import org.libresource.kernel.KernelConstants;
042: import org.libresource.kernel.LibresourceSecurityException;
043: import org.libresource.kernel.interfaces.KernelService;
044:
045: import org.libresource.web.Controller;
046:
047: import java.net.URI;
048:
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051:
052: public class EditFileInfoController implements Controller {
053: public Object process(URI uri, HttpServletRequest request,
054: HttpServletResponse response) throws Exception {
055: if (request.getParameter("cancel") != null) {
056: return uri;
057: }
058:
059: if (request.getParameter("displayName") == null) {
060: KernelService kernelService = (KernelService) Libresource
061: .getService(KernelConstants.SERVICE);
062:
063: if (!kernelService.checkSecurity(uri,
064: KernelConstants.SECURITY_UPDATE)) {
065: throw new LibresourceSecurityException(uri,
066: KernelConstants.SECURITY_UPDATE);
067: }
068:
069: LibresourceFilesService libresourceFilesService = (LibresourceFilesService) Libresource
070: .getService(FileConstants.SERVICE);
071: FileResourceValue file = libresourceFilesService
072: .getFile(uri);
073: request.setAttribute("displayName", file.getDisplayName());
074: request.setAttribute("description", file.getDescription());
075: request.setAttribute("throwEvent", String.valueOf(file
076: .getThrowEvent()));
077: request.setAttribute("infos", file.getDownloadInfos());
078:
079: return "/pages/modules/files/editFile.jsp";
080: }
081:
082: // Set file info
083: String displayName = request.getParameter("displayName");
084: String description = request.getParameter("description");
085: String throwEvent = request.getParameter("throwEvent");
086:
087: LibresourceFilesService libresourceFilesService = (LibresourceFilesService) Libresource
088: .getService(FileConstants.SERVICE);
089:
090: if ((throwEvent != null) && (throwEvent.compareTo("on") == 0)) {
091: libresourceFilesService.editFile(uri, displayName,
092: description, null, true);
093: } else {
094: libresourceFilesService.editFile(uri, displayName,
095: description, null, false);
096: }
097:
098: return uri;
099: }
100: }
|