From f70acbb491c6421623cca57292a75f1820efad4d Mon Sep 17 00:00:00 2001
From: ulrich
Date: Thu, 06 May 2021 16:41:59 +0000
Subject: [PATCH] Nicht erforderliche globale Variablen entfernt

---
 src/de/uhilger/tango/api/MediaSteuerung.java    |   16 ++-
 src/de/uhilger/tango/api/ListHandler.java       |   13 +
 src/de/uhilger/tango/App.java                   |   63 ++----------
 src/de/uhilger/tango/api/StopServerHandler.java |   17 ++
 src/de/uhilger/tango/api/FileHandler.java       |   27 +++-
 src/de/uhilger/tango/api/AbstractHandler.java   |   11 ++
 src/de/uhilger/tango/api/GeraetSteuerung.java   |    8 +
 src/de/uhilger/tango/api/StorageHandler.java    |   41 ++++++--
 src/de/uhilger/tango/Server.java                |   40 ++++---
 src/de/uhilger/tango/api/ListFileHandler.java   |   10 +
 10 files changed, 141 insertions(+), 105 deletions(-)

diff --git a/src/de/uhilger/tango/App.java b/src/de/uhilger/tango/App.java
index 1d0d5b9..690df7f 100644
--- a/src/de/uhilger/tango/App.java
+++ b/src/de/uhilger/tango/App.java
@@ -20,6 +20,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -40,16 +41,8 @@
 
   private static final Logger logger = Logger.getLogger(App.class.getName());
 
-  private static HashMap initParams;
-  
-  /* ResourceBundle dieser App */
-  private static ResourceBundle rb;
-  
   /* Name des ResourceBundles dieser App */
-  private static final String RB_NAME = "tango";
-  
-  /* Der Server dieser App */
-  private static Server server;
+  public static final String RB_NAME = "tango";
   
   /* ResourceBundle-Kennungen */
   public static final String RB_PARAM_FEHLT = "msgParamFehlt";
@@ -72,71 +65,41 @@
    * @throws java.lang.ClassNotFoundException
    */
   public static void main(String[] args) throws ClassNotFoundException {
-    rb = ResourceBundle.getBundle(RB_NAME);
+    ResourceBundle rb = ResourceBundle.getBundle(RB_NAME);
     logger.fine(new File(".").getAbsolutePath());
     
-    initParams = new HashMap();
+    HashMap<String,String> initParams = new HashMap();
     for (String arg : args) {
       String[] argParts = arg.split("=");
       initParams.put(argParts[0], argParts[1]);
     }
 
-    String portStr = getInitParameter(getRs(RB_AP_PORT));
+    String portStr = initParams.get(rb.getString(RB_AP_PORT)); 
     if (portStr != null) {
       //Server server = new Server(Integer.parseInt(portStr));
-      server = new Server(Integer.parseInt(portStr));
+      Server server = new Server(Integer.parseInt(portStr));
       try {
-        String ctxName = getInitParameter(getRs(RB_AP_CTX));
+        String ctxName = initParams.get(rb.getString(RB_AP_CTX));
         if (ctxName != null) {
           server.setContextName(ctxName);
-          server.start();
+          server.start(initParams.get(rb.getString(RB_AP_WWW_DATA)), 
+                  initParams.get(rb.getString(RB_AP_CONF)));
         } else {
-          logger.log(Level.INFO, getRs(RB_PARAM_FEHLT), getRs(RB_AP_CTX));
+          logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CTX));
         }
-        String conf = getInitParameter(getRs(RB_AP_CONF));
+        String conf = initParams.get(rb.getString(RB_AP_CONF));
         if(conf != null) {
           File confDir = new File(conf);
           confDir.mkdirs();
         } else {
-          logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_CONF));
+          logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CONF));
         }
       } catch (IOException ex) {
         logger.log(Level.SEVERE, null, ex);
       }
     } else {
-      logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_PORT));
+      logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_PORT));
     }
