commit | author | age
|
aed034
|
1 |
/* |
U |
2 |
neon-fm - Dateiverwaltung fuer neon |
|
3 |
Copyright (C) 2024 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.neon.fm; |
|
19 |
|
|
20 |
import com.sun.net.httpserver.HttpExchange; |
|
21 |
import de.uhilger.neon.HttpResponder; |
|
22 |
import de.uhilger.fm.Eraser; |
|
23 |
import java.io.IOException; |
|
24 |
import java.util.Arrays; |
|
25 |
import java.util.logging.Level; |
|
26 |
import java.util.logging.Logger; |
|
27 |
|
|
28 |
/** |
bb2648
|
29 |
* Loeschen von Dateien und Ordnern als Reaktion auf entsprechende |
516d0b
|
30 |
* Aufrufe mittels HTTP DELETE |
U |
31 |
* |
aed034
|
32 |
* @author Ulrich Hilger |
U |
33 |
* @version 0.1, 08.11.2024 |
|
34 |
*/ |
|
35 |
public class FileEraser extends AbstractFileActor { |
|
36 |
|
516d0b
|
37 |
/** |
bb2648
|
38 |
* <p>Diese Mthode ist als Reaktion auf einen HTTP DELETE Aufruf an |
516d0b
|
39 |
* folgenden URL gedacht</p> |
U |
40 |
* |
|
41 |
* <pre> |
|
42 |
* Dateien und Ordner loeschen: |
|
43 |
* http://localhost:[port]/[kontext]/pfad/zum/ordner/ |
|
44 |
* Body: Liste mit Datei- und Ordnernamen, die aus dem im URL |
|
45 |
* angegebenen Ordner geloescht werden sollen, z.B. ["test.txt","dok"] |
|
46 |
* Hiermit werden die Datei test.txt und der Ordner dok geloescht. |
|
47 |
* Das Loeschen geschieht rekursiv, einschliesslich aller Unterordner |
|
48 |
* </pre> |
|
49 |
* |
d64c87
|
50 |
* @param exchange das Objekt mit Infos zu HTTP-Request, -Response usw. |
516d0b
|
51 |
*/ |
U |
52 |
public void delete(HttpExchange exchange) { |
aed034
|
53 |
try { |
b3d917
|
54 |
init(exchange); |
aed034
|
55 |
String[] dateiNamen = dateiliste(exchange); |
U |
56 |
new Eraser().deleteFiles(fileName, Arrays.asList(dateiNamen), base); |
|
57 |
antwort(exchange, HttpResponder.SC_OK, "Dateien geloescht."); |
|
58 |
} catch (IOException ex) { |
|
59 |
Logger.getLogger(FileEraser.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); |
|
60 |
} finally { |
|
61 |
free(); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
} |