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;
034:
035: import org.libresource.Libresource;
036: import org.libresource.LibresourceResourceIdentifier;
037: import org.libresource.LibresourceResourceValue;
038:
039: import org.libresource.kernel.KernelConstants;
040: import org.libresource.kernel.LibresourceSecurityException;
041: import org.libresource.kernel.interfaces.KernelService;
042:
043: import org.libresource.subversion.SubversionConstants;
044: import org.libresource.subversion.interfaces.LibresourceSubversionService;
045:
046: import org.libresource.web.Controller;
047:
048: import java.net.URI;
049:
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052:
053: public class DeleteController implements Controller {
054: public Object process(URI uri, HttpServletRequest request,
055: HttpServletResponse response) throws Exception {
056: KernelService kernelService = (KernelService) Libresource
057: .getService(KernelConstants.SERVICE);
058:
059: if (!kernelService.checkSecurity(uri,
060: KernelConstants.SECURITY_DELETE)) {
061: throw new LibresourceSecurityException(uri,
062: KernelConstants.SECURITY_DELETE);
063: }
064:
065: if (request.getParameter("cancel") != null) {
066: return uri;
067: }
068:
069: if (request.getParameter("confirm") == null) {
070: // modifié 06/04/2007
071: // 8+1 représente la profondeur de l'arbre affiche
072: StringBuffer buffer = new StringBuffer();
073:
074: LibresourceResourceValue[] resourceValues = kernelService
075: .listResourcesAt(uri);
076:
077: for (int i = 0; i < resourceValues.length; i++) {
078: ChildrenTreeController.listRecursively(
079: resourceValues[i], buffer, 0, 8);
080: }
081:
082: request.setAttribute("content", buffer.toString());
083:
084: return "/pages/deleteResource.jsp";
085: }
086:
087: URI parentUri;
088: parentUri = kernelService.getParent(uri);
089:
090: LibresourceResourceIdentifier resourceIdentifier = kernelService
091: .lookup(uri);
092:
093: if (resourceIdentifier == null) {
094: kernelService.deleteURI(uri);
095: } else {
096: if (SubversionConstants.RESOURCE.equals(resourceIdentifier
097: .getResourceType())) {
098: LibresourceSubversionService libresourceSubversionService = (LibresourceSubversionService) Libresource
099: .getService("LibresourceSubversion");
100: libresourceSubversionService.deleteRepository(uri);
101: } else {
102: kernelService.deleteURI(uri);
103: }
104: }
105:
106: return parentUri;
107: }
108: }
|