src/de/uhilger/mediaz/Server.java
@@ -19,6 +19,7 @@ import com.sun.net.httpserver.HttpServer; import de.uhilger.mediaz.api.FileHandler; import de.uhilger.mediaz.api.ListFileHandler; import de.uhilger.mediaz.api.StopServerHandler; import de.uhilger.mediaz.api.StorageHandler; import de.uhilger.mediaz.store.FileStorage; @@ -130,8 +131,9 @@ if(e instanceof Ablageort) { Ablageort ort = (Ablageort) e; Ablageort ablageort = (Ablageort) e; logger.fine(ctx + ablageort.getUrl()); server.createContext(ctx + ablageort.getUrl(), new FileHandler(new File(ablageort.getOrt()).getAbsolutePath())); new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath())); } } } src/de/uhilger/mediaz/api/AbstractHandler.java
New file @@ -0,0 +1,41 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.uhilger.mediaz.api; import com.google.gson.Gson; /** * * @author ulrich */ public class AbstractHandler { protected String jsonWithEnclosingType(Object o) { /* StringBuilder sb = new StringBuilder(); sb.append("{\""); sb.append(o.getClass().getSimpleName()); sb.append("\": "); Gson gson = new Gson(); sb.append(gson.toJson(o)); sb.append("}"); return sb.toString(); */ return jsonWithCustomType(o, o.getClass().getSimpleName()); } protected String jsonWithCustomType(Object o, String typeName) { StringBuilder sb = new StringBuilder(); sb.append("{\""); sb.append(typeName); sb.append("\": "); Gson gson = new Gson(); sb.append(gson.toJson(o)); sb.append("}"); return sb.toString(); } } src/de/uhilger/mediaz/api/FileHandler.java
@@ -21,7 +21,6 @@ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import de.uhilger.mediaz.App; import de.uhilger.mediaz.Server; import static de.uhilger.mediaz.Server.RB_SLASH; import java.io.File; import java.io.FileInputStream; @@ -48,7 +47,7 @@ * @author Ulrich Hilger * @version 0.1, 25. März 2021 */ public class FileHandler implements HttpHandler { public class FileHandler extends AbstractHandler implements HttpHandler { /* Der Logger fuer diesen FileHandler */ private static final Logger logger = Logger.getLogger(FileHandler.class.getName()); @@ -83,7 +82,7 @@ public static final String RB_WELCOME_FILE = "welcomeFile"; /* Ablageort fuer Webinhalte */ private final String fileBase; protected final String fileBase; /** * Ein neues Objekt der Klasse FileHandler erzeugen src/de/uhilger/mediaz/api/ListFileHandler.java
New file @@ -0,0 +1,68 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.uhilger.mediaz.api; import com.sun.net.httpserver.HttpExchange; import de.uhilger.mediaz.App; import de.uhilger.mediaz.Server; import de.uhilger.mediaz.store.StorageFile; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.logging.Logger; /** * * @author ulrich */ public class ListFileHandler extends FileHandler { /* Der Logger fuer diesen ListFileHandler */ private static final Logger logger = Logger.getLogger(ListFileHandler.class.getName()); public ListFileHandler(String absoluteDirectoryPathAndName) { super(absoluteDirectoryPathAndName); } @Override public void handle(HttpExchange e) throws IOException { String path = e.getRequestURI().toString(); logger.fine(path); if(path.endsWith(App.getRs(Server.RB_SLASH))) { String fName = getFileName(e); logger.fine(fName); File dir = new File(fileBase, fName); logger.fine(dir.getAbsolutePath()); File[] files = dir.listFiles(); ArrayList list = new ArrayList(); if(files != null) { for(File file : files) { StorageFile sf = new StorageFile(); sf.setName(file.getName()); if(file.isDirectory()) { sf.setTyp("folder"); } else { sf.setTyp("file"); } list.add(sf); } } //Gson gson = new Gson(); //String json = gson.toJson(fileNames); String json = jsonWithCustomType(list, "Medialiste"); logger.fine(json); e.sendResponseHeaders(200, json.length()); OutputStream os = e.getResponseBody(); os.write(json.getBytes()); os.close(); } else { super.handle(e); } } } src/de/uhilger/mediaz/api/StorageHandler.java
@@ -41,7 +41,7 @@ * @author Ulrich Hilger * @version 1, 5.4.2021 */ public class StorageHandler implements HttpHandler { public class StorageHandler extends AbstractHandler implements HttpHandler { private static final Logger logger = Logger.getLogger(StorageHandler.class.getName()); @@ -186,17 +186,6 @@ String elemName = elems[elems.length - 1]; return fs.readJson(type, elemName); } } private String jsonWithEnclosingType(Object o) { StringBuilder sb = new StringBuilder(); sb.append("{\""); sb.append(o.getClass().getSimpleName()); sb.append("\": "); Gson gson = new Gson(); sb.append(gson.toJson(o)); sb.append("}"); return sb.toString(); } private String bodyLesen(HttpExchange e) throws IOException { src/de/uhilger/mediaz/entity/Einstellung.java
New file @@ -0,0 +1,33 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.uhilger.mediaz.entity; /** * * @author ulrich */ public class Einstellung { private String key; private String value; public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } } src/de/uhilger/mediaz/store/StorageFile.java
New file @@ -0,0 +1,32 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.uhilger.mediaz.store; /** * * @author ulrich */ public class StorageFile { private String name; private String typ; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTyp() { return typ; } public void setTyp(String typ) { this.typ = typ; } } www/ui/data/katalog.css
New file @@ -0,0 +1,10 @@ /* To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. */ /* Created on : 06.04.2021, 15:26:45 Author : ulrich */ www/ui/data/katalog.html
New file @@ -0,0 +1,45 @@ <!DOCTYPE html> <!-- Mediazentrale - Personal Media Center Copyright (C) 2021 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/>. --> <html> <head> <title>Katalog</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="../app.css"> <link rel="stylesheet" type="text/css" href="formulare.css"> <link rel="stylesheet" type="text/css" href="katalog.css"> </head> <body> <div class="katalog-seite"> <div class="katalog-ueberschrift"> Katalog </div> <div class="katalog-breadcrumb"> Breadcrumb 1 | Breadcrumb 2 | Breadcrumb 3 | Breadcrumb 4 | Breadcrumb 5 | Breadcrumb 6 </div> <div class="katalog-eintraege"> <ul class="entity-liste"> <li class="entity-eintrag">Katalog</li> <li class="entity-eintrag">Katalog2</li> </ul> </div> </div> </body> </html> www/ui/data/menu/hauptmenue.json
@@ -8,6 +8,11 @@ }, "inhalt": [ { "titel": "Media", "umenue": false, "funktion": "app.media_liste" }, { "titel": "Ablageorte", "umenue": false, "funktion": "app.ablageort_liste" www/ui/data/tpl/katalog_inhalt_liste.tpl
New file @@ -0,0 +1,13 @@ <div class='entity-formular'> <div class='entity-liste-kopf'> Media-Liste <button class='button' id='zurueck-btn'>Zurück</button> </div> <ul class='entity-liste'> {{#Medialiste}} <li class='entity-eintrag entity-typ-{{typ}}'>{{name}}</li> {{/Medialiste}} </ul> </div> www/ui/data/tpl/katalog_root_liste.tpl
New file @@ -0,0 +1,19 @@ <div class='entity-formular'> <div class='entity-liste-kopf'> Media-Liste <!-- <button class='button' id='neu-btn'>Neu</button> --> </div> <ul class='entity-liste'> {{#ArrayList}} <li class='entity-eintrag'>{{.}}</li> {{/ArrayList}} </ul> </div> www/ui/js/app.js
@@ -10,6 +10,68 @@ var self = this; var appMenu; var cache; // mustache templates var ortPfad; var mediaPfad; // auf der obersten Ebene werden die Kataloge angezeigt, // darunter der Inhalt des aktuellen Pfades this.media_liste = function() { if(self.ortPfad === '/') { console.log("kein Pfad, liste Kataloge"); // Kataloge listen self.http_get('../api/store/Ablageort/', function (responseText) { self.vorlage_laden_und_fuellen("data/tpl/katalog_root_liste.tpl", JSON.parse(responseText), function (html) { document.querySelector(".zentraler-inhalt").innerHTML = html; self.addEvtListener('.entity-eintrag', 'click', function (event) { var t = event.target; self.http_get('../api/store/Ablageort/' + t.textContent, function(responseText) { var ablageort = JSON.parse(responseText); console.log(ablageort.url); self.ortPfad = ablageort.url; self.media_liste(); }); }); }); }); } else { console.log("liste Pfad " + self.mediaPfad); // Pfad listen self.http_get('..' + self.ortPfad + '/' + self.mediaPfad + '/', function(responseText) { console.log(responseText); self.vorlage_laden_und_fuellen("data/tpl/katalog_inhalt_liste.tpl", JSON.parse(responseText), function (html) { document.querySelector(".zentraler-inhalt").innerHTML = html; self.addEvtListener('.entity-eintrag', 'click', function (event) { var t = event.target; console.log(t.textContent); if(t.classList.contains("entity-typ-folder")) { self.mediaPfad = self.mediaPfad + '/' + t.textContent; self.media_liste(); } else { console.log("Media-Inhalt auswaehlen oder abspielen"); } }); self.addEvtListener('#zurueck-btn', 'click', function (event) { if(self.mediaPfad === '/') { self.ortPfad = '/'; } else { var pos = self.mediaPfad.lastIndexOf('/'); var parent = self.mediaPfad.substring(0, pos); console.log("Parent: " + parent); self.mediaPfad = parent; /* if(parent === '/') { self.ortPfad = '/'; } else { self.mediaPfad = parent; } */ } self.media_liste(); }); }); }); } }; this.ablageort_liste = function() { self.http_get('../api/store/Ablageort/', function (responseText) { @@ -18,7 +80,7 @@ self.addEvtListener('.entity-eintrag', 'click', function (event) { var t = event.target; self.http_get('../api/store/Ablageort/' + t.textContent, function(responseText){ ablageort = JSON.parse(responseText); var ablageort = JSON.parse(responseText); self.ablageort_form(ablageort); }); }); @@ -133,6 +195,8 @@ this.init = function () { //self.vorlagen = new Vorlagen(); self.mediaPfad = '/'; self.ortPfad = '/'; self.cache = new Array(); self.appMenu = new AppMenu(); self.appMenu.init(