Added even more stuff
This commit is contained in:
parent
29d3ec8268
commit
d6e88977ba
7 changed files with 102 additions and 21 deletions
|
@ -1,9 +1,11 @@
|
|||
package hsmw.jotto5.beleg;
|
||||
|
||||
import hsmw.jotto5.beleg.views.*;
|
||||
import hsmw.jotto5.beleg.data.*;
|
||||
|
||||
import com.sun.net.httpserver.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import com.sun.net.httpserver.*;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Die Main-Klasse mit dem Einstiegspunkt der Anwendung.
|
||||
|
@ -14,19 +16,31 @@ public class Main {
|
|||
* Main-Methode
|
||||
* @param args Die Programmargumente
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
HttpServer s = HttpServer.create(new InetSocketAddress("127.0.0.1", 8000), 0);
|
||||
public static void main(String[] args) {
|
||||
Model m;
|
||||
|
||||
m = new Model();
|
||||
m.fillMockData();
|
||||
|
||||
|
||||
/**HttpServer s = null;
|
||||
|
||||
try {
|
||||
s = HttpServer.create(new InetSocketAddress("127.0.0.1", 8000), 0);
|
||||
// Kontexts werden nach längstem Matching ausgewählt (wieso?)
|
||||
// Alle unbekannten Anfragen die mit / starten werden also an die RootView gegeben
|
||||
// Statische Dateien werden auch von der RootView verarbeitet
|
||||
// TODO: Error Handling!!!
|
||||
s.createContext("/", new RootView());
|
||||
s.createContext("/main", new StartView());
|
||||
s.createContext("/auth", new AuthView());
|
||||
|
||||
s.setExecutor(null);
|
||||
s.start();
|
||||
} catch (IOException e) {
|
||||
System.err.println("IOException bei der Erstellung des HTTP Servers. Stack Trace folgt.");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}**/
|
||||
// schließen ist nicht nötig, da beim Beenden die ganze JVM zerstört wird
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ package hsmw.jotto5.beleg.data;
|
|||
* Vorgesehen ist die UID als Pfad-formatierter String mit "/" als Trennsymbol, um
|
||||
* DataObjects hierarchisch zu gliedern - der Inhalt ist aber eigentlich egal
|
||||
* (solange eindeutig).
|
||||
* <p>
|
||||
* Für alle DataObjects gilt, dass der Zugriff auf Methoden und Felder der Objekte
|
||||
* nicht definiert ist, solange sie nicht an ein Modell gebunden sind.
|
||||
*/
|
||||
public abstract class DataObject {
|
||||
|
||||
private Model model; // DataObjects speichern eine Referenz auf das Modell zu dem sie gehören
|
||||
protected Model model; // DataObjects speichern eine Referenz auf das Modell zu dem sie gehören
|
||||
protected String uid; // einmalige UID des Objektes
|
||||
private String displayName;
|
||||
protected String displayName;
|
||||
|
||||
/**
|
||||
* Konstruktor für manuelles Erzeugen.
|
||||
|
@ -39,4 +42,16 @@ public abstract class DataObject {
|
|||
this.model = m;
|
||||
}
|
||||
|
||||
public Model getModel() {
|
||||
return this.model;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,4 +15,11 @@ public class Group extends DataObject {
|
|||
super(uid, displayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt das DataObject mit der gegebenen UID zu der Gruppe hinzu.
|
||||
*/
|
||||
public void addMember(String uid) {
|
||||
this.model.addRelation(this.uid, uid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@ import java.util.HashMap;
|
|||
* Datenbank.
|
||||
* <p>
|
||||
* Die aktuelle Implementierung speichert alle DataObjects in einer HashMap, mit ihrer
|
||||
* UID als Key.
|
||||
* UID als Key. Das erlaubt schnelle forward-lookups (also Suche nach Obj mit gegebener UID),
|
||||
* was die deutlich häufiger ausgeführte Operation sein sollte.
|
||||
*/
|
||||
public class Model {
|
||||
|
||||
|
@ -29,12 +30,53 @@ public class Model {
|
|||
relations = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public void add(DataObject a) {
|
||||
/**
|
||||
* Füllt das Model mit Beispieldaten.
|
||||
*/
|
||||
public void fillMockData() {
|
||||
Group g1, g2, g3;
|
||||
|
||||
// Studierende
|
||||
new Student("students/jotto5", "Jocelyn", "Otto").bind(this);
|
||||
new Student("students/vnachn", "Vorname", "Nachname").bind(this);
|
||||
new Student("students/alovel", "Ada", "Lovelace").bind(this);
|
||||
new Student("students/aturin", "Alan", "Turing").bind(this);
|
||||
new Student("students/dknuth", "Donald", "Knuth").bind(this);
|
||||
new Student("students/ltorva", "Linus", "Torvalds").bind(this);
|
||||
new Student("students/dritch", "Dennis", "Ritchie").bind(this);
|
||||
|
||||
// Gruppen
|
||||
g1 = new Group("groups/IF24wS2-B", "Softwareentwicklung WiSe 24/25 Seminargruppe 2");
|
||||
g2 = new Group("groups/admins", "Administrator:innen");
|
||||
g3 = new Group("groups/alumni", "Alumni");
|
||||
new Group("groups/leer").bind(this);
|
||||
g1.bind(this);
|
||||
g2.bind(this);
|
||||
g3.bind(this);
|
||||
g1.addMember("students/jotto5");
|
||||
g2.addMember("students/vnachn");
|
||||
g2.addMember("students/ltorva");
|
||||
g3.addMember("alovel");
|
||||
g3.addMember("aturin");
|
||||
}
|
||||
|
||||
/*
|
||||
* Folgende Funktionen sind nur durch die DataObject-Objekte
|
||||
* zu verwenden, und sind daher protected.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fügt ein neues DataObject hinzu, also bindet es an das Model.
|
||||
*/
|
||||
protected void add(DataObject a) {
|
||||
// TODO: Auf doppelte UIDs überprüfen!
|
||||
this.objs.put(a.uid, a);
|
||||
}
|
||||
|
||||
public void addRelation(String a, String b) {
|
||||
/**
|
||||
* Fügt eine neue Objekt-Beziehung hinzu.
|
||||
*/
|
||||
protected void addRelation(String a, String b) {
|
||||
// TODO: Prüfen ob die Objekte existieren!
|
||||
this.relations.put(a, b);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ public class Student extends DataObject {
|
|||
/**
|
||||
* Konstruktor zum manuellen Erzeugen.
|
||||
*
|
||||
* Bindet das Objekt nicht an ein Model, das sollte getan werden!
|
||||
* <p>
|
||||
* Der displayName wird aus Vor- und Nachname zusammengesetzt. Beim Ändern der
|
||||
* Namensattribute wird die UID NICHT neu vergeben!
|
||||
* @param uid Die zu vergebende UID
|
||||
|
|
|
@ -5,7 +5,7 @@ package hsmw.jotto5.beleg.views;
|
|||
*/
|
||||
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>";
|
||||
public static final String HTMLFOOTER = "</body></html>";
|
||||
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 HTMLFOOTER = "</main></body></html>";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
* {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
main {
|
||||
max-width: 600px;
|
||||
margin: auto;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue