src/de/uhilger/mediaz/Server.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/AblageTestHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/StorageHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/api/StoreTestHandler.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/store/FileStorage.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/mediaz/store/Storage.java | ●●●●● patch | view | raw | blame | history | |
www/ui/data/tpl/form_ablageort.tpl | ●●●●● patch | view | raw | blame | history | |
www/ui/js/app.js | ●●●●● patch | view | raw | blame | history |
src/de/uhilger/mediaz/Server.java
@@ -18,11 +18,9 @@ package de.uhilger.mediaz; import com.sun.net.httpserver.HttpServer; import de.uhilger.mediaz.api.AblageTestHandler; import de.uhilger.mediaz.api.FileHandler; import de.uhilger.mediaz.api.StopServerHandler; import de.uhilger.mediaz.api.StorageHandler; import de.uhilger.mediaz.api.StoreTestHandler; import de.uhilger.mediaz.store.FileStorage; import de.uhilger.mediaz.entity.Ablageort; import java.io.File; @@ -51,8 +49,8 @@ public static final String RB_STORE = "store"; //public static final String RB_UI_ROOT = "uiroot"; public static final String RB_STOP_SERVER = "stopServer"; public static final String RB_ABLAGE_TEST = "testAblage"; public static final String RB_STORE_TEST = "testStore"; //public static final String RB_ABLAGE_TEST = "testAblage"; //public static final String RB_STORE_TEST = "testStore"; public static final String RB_SLASH = "slash"; private int port; @@ -93,7 +91,7 @@ } /** * Die Endpunkte ('Context'e) einrichten, unter denen die Dienste dieses * Die Endpunkte einrichten, unter denen die Dienste dieses * Servers erreichbar sein sollen und den Server starten * * @throws IOException wenn etwas schief geht, finden sich Angaben in diesem @@ -115,8 +113,8 @@ server.createContext(ctx + App.getRs(RB_STORE), new StorageHandler()); //server.createContext(ctx + App.getRs(RB_UI_ROOT), new FileHandler(uiDir.getAbsolutePath())); server.createContext(ctx + App.getRs(RB_STOP_SERVER), new StopServerHandler()); server.createContext(ctx + App.getRs(RB_ABLAGE_TEST), new AblageTestHandler()); server.createContext(ctx + App.getRs(RB_STORE_TEST), new StoreTestHandler()); //server.createContext(ctx + App.getRs(RB_ABLAGE_TEST), new AblageTestHandler()); //server.createContext(ctx + App.getRs(RB_STORE_TEST), new StoreTestHandler()); server.setExecutor(Executors.newFixedThreadPool(20)); server.start(); } @@ -136,22 +134,5 @@ new FileHandler(new File(ablageort.getOrt()).getAbsolutePath())); } } /* String conf = App.getInitParameter(App.getRs(App.RB_AP_CONF)); File ablageortDir = new File(conf, Ablageort.class.getSimpleName()); File[] orte = ablageortDir.listFiles(); if (orte != null) { for (File ort : orte) { Entity elem = store.readFromFile(ort); if (elem instanceof Ablageort) { Ablageort ablageort = (Ablageort) elem; server.createContext(ctx + ablageort.getUrl(), new FileHandler(new File(ablageort.getOrt()).getAbsolutePath())); } } } */ } } src/de/uhilger/mediaz/api/AblageTestHandler.java
File was deleted src/de/uhilger/mediaz/api/StorageHandler.java
@@ -18,7 +18,6 @@ package de.uhilger.mediaz.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import de.uhilger.mediaz.App; @@ -37,7 +36,7 @@ import java.util.logging.Logger; /** * HttpHandler fuer die Ablage von Entitaeten der Mediazentrale * HttpHandler fuer die Verwaltung von Entitaeten der Mediazentrale * * @author Ulrich Hilger * @version 1, 5.4.2021 @@ -129,6 +128,14 @@ } private String neu(HttpExchange e) throws IOException { return schreiben(e, false); } private String aendern(HttpExchange e) throws IOException { return schreiben(e, true); } private String schreiben(HttpExchange e, boolean overwrite) throws IOException { String path = e.getRequestURI().toString(); String[] elems = path.split(App.getRs(Server.RB_SLASH)); String type = elems[elems.length - 1]; @@ -139,19 +146,22 @@ logger.log(Level.INFO, "type: {0}", type); Object o = gson.fromJson(body, fs.typeFromName(type).getType()); if(o instanceof Entity) { Object antwortObjekt = fs.write((Entity) o); Object antwortObjekt = fs.write((Entity) o, overwrite); if(antwortObjekt instanceof File) { File file = (File) antwortObjekt; logger.log(Level.INFO, "Datei {0} geschrieben.", file.getAbsolutePath()); filename = file.getName(); } } return type + FileHandler.STR_BLANK + filename; } } return type + FileHandler.STR_BLANK + " Operation 'neu' fuer bereits existierende Entitaet."; } /* private String aendern(HttpExchange e) throws IOException { return neu(e); // einstweilen wird einfach ueberschrieben } */ private boolean loeschen(HttpExchange e) { String path = e.getRequestURI().toString(); @@ -188,7 +198,6 @@ sb.append("}"); return sb.toString(); } private String bodyLesen(HttpExchange e) throws IOException { InputStream is = e.getRequestBody(); src/de/uhilger/mediaz/api/StoreTestHandler.java
File was deleted src/de/uhilger/mediaz/store/FileStorage.java
@@ -80,21 +80,25 @@ * * @param entity */ public File writeToFile(Entity entity) throws IOException { public File writeToFile(Entity entity, boolean overwrite) throws IOException { String className = entity.getClass().getSimpleName(); logger.finer(className); File dir = new File(fileBase, className); dir.mkdirs(); File file = new File(dir, entity.getName()); if(file.exists()) { file.delete(); } //if(file.exists()) { // file.delete(); //} if(file.exists() && !overwrite) { return null; } else { FileWriter fw = new FileWriter(file); Gson gson = new Gson(); fw.write(gson.toJson(entity)); fw.flush(); fw.close(); return file; } } public String readFromFile(File file) throws IOException { @@ -121,9 +125,9 @@ } @Override public Object write(Entity e) { public Object write(Entity e, boolean overwrite) { try { return writeToFile(e); return writeToFile(e, overwrite); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); return null; src/de/uhilger/mediaz/store/Storage.java
@@ -56,7 +56,7 @@ * @param e das Objekt, das geschrieben werden soll * @return ein Antwortobjekt oder null */ public Object write(Entity e); public Object write(Entity e, boolean overwrite); /** * Ein Objekt aus der Ablage lesen www/ui/data/tpl/form_ablageort.tpl
@@ -1,9 +1,9 @@ <div class="entity-formular"> Ablageort <input class="entity-element" type="text" id="ablageort-name" placeholder="Name" /> <input class="entity-element" type="text" id="ablageort-ort" placeholder="Pfad" /> <input class="entity-element" type="text" id="ablageort-url" placeholder="URL" /> <input class="entity-element" type="text" id="ablageort-name" placeholder="Name" value="{{name}}" /> <input class="entity-element" type="text" id="ablageort-ort" placeholder="Pfad" value="{{ort}}" /> <input class="entity-element" type="text" id="ablageort-url" placeholder="URL" value="{{url}}" /> <div class="entity-buttons"> <button class="button-primary" id="ok-btn">Speichern</button> <button class="button" id="cancel-btn">Abbrechen</button> www/ui/js/app.js
@@ -9,7 +9,6 @@ function Mediazentrale() { var self = this; var appMenu; // var vorlagen; var cache; // mustache templates this.ablageort_liste = function() { @@ -18,7 +17,6 @@ document.querySelector(".zentraler-inhalt").innerHTML = html; self.addEvtListener('.entity-eintrag', 'click', function (event) { var t = event.target; //self.meldung_mit_timeout(t.textContent, 1500); self.http_get('../api/store/Ablageort/' + t.textContent, function(responseText){ ablageort = JSON.parse(responseText); self.ablageort_form(ablageort); @@ -40,21 +38,26 @@ self.vorlage_laden_und_fuellen("data/tpl/form_ablageort.tpl", ort, function (html) { document.querySelector(".zentraler-inhalt").innerHTML = html; self.addEvtListener('#ok-btn', 'click', function () { var aName = document.querySelector('#ablageort-name').value; aName = aName.replace(' ', '').replace(/[\W]+/g, ''); var a = new Ablageort( document.querySelector('#ablageort-name').value, aName, document.querySelector('#ablageort-ort').value, document.querySelector('#ablageort-url').value ); var daten = JSON.stringify(a); if(typeof ort === "undefined") { if(typeof ort === "undefined" || ort.name !== aName) { // neu self.http_post('../api/store/Ablageort', daten, function (responseText) { // hier die Antwort verarbeiten }); } else { // aendern self.http_put('../api/store/Ablageort', daten, function (responseText) { // hier die Antwort verarbeiten }); } document.querySelector(".zentraler-inhalt").innerHTML = ''; }); self.addEvtListener('#cancel-btn', 'click', function () { document.querySelector(".zentraler-inhalt").innerHTML = ''; @@ -67,6 +70,8 @@ self.addEvtListener('#ja-btn', 'click', function() { self.http_delete('../api/store/Ablageort/' + aoname, '', function (responseText) { // hier die Antwort verarbeiten self.dialog_schliessen(); document.querySelector(".zentraler-inhalt").innerHTML = ''; }); }); }); @@ -95,6 +100,7 @@ }; this.http_delete = function (u, data, cb) { console.log("delete " + u); self.http_call('DELETE', u, data, cb); }; @@ -109,18 +115,11 @@ xhr.open(method, url); if (method === 'GET') { xhr.send(); } else if (method === 'POST' || method === 'PUT') { } else if (method === 'POST' || method === 'PUT' || method === 'DELETE') { xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.send(data); } }; this.serialisieren = function (obj) { return '{"' + obj.constructor.name + '":' + JSON.stringify(obj) + '}'; }; /* ab hier aus App-Vorlage */ @@ -233,26 +232,18 @@ self.http_get(vurl, function(antwort) { self.cache[vurl] = antwort; self.dialog_zeigen(vurl, msgTpl, cb); //self.dialog_zeigen(vurl, antwort, cb); //self.vorlage_fuellen(vurl, inhalt, cb); }); } else { self.dialog_zeigen(vurl, msgTpl, cb); //self.dialog_zeigen(vurl, vorlage, cb); } }; this.dialog_zeigen = function (vurl, inhalt, cb) { var dlg = document.querySelector(".dialog"); self.html_erzeugen( vurl, inhalt, function (html) { //dlg.html(html); self.html_erzeugen(vurl, inhalt, function (html) { dlg.style.height = '7em'; dlg.innerHTML = html; document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen); //dlg.slideDown(300); if(typeof(cb) !== 'function') { // .. } else { @@ -261,27 +252,9 @@ }); }; /* this.dialog_zeigen = function (vurl, inhalt) { var dlg = document.querySelector(".dialog"); self.html_erzeugen( vurl, inhalt, function (html) { //dlg.html(html); dlg.style.height = '5em'; dlg.innerHTML = html; document.querySelector('.close-btn').addEventListener('click', self.dialog_schliessen); //dlg.slideDown(300); }); }; */ self.dialog_schliessen = function () { document.querySelector('.close-btn').removeEventListener('click', self.dialog_schliessen); //$('.dialog').slideUp(300); var dlg = document.querySelector('.dialog'); //dlg.style.display = "none"; dlg.style.height = '0'; dlg.innerHTML = ''; }; @@ -314,8 +287,6 @@ }; this.vorlage_fuellen = function (vurl, inhalt, cb) { //console.log("vorlage " + self.cache[vurl]); //console.log("render " + inhalt); cb(Mustache.render(self.cache[vurl], inhalt)); }; @@ -328,16 +299,6 @@ Inhalt gefüllt ist */ this.vorlage_laden_und_fuellen = function (vurl, inhalt, cb) { /* $.ajax({ url: vurl, type: "GET", dataType : "text" }).done(function( vorlage ) { self.cache[vurl] = vorlage; self.vorlage_fuellen(vurl, inhalt, cb); }); */ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) {