From 031c6bfd7fed0739e89297a068571860b1f31280 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Wed, 20 Nov 2024 12:27:15 +0000
Subject: [PATCH] Dokumentation in Arbeit: FileCatalog fertig dokumentiert, kleinere Anpassungen

---
 src/de/uhilger/neon/fm/FileCatalog.java |   75 +++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/src/de/uhilger/neon/fm/FileCatalog.java b/src/de/uhilger/neon/fm/FileCatalog.java
new file mode 100644
index 0000000..42e54f7
--- /dev/null
+++ b/src/de/uhilger/neon/fm/FileCatalog.java
@@ -0,0 +1,75 @@
+/*
+  neon-fm - Dateiverwaltung fuer neon
+  Copyright (C) 2024  Ulrich Hilger
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as
+  published by the Free Software Foundation, either version 3 of the
+  License, or (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU Affero General Public License for more details.
+
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package de.uhilger.neon.fm;
+
+import com.sun.net.httpserver.HttpContext;
+import com.sun.net.httpserver.HttpExchange;
+import de.uhilger.neon.FileServer;
+import de.uhilger.neon.HttpHelper;
+import de.uhilger.neon.HttpResponder;
+import de.uhilger.fm.Catalog;
+import java.io.IOException;
+
+/**
+ * Die Klasse FileCatalog liefert HTTP Methoden zur Erzeugung einer 
+ * Liste von Dateien und Ordnern
+ * 
+ * @author Ulrich Hilger
+ * @version 0.1, 05.11.2024
+ */
+public class FileCatalog extends AbstractFileActor {
+
+  /**
+   * <p>Diese Methode ist als Reaktion auf einen HTTP GET Aufruf an 
+   * folgenden URL gedacht und liefert eine Liste des Ordnerinhalts 
+   * im JSON-Format</p>
+   * 
+   * <pre>
+   * Ordnerinhalt auflisten:    
+   * http://localhost:[port]/[kontext]/pfad/zum/ordner/
+   * </pre>
+   * 
+   * @param exchange das Objekt mit Infos zu HTTP-Request, -Response usw.
+   */
+  public void list(HttpExchange exchange) {
+    try {
+      init(exchange);
+      HttpContext ctx = exchange.getHttpContext();
+      //String base = ctx.getAttributes().getOrDefault(FileServer.ATTR_FILE_BASE, "").toString();
+      if(base.length() == 0) {
+        new HttpResponder().sendNotFound(exchange, exchange.getRequestURI().toString()); // not found
+      } else {
+        String fName = new HttpHelper().getFileName(exchange);
+        if (fName.endsWith(FileServer.STR_SLASH)) { // Ordnerliste erzeugen
+          String json = new Catalog().list(fName, ctx.getPath(), base);
+          if (null != json) {
+            new HttpResponder().antwortSenden(exchange, HttpResponder.SC_OK, json);
+          } else {
+            new HttpResponder().antwortSenden(exchange, HttpResponder.SC_OK, "{}"); // leere Liste
+          }
+        } else {
+          new FileServer().serveFile(exchange); // Datei ausliefern
+        }
+      }
+    } catch (IOException | IllegalArgumentException ex) {
+      fehlerAntwort(exchange, ex);
+    } finally {
+      free();
+    }
+  }  
+}
\ No newline at end of file

--
Gitblit v1.9.3