-  }
-
-  /**
-   * Diese Anwendung stoppen
-   */
-  public static void stop() {
-    System.exit(0);
-  }
-
-  /**
-   * Einen Kommandozeilenparameter ermitteln
-   *
-   * @param pname Names des Parameters
-   * @return Inhalt des Parameters oder null, wenn der Parameter nicht gefunden
-   * wurde
-   */
-  public static String getInitParameter(String pname) {
-    String param = null;
-    Object o = initParams.get(pname);
-    if (o != null) {
-      param = o.toString();
-    }
-    return param;
-  }
-  
-  public static String getRs(String key) {
-    return rb.getString(key);
-  }
-  
-  public static Server getServer() {
-    return server;
   }
 
 }
diff --git a/src/de/uhilger/tango/Server.java b/src/de/uhilger/tango/Server.java
index 3421d47..d356c0f 100644
--- a/src/de/uhilger/tango/Server.java
+++ b/src/de/uhilger/tango/Server.java
@@ -36,6 +36,7 @@
 import de.uhilger.tango.entity.Entity;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ResourceBundle;
 
 /**
  * Die Klasse Server stellt Methoden zur Ausf&uuml;hrung eines HTTP-Servers
@@ -64,7 +65,7 @@
 
   private String ctx;
   
-  private HttpServer server;
+  //private HttpServer server;
 
   /**
    * Ein neues Objekt der Kalsse Server erzeugen
@@ -73,7 +74,7 @@
    */
   public Server(int port) {
     this.port = port;
-  }
+  }  
 
   /**
    * Den Port angeben, unter dem der Server erreichbar sein soll
@@ -106,38 +107,41 @@
    * Objekt
    * @throws java.lang.ClassNotFoundException
    */
-  public void start() throws IOException, ClassNotFoundException {
-    logger.log(Level.INFO, App.getRs(RB_SERVER_START_MSG), Integer.toString(port));
+  public void start(String wwwData, String conf) throws IOException, ClassNotFoundException {
+    ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME);
+    logger.log(Level.INFO, rb.getString(RB_SERVER_START_MSG), Integer.toString(port));
 
-    String wwwData = App.getInitParameter(App.getRs(App.RB_AP_WWW_DATA));
+    //String wwwData = App.getInitParameter(rb.getString(App.RB_AP_WWW_DATA));
     File wwwDir = new File(wwwData);
 
-    server = HttpServer.create(new InetSocketAddress(port), 0);
-    server.createContext(ctx + App.getRs(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath()));
-    ablageorteEinklinken(server);
-    server.createContext(ctx + App.getRs(RB_STORE), new StorageHandler());
-    server.createContext(ctx + App.getRs(RB_STRG), new MediaSteuerung());
-    server.createContext(ctx + App.getRs(RB_GSTRG), new GeraetSteuerung());
-    server.createContext(ctx + App.getRs(RB_ALIST), new ListHandler());
-    server.createContext(ctx + App.getRs(RB_STOP_SERVER), new StopServerHandler());
+    HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
+    server.createContext(ctx + rb.getString(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath()));
+    ablageorteEinklinken(server, rb, conf);
+    server.createContext(ctx + rb.getString(RB_STORE), new StorageHandler(conf));
+    server.createContext(ctx + rb.getString(RB_STRG), new MediaSteuerung(conf));
+    server.createContext(ctx + rb.getString(RB_GSTRG), new GeraetSteuerung(conf));
+    server.createContext(ctx + rb.getString(RB_ALIST), new ListHandler(conf));
+    server.createContext(ctx + rb.getString(RB_STOP_SERVER), new StopServerHandler());
     //server.setExecutor(Executors.newFixedThreadPool(20));
     server.setExecutor(Executors.newCachedThreadPool());
     server.start();
   }
   
+  /*
   public void ablageortEntfernen(String url) {
     server.removeContext(ctx + url);
   }
 
-  public void ablageortHinzufuegen(Ablageort ort) {
+  public void ablageortHinzufuegen(Ablageort ort, String conf) {
     server.createContext(ctx + ort.getUrl(),  
-          new ListFileHandler(new File(ort.getOrt()).getAbsolutePath()));
+          new ListFileHandler(new File(ort.getOrt()).getAbsolutePath(), conf));
   }
+  */
   
-  private void ablageorteEinklinken(HttpServer server) 
+  private void ablageorteEinklinken(HttpServer server, ResourceBundle rb, String conf) 
               throws ClassNotFoundException, IOException {
     String typ = Ablageort.class.getSimpleName();
-    FileStorage store = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage store = new FileStorage(conf);
     List<String> orte = store.list(typ);
     Iterator<String> i = orte.iterator();
     while(i.hasNext()) {
@@ -148,7 +152,7 @@
         logger.log(Level.FINE, "{0}{1}", new Object[]{ctx, ablageort.getUrl()});
         logger.fine(ablageort.getOrt());
         server.createContext(ctx + ablageort.getUrl(),  
-          new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath()));
+          new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath(), conf));
       }
     }
   }
diff --git a/src/de/uhilger/tango/api/AbstractHandler.java b/src/de/uhilger/tango/api/AbstractHandler.java
index 9afb94e..891b06d 100644
--- a/src/de/uhilger/tango/api/AbstractHandler.java
+++ b/src/de/uhilger/tango/api/AbstractHandler.java
@@ -20,11 +20,13 @@
 import com.sun.net.httpserver.Headers;
 import com.sun.net.httpserver.HttpExchange;
 import com.sun.net.httpserver.HttpHandler;
+import de.uhilger.tango.App;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 
@@ -53,6 +55,8 @@
   public static final int RTC_NOT_FOUND = 404;
   
   protected int returnCode;
+  
+  private ResourceBundle rb;
 
   public AbstractHandler() {
     this.returnCode = RTC_OK;
@@ -144,4 +148,11 @@
   protected abstract boolean delete(HttpExchange e);
   */
   
+  protected String getResString(String key) {
+    if(rb == null) {
+      rb = ResourceBundle.getBundle(App.RB_NAME);
+    }
+    return rb.getString(key);
+  }
+  
 }
diff --git a/src/de/uhilger/tango/api/FileHandler.java b/src/de/uhilger/tango/api/FileHandler.java
index 05b8bbd..40edfed 100644
--- a/src/de/uhilger/tango/api/FileHandler.java
+++ b/src/de/uhilger/tango/api/FileHandler.java
@@ -34,6 +34,7 @@
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 /**
@@ -83,6 +84,8 @@
 
   /* Ablageort fuer Webinhalte */
   protected final String fileBase;
+  
+  private ResourceBundle rb;
 
   /**
    * Ein neues Objekt der Klasse FileHandler erzeugen
@@ -115,7 +118,8 @@
         serveFileParts(e, new File(fileBase, fName));
       } else {
         if (fName.length() < 1 || fName.endsWith(Server.SLASH)) {
-          fName += App.getRs(RB_WELCOME_FILE);
+          ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME);
+          fName += getResString(RB_WELCOME_FILE);
         }
         serveFile(e, new File(fileBase, fName));
       }
@@ -257,7 +261,7 @@
       Der regulaere Ausdruck "[^\\d-,]" bezeichnet alle Zeichen, die keine 
       Ziffern 0-9, Bindestrich oder Komma sind.
      */
-    rangeHeader = rangeHeader.replaceAll(App.getRs(RB_RANGE_PATTERN), "");
+    rangeHeader = rangeHeader.replaceAll(getResString(RB_RANGE_PATTERN), "");
 
     /*
       Die Ranges ermitteln. 
@@ -280,7 +284,7 @@
     String[] rangeArray = rangeHeader.split(STR_COMMA);
     for (String rangeStr : rangeArray) {
       Range range = new Range();
-      String[] values = rangeStr.split(App.getRs(RB_DASH));
+      String[] values = rangeStr.split(getResString(RB_DASH));
       if (values.length < 2) {
         // Fall 3
         range.setStart(Long.parseLong(values[0]));
@@ -311,10 +315,10 @@
    */
   protected String contentRangeHdr(Range range, File file) {
     StringBuilder sb = new StringBuilder();
-    sb.append(App.getRs(RB_BYTES));
+    sb.append(getResString(RB_BYTES));
     sb.append(STR_BLANK);
     sb.append(range.getStart());
-    sb.append(App.getRs(RB_DASH));
+    sb.append(getResString(RB_DASH));
     sb.append(range.getEnd());
     sb.append(Server.SLASH);
     sb.append(file.length());
@@ -333,12 +337,12 @@
    */
   protected void setHeaders(HttpExchange e, File file) throws IOException {
     Headers resHeaders = e.getResponseHeaders();
-    resHeaders.add(ACCEPT_RANGES_HEADER, App.getRs(RB_BYTES));
+    resHeaders.add(ACCEPT_RANGES_HEADER, getResString(RB_BYTES));
     String mimeType = Files.probeContentType(file.toPath());
     if (mimeType != null) {
       resHeaders.add(CONTENT_TYPE, mimeType);
     }
-    SimpleDateFormat sdf = new SimpleDateFormat(App.getRs(RB_LM_PATTERN));
+    SimpleDateFormat sdf = new SimpleDateFormat(getResString(RB_LM_PATTERN));
     Date date = new Date(file.lastModified());
     resHeaders.add(LAST_MODIFIED_DATE_HEADER, sdf.format(date));
   }
@@ -353,7 +357,7 @@
    */
   protected void sendNotFound(HttpExchange e, String fname) throws IOException {
     OutputStream os = e.getResponseBody();
-    String response = fname + STR_BLANK + App.getRs(RB_NOT_FOUND);
+    String response = fname + STR_BLANK + getResString(RB_NOT_FOUND);
     byte[] bytes = response.getBytes(StandardCharsets.UTF_8);
     e.sendResponseHeaders(SC_NOT_FOUND, bytes.length);
     os.write(bytes);
@@ -452,4 +456,11 @@
       return ranges.iterator();
     }
   }
+  
+  protected String getResString(String key) {
+    if(rb == null) {
+      rb = ResourceBundle.getBundle(App.RB_NAME);
+    }
+    return rb.getString(key);
+  }
 }
diff --git a/src/de/uhilger/tango/api/GeraetSteuerung.java b/src/de/uhilger/tango/api/GeraetSteuerung.java
index 3b9a65a..f5bc27a 100644
--- a/src/de/uhilger/tango/api/GeraetSteuerung.java
+++ b/src/de/uhilger/tango/api/GeraetSteuerung.java
@@ -48,12 +48,18 @@
   public static final String KMD_AUS = "aus";
   public static final String KMD_STATUS = "status";
   
+  private String conf;
+  
+  public GeraetSteuerung(String conf) {
+    this.conf = conf;
+  }
+  
   @Override
   protected String get(HttpExchange e) {
     String response;
     String path = e.getRequestURI().toString();
     String[] elems = path.split(Server.SLASH);
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     logger.fine(path);
     
     String geraetName = elems[5];
diff --git a/src/de/uhilger/tango/api/ListFileHandler.java b/src/de/uhilger/tango/api/ListFileHandler.java
index 3aed9e0..12c44db 100644
--- a/src/de/uhilger/tango/api/ListFileHandler.java
+++ b/src/de/uhilger/tango/api/ListFileHandler.java
@@ -58,7 +58,9 @@
   
   Map extMap = new HashMap();
   
-  public ListFileHandler(String absoluteDirectoryPathAndName) {
+  private String conf;
+  
+  public ListFileHandler(String absoluteDirectoryPathAndName, String conf) {
     super(absoluteDirectoryPathAndName);
     /*
       Ermittlung von Dateifiltern. 
@@ -66,9 +68,9 @@
       jeweils als Dateierweiterungen mit Komma getrennt
       z.B. "mp4,m4v"
     */
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
-    initMap(fs, App.getRs(App.RB_AUDIOEXTS), StorageFile.TYP_AUDIO);
-    initMap(fs, App.getRs(App.RB_VIDEOEXTS), StorageFile.TYP_VIDEO);
+    FileStorage fs = new FileStorage(conf);
+    initMap(fs, getResString(App.RB_AUDIOEXTS), StorageFile.TYP_AUDIO);
+    initMap(fs, getResString(App.RB_VIDEOEXTS), StorageFile.TYP_VIDEO);
   }
 
   private void initMap(Storage s, String key, String typ) {
diff --git a/src/de/uhilger/tango/api/ListHandler.java b/src/de/uhilger/tango/api/ListHandler.java
index 719f911..8154211 100644
--- a/src/de/uhilger/tango/api/ListHandler.java
+++ b/src/de/uhilger/tango/api/ListHandler.java
@@ -45,14 +45,19 @@
   private static final Logger logger = Logger.getLogger(ListHandler.class.getName());
   
   public static final String ALLE_TITEL = "alle";
-
+  
+  private String conf;
+  
+  public ListHandler(String conf) {
+    this.conf = conf;
+  }
 
   @Override
   protected String get(HttpExchange e) {
     String path = e.getRequestURI().toString();
     String[] elems = path.split(Server.SLASH);
     String plname = elems[elems.length - 1];
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     String json = fs.readJson(FileStorage.ST_ABSPIELLISTE, plname);
     return embedInCustomType(json, FileStorage.ST_ABSPIELLISTE);
   }
@@ -75,7 +80,7 @@
   }
   
   private String addTitel(HttpExchange e, String plname) throws IOException {
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     Entity entity = fs.read(FileStorage.ST_ABSPIELLISTE, plname);
     String response = "Titel konnte nicht hinzugefuegt werden.";
     if(entity instanceof Abspielliste) {
@@ -104,7 +109,7 @@
     String path = e.getRequestURI().toString();
     String[] elems = path.split(Server.SLASH);
     String listName = elems[elems.length - 2];
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     Entity entity = fs.read(Abspielliste.class.getSimpleName(), listName);
     if(entity instanceof Abspielliste) {
       Abspielliste liste = (Abspielliste) entity;
diff --git a/src/de/uhilger/tango/api/MediaSteuerung.java b/src/de/uhilger/tango/api/MediaSteuerung.java
index e55be01..7c75242 100644
--- a/src/de/uhilger/tango/api/MediaSteuerung.java
+++ b/src/de/uhilger/tango/api/MediaSteuerung.java
@@ -79,13 +79,19 @@
   public static final String DEFAULT_HOST = "http://localhost:9090";
 
   private final Map spielt = new HashMap();
+  
+  private String conf;
+  
+  public MediaSteuerung(String conf) {
+    this.conf = conf;
+  }
 
   @Override
   protected String get(HttpExchange e) {
     String response;
     String path = e.getRequestURI().toString();
     String[] elems = path.split(Server.SLASH);
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     logger.fine(path);
     
     // Faustregel: Anzahl Elemente eines URL plus 1 ist die Anzahl der Elemente des 
@@ -139,7 +145,7 @@
   private String urlAbspielen(HttpExchange e, String abspielerKmd) throws IOException {
     String path = e.getRequestURI().toString();
     String[] elems = path.split(Server.SLASH);
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     if(elems[6].equalsIgnoreCase("titel")) {
       String titelJson = bodyLesen(e);
       Gson gson = new Gson();
@@ -150,7 +156,7 @@
         Entity entity = fs.read(FileStorage.ST_ABSPIELER, elems[4]);
         if (entity instanceof Abspieler) {
           Abspieler abspieler = (Abspieler) entity;
-          String server = getEinstellung(fs, App.getRs(App.RB_HOST), DEFAULT_HOST);
+          String server = getEinstellung(fs, getResString(App.RB_HOST), DEFAULT_HOST);
           String signal = abspielKommando(fs, abspieler, server, titelUrl, abspielerKmd).toString();
           abspielerKommandoSenden(signal);
           return signal + "gesendet.";
@@ -286,7 +292,7 @@
     vorgang.setTitelNr(titelNr);
     spielt.put(abspieler.getName(), vorgang);
     
-    String server = getEinstellung(s, App.getRs(App.RB_HOST), DEFAULT_HOST);
+    String server = getEinstellung(s, getResString(App.RB_HOST), DEFAULT_HOST);
 
     /*
 
@@ -320,7 +326,7 @@
     //kmd.append(PL_CMD_PLAY);
     kmd.append(abspielKmd);
     // Parameter fuer den Abspieler holen
-    kmd.append(getEinstellung(s, App.getRs(App.RB_PLAYERPARAMS), PL_DEFAULT_PARAMS));
+    kmd.append(getEinstellung(s, getResString(App.RB_PLAYERPARAMS), PL_DEFAULT_PARAMS));
     kmd.append(server);
     kmd.append(titelUrl);
 
diff --git a/src/de/uhilger/tango/api/StopServerHandler.java b/src/de/uhilger/tango/api/StopServerHandler.java
index 33b9d61..bcad82c 100644
--- a/src/de/uhilger/tango/api/StopServerHandler.java
+++ b/src/de/uhilger/tango/api/StopServerHandler.java
@@ -22,6 +22,7 @@
 import de.uhilger.tango.App;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ResourceBundle;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.logging.Logger;
@@ -41,6 +42,8 @@
   public static final String RB_SERVER_STOPPED = "serverStopped";
   public static final String RB_MEDIAZ_END = "mediazEnd";
 
+  private ResourceBundle rb;
+  
   /**
    * Den Server geordnet herunterfahren und 
    * dann die Anwendung beenden.
@@ -52,13 +55,13 @@
   @Override
   public void handle(HttpExchange e) throws IOException {
     Logger.getLogger(StopServerHandler.class.getName()).info(e.getRequestURI().toString());
-    String response = App.getRs(RB_SERVER_STOPPED);
+    String response = getResString(RB_SERVER_STOPPED);
     e.sendResponseHeaders(200, response.length());
     OutputStream os = e.getResponseBody();
     os.write(response.getBytes());
     os.flush();
     os.close();
-    logger.info(App.getRs(RB_STOPPING_SERVER));
+    logger.info(getResString(RB_STOPPING_SERVER));
     e.getHttpContext().getServer().stop(1);
     Timer timer = new Timer();
     timer.schedule(new AppStopper(), 2000);
@@ -72,9 +75,15 @@
 
     @Override
     public void run() {
-      logger.info(App.getRs(RB_MEDIAZ_END));
-      App.stop();
+      logger.info(getResString(RB_MEDIAZ_END));
+      System.exit(0);
     }
   }
 
+  protected String getResString(String key) {
+    if(rb == null) {
+      rb = ResourceBundle.getBundle(App.RB_NAME);
+    }
+    return rb.getString(key);
+  }
 }
diff --git a/src/de/uhilger/tango/api/StorageHandler.java b/src/de/uhilger/tango/api/StorageHandler.java
index 52a0f08..1e23628 100644
--- a/src/de/uhilger/tango/api/StorageHandler.java
+++ b/src/de/uhilger/tango/api/StorageHandler.java
@@ -18,6 +18,7 @@
 package de.uhilger.tango.api;
 
 import com.google.gson.Gson;
+import com.sun.net.httpserver.HttpContext;
 import com.sun.net.httpserver.HttpExchange;
 import de.uhilger.tango.App;
 import static de.uhilger.tango.App.RB_EP_LISTE;
@@ -30,6 +31,7 @@
 import static de.uhilger.tango.store.FileStorage.ST_ABLAGEORT;
 import static de.uhilger.tango.store.FileStorage.ST_GERAET;
 import de.uhilger.tango.store.Storage;
+import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.util.Iterator;
@@ -60,6 +62,12 @@
 public class StorageHandler extends AbstractHandler {
   
   private static final Logger logger = Logger.getLogger(StorageHandler.class.getName());
+  
+  private String conf;
+  
+  public StorageHandler(String conf) {
+    this.conf = conf;
+  }
 
   @Override
   protected String put(HttpExchange e) throws IOException {
@@ -67,8 +75,8 @@
     String[] elems = path.split(Server.SLASH);
     String type = elems[elems.length - 2];
     String elemName = elems[elems.length - 1]; // alter Name, wenn Aenderung
-    if(!elemName.equalsIgnoreCase(App.getRs(RB_EP_LISTE))) {
-      FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    if(!elemName.equalsIgnoreCase(getResString(RB_EP_LISTE))) {
+      FileStorage fs = new FileStorage(conf);
       Gson gson = new Gson();
       logger.log(Level.FINE, "type: {0}, token: {1}", new Object[]{type, fs.typeFromName(type).getType().getTypeName()});
       Object o = gson.fromJson(bodyLesen(e), fs.typeFromName(type).getType());
@@ -81,7 +89,8 @@
             Entity aoe = fs.read(type, elemName);
             if(aoe instanceof Ablageort) {
               Ablageort ablageort = (Ablageort) aoe;
-              App.getServer().ablageortEntfernen(ablageort.getUrl());      
+              //App.getServer().ablageortEntfernen(ablageort.getUrl());      
+              e.getHttpContext().getServer().removeContext(ablageort.getUrl());
             }
           }
           fs.write(entity, true);
@@ -89,7 +98,8 @@
           if(type.equalsIgnoreCase(FileStorage.ST_ABLAGEORT)) {
             if(entity instanceof Ablageort) {
               Ablageort ablageort = (Ablageort) entity;
-              App.getServer().ablageortHinzufuegen(ablageort);
+              //App.getServer().ablageortHinzufuegen(ablageort);
+              ablageortHinzufuegen(e, ablageort);
             }
           }
         } else { // Neu
@@ -98,7 +108,8 @@
           if(type.equalsIgnoreCase(FileStorage.ST_ABLAGEORT)) {
             if(entity instanceof Ablageort) {
               Ablageort ablageort = (Ablageort) entity;
-              App.getServer().ablageortHinzufuegen(ablageort);
+              //App.getServer().ablageortHinzufuegen(ablageort);
+              ablageortHinzufuegen(e, ablageort);
             }
           }
         }
@@ -107,8 +118,15 @@
         return "Ungueltiges Objekt im Body.";
       }
     } else {
-      return "Ungueltiger Elementname: " + App.getRs(RB_EP_LISTE);
+      return "Ungueltiger Elementname: " + getResString(RB_EP_LISTE);
     }
+  }
+  
+  private void ablageortHinzufuegen(HttpExchange e, Ablageort ort) {
+    HttpContext c = e.getHttpContext();
+    String ctx = c.getPath();
+    c.getServer().createContext(ctx + ort.getUrl(),  
+          new ListFileHandler(new File(ort.getOrt()).getAbsolutePath(), conf));  
   }
   
   private boolean loeschen(HttpExchange e) {
@@ -116,13 +134,14 @@
     String[] elems = path.split(Server.SLASH);
     String type = elems[elems.length - 2];
     String elemName = elems[elems.length - 1];
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     if(type.equalsIgnoreCase(FileStorage.ST_ABLAGEORT)) {
       // im laufenden Server den Context entfernen
       Entity entity = fs.read(type, elemName);
       if(entity instanceof Ablageort) {
         Ablageort ablageort = (Ablageort) entity;
-        App.getServer().ablageortEntfernen(ablageort.getUrl());      
+        //App.getServer().ablageortEntfernen(ablageort.getUrl());      
+        e.getHttpContext().getServer().removeContext(ablageort.getUrl());
       }
     }
     return fs.delete(type, elemName);
@@ -131,10 +150,10 @@
   private String lesen(HttpExchange e) throws IOException, InterruptedException {
     String path = e.getRequestURI().toString();
     String[] elems = path.split(Server.SLASH);
-    FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
+    FileStorage fs = new FileStorage(conf);
     if(path.endsWith(Server.SLASH)) {
       List list = null;
-      if(elems[elems.length - 1].equalsIgnoreCase(App.getRs(RB_EP_LISTE_ALLES))) {
+      if(elems[elems.length - 1].equalsIgnoreCase(getResString(RB_EP_LISTE_ALLES))) {
         String type = elems[elems.length - 2];
         logger.fine(type);
         if(type.equalsIgnoreCase(ST_GERAET)) {
@@ -143,7 +162,7 @@
           Object o = gson.fromJson(bodyLesen(e), fs.typeFromName(type).getType());
           return gson.toJson(list);
         }
-      } else if(elems[elems.length - 1].equalsIgnoreCase(App.getRs(RB_EP_LISTE))) {
+      } else if(elems[elems.length - 1].equalsIgnoreCase(getResString(RB_EP_LISTE))) {
         String type = elems[elems.length - 2];
         logger.fine(type);
         list = fs.list(type);

--
Gitblit v1.9.3