Implemented TreeView

This commit is contained in:
joss 2025-05-20 21:17:40 +02:00
parent ed01e2796c
commit aac199f5ed
2 changed files with 27 additions and 3 deletions

View file

@ -90,8 +90,20 @@ public class Model {
* oder null wenn es keines gibt.
*/
public DataObject get(String path) {
if ( !objs.containsKey(path) ) return null;
return objs.get(path);
if ( !this.objs.containsKey(path) ) return null;
return this.objs.get(path);
}
/**
* Gibt ein Array aus allen vorhandenen UIDs zurück.
*
* Praktisch für Anzeige von Listen.
* TODO: Eventuell ersetzen durch Rückgabe DataObjects?
*/
public String[] getAllUids() {
// was zur hölle ist das denn?
// siehe https://docs.oracle.com/javase/8/docs/api/java/util/Set.html#toArray-T:A-
return this.objs.keySet().toArray(new String[0]);
}
}

View file

@ -1,5 +1,7 @@
package hsmw.jotto5.beleg.views;
import hsmw.jotto5.beleg.data.Model;
import java.io.IOException;
import java.io.OutputStream;
import com.sun.net.httpserver.*;
@ -9,8 +11,18 @@ public class TreeView implements HttpHandler {
public void handle(HttpExchange t) throws IOException {
String response;
OutputStream os;
Model m;
m = Model.getModel();
response = Defaults.HTMLHEADER + "<h1>Beleg - Objekt&uuml;bersicht</h1><ul>";
for ( String s : m.getAllUids() ) {
response += "<li><a href=\"/object/" + s + "\">" + s + "</a></li>";
}
response += "</ul>" + Defaults.HTMLFOOTER;
response = Defaults.HTMLHEADER + "<h1>Beleg - Objekt&uuml;bersicht</h1>" + Defaults.HTMLFOOTER;
os = t.getResponseBody();
t.sendResponseHeaders(200, response.length());