Persoenliche Mediazentrale
ulrich
2021-04-21 5c621434b008d1671accfc4b9c9c9016a256fd9f
src/de/uhilger/mediaz/store/FileStorage.java
@@ -19,10 +19,10 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import de.uhilger.mediaz.App;
import de.uhilger.mediaz.Server;
import de.uhilger.mediaz.entity.Ablageort;
import de.uhilger.mediaz.entity.Abspieler;
import de.uhilger.mediaz.entity.Abspielliste;
import de.uhilger.mediaz.entity.Einstellung;
import java.io.BufferedReader;
import java.io.File;
@@ -32,6 +32,9 @@
import java.io.IOException;
import java.util.logging.Logger;
import de.uhilger.mediaz.entity.Entity;
import de.uhilger.mediaz.entity.Geraet;
import de.uhilger.mediaz.entity.Livestream;
import de.uhilger.mediaz.entity.Titel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -57,6 +60,9 @@
  public static final String ST_ABLAGEORT = "Ablageort";
  public static final String ST_EINSTELLUNG = "Einstellung";
  public static final String ST_ABSPIELER = "Abspieler";
  public static final String ST_ABSPIELLISTE = "Abspielliste";
  public static final String ST_LIVESTREAM = "Livestream";
  public static final String ST_GERAET = "Geraet";
  
  private final String fileBase;
  
@@ -69,10 +75,18 @@
    TypeToken<Ablageort> ttAblageort = new TypeToken<Ablageort>() {};
    TypeToken<Einstellung> ttEinstellung = new TypeToken<Einstellung>() {};
    TypeToken<Abspieler> ttAbspieler = new TypeToken<Abspieler>() {};
    TypeToken<Abspielliste> ttAbspielliste = new TypeToken<Abspielliste>() {};
    TypeToken<Livestream> ttLivestream = new TypeToken<Livestream>() {};
    TypeToken<Geraet> ttGeraet = new TypeToken<Geraet>() {};
    TypeToken<Titel> ttTitel = new TypeToken<Titel>() {};
    types = new HashMap();
    types.put(Ablageort.class.getSimpleName(), ttAblageort);
    types.put(Einstellung.class.getSimpleName(), ttEinstellung);
    types.put(Abspieler.class.getSimpleName(), ttAbspieler);
    types.put(Abspielliste.class.getSimpleName(), ttAbspielliste);
    types.put(Titel.class.getSimpleName(), ttTitel);
    types.put(Livestream.class.getSimpleName(), ttLivestream);
    types.put(Geraet.class.getSimpleName(), ttGeraet);
  }
  
  /**
@@ -124,12 +138,13 @@
  
  public Entity entityFromFile(File file) throws ClassNotFoundException, FileNotFoundException, IOException {
    String json = readFromFile(file);
    logger.finer("json: " + json);
    Gson gson = new Gson();
    return gson.fromJson(json, typeFromName(typeNameFromPath(file)).getType());
  }
  
  private String typeNameFromPath(File file) {
    String[] parts = file.getPath().split(App.getRs(Server.RB_SLASH));
    String[] parts = file.getPath().split(Server.SLASH);
    return parts[parts.length-2];
  }
@@ -218,4 +233,8 @@
    return list;
  }
  
  public boolean exists(String typ, String name) {
    return getFile(typ, name).exists();
  }
}