Added TreeView and ObjectView
This commit is contained in:
parent
50f80d3397
commit
a35d259fd8
4 changed files with 82 additions and 2 deletions
|
@ -29,6 +29,8 @@ public class Main {
|
||||||
s.createContext("/", new RootView());
|
s.createContext("/", new RootView());
|
||||||
s.createContext("/main", new StartView());
|
s.createContext("/main", new StartView());
|
||||||
s.createContext("/auth", new AuthView());
|
s.createContext("/auth", new AuthView());
|
||||||
|
s.createContext("/tree", new TreeView());
|
||||||
|
s.createContext("/object", new ObjectView());
|
||||||
s.setExecutor(null);
|
s.setExecutor(null);
|
||||||
s.start();
|
s.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package hsmw.jotto5.beleg.views;
|
||||||
*/
|
*/
|
||||||
public class Defaults {
|
public class Defaults {
|
||||||
|
|
||||||
public static final String HTMLHEADER = "<!DOCTYPE html><html><title>Beleg SoSe 2025</title><link rel=stylesheet href=\"/style.css\"><head></head><body><main>";
|
public static final String HTMLHEADER = "<!DOCTYPE html><html><title>Beleg SoSe 2025</title><link rel=stylesheet href=\"/style.css\"><head></head><body><div id=\"content\"><main><hr>";
|
||||||
public static final String HTMLFOOTER = "</main></body></html>";
|
public static final String HTMLFOOTER = "</main><footer><i><center>Hier könnte ihr Text stehen!</center></i></footer></div></body></html>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
57
src/views/ObjectView.java
Normal file
57
src/views/ObjectView.java
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package hsmw.jotto5.beleg.views;
|
||||||
|
|
||||||
|
import hsmw.jotto5.beleg.data.DataObject;
|
||||||
|
import hsmw.jotto5.beleg.data.Model;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import com.sun.net.httpserver.*;
|
||||||
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
|
public class ObjectView implements HttpHandler {
|
||||||
|
|
||||||
|
public void handle(HttpExchange t) throws IOException {
|
||||||
|
String response;
|
||||||
|
String objectPath;
|
||||||
|
OutputStream os;
|
||||||
|
Model m = Model.getModel();
|
||||||
|
DataObject obj = null;
|
||||||
|
|
||||||
|
// Das angefragte Objekt finden
|
||||||
|
objectPath = t.getRequestURI().toString();
|
||||||
|
if (objectPath.length() >= 9) {
|
||||||
|
objectPath = objectPath.substring(8);
|
||||||
|
obj = m.get(objectPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( obj == null ) return; // TODO: 404 oder 500 zurückgeben!
|
||||||
|
|
||||||
|
// Die Tabelle ausgeben
|
||||||
|
response = Defaults.HTMLHEADER + "<h1>Beleg - Objektansicht</h1>";
|
||||||
|
response += "<table class=\"objecttable\">";
|
||||||
|
try {
|
||||||
|
for (Field f : obj.getClass().getFields()) {
|
||||||
|
if (f.isAnnotationPresent(DataObject.WebField.class)) {
|
||||||
|
// Das Feld hat die "WebField"-Annotation, ist also anzuzeigen
|
||||||
|
response += "<tr><td>" + f.getAnnotation(DataObject.WebField.class).displayAs() + "</td>";
|
||||||
|
// Feld anzeigen
|
||||||
|
response += "<td><input type=\"text\" value=\"" + f.get(obj).toString() + "\" disabled /></td></tr>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(IllegalAccessException e) {
|
||||||
|
// hier sollten wir niemals her kommen
|
||||||
|
// TODO: 500 werfen
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
response += "</table><button>Speichern</button>";
|
||||||
|
|
||||||
|
response += Defaults.HTMLFOOTER;
|
||||||
|
os = t.getResponseBody();
|
||||||
|
|
||||||
|
t.sendResponseHeaders(200, response.length());
|
||||||
|
os.write(response.getBytes());
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
src/views/TreeView.java
Normal file
21
src/views/TreeView.java
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package hsmw.jotto5.beleg.views;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import com.sun.net.httpserver.*;
|
||||||
|
|
||||||
|
public class TreeView implements HttpHandler {
|
||||||
|
|
||||||
|
public void handle(HttpExchange t) throws IOException {
|
||||||
|
String response;
|
||||||
|
OutputStream os;
|
||||||
|
|
||||||
|
response = Defaults.HTMLHEADER + "<h1>Beleg - Objektübersicht</h1>" + Defaults.HTMLFOOTER;
|
||||||
|
os = t.getResponseBody();
|
||||||
|
|
||||||
|
t.sendResponseHeaders(200, response.length());
|
||||||
|
os.write(response.getBytes());
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue