| | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import de.uhilger.mediaz.App; |
| | | import de.uhilger.mediaz.Server; |
| | | import de.uhilger.mediaz.entity.Einstellung; |
| | | import de.uhilger.mediaz.entity.Entity; |
| | | import de.uhilger.mediaz.store.FileStorage; |
| | | import de.uhilger.mediaz.store.Storage; |
| | | import de.uhilger.mediaz.store.StorageFile; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | |
| | | /* Der Logger fuer diesen ListFileHandler */ |
| | | private static final Logger logger = Logger.getLogger(ListFileHandler.class.getName()); |
| | | |
| | | Map extMap = new HashMap(); |
| | | |
| | | public ListFileHandler(String absoluteDirectoryPathAndName) { |
| | | super(absoluteDirectoryPathAndName); |
| | | /* |
| | | Nachfolgend hart codiert die Ermittlung von Dateifiltern. |
| | | Sie werden erwartet in den Einstellungen 'audioexts' und 'videoexts' |
| | | jeweils als Dateierweiterungen mit Komma getrennt |
| | | z.B. "mp4,m4v" |
| | | */ |
| | | FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); |
| | | initMap(fs, "audioexts", StorageFile.TYP_AUDIO); |
| | | initMap(fs, "videoexts", StorageFile.TYP_VIDEO); |
| | | } |
| | | |
| | | private void initMap(Storage s, String key, String typ) { |
| | | Entity e = s.read(Einstellung.class.getSimpleName(), key); |
| | | if(e instanceof Einstellung) { |
| | | String[] exts = ((Einstellung) e).getValue().split(","); |
| | | for(String ext : exts) { |
| | | extMap.put(ext, typ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void handle(HttpExchange e) throws IOException { |
| | | String path = e.getRequestURI().toString(); |
| | |
| | | if(file.isDirectory()) { |
| | | sf.setTyp(StorageFile.TYP_FOLDER); |
| | | } else { |
| | | if(fname.endsWith(".mp3")) { |
| | | sf.setTyp(StorageFile.TYP_AUDIO); |
| | | } else if(fname.endsWith(".mp4") || fname.endsWith(".m4v")) { |
| | | sf.setTyp(StorageFile.TYP_VIDEO); |
| | | int pos = fname.lastIndexOf("."); |
| | | String ext = fname.substring(pos+1); |
| | | logger.log(Level.FINE, "ext: {0}", ext); |
| | | Object o = extMap.get(ext); |
| | | if(o instanceof String) { |
| | | sf.setTyp(o.toString()); |
| | | } else { |
| | | sf.setTyp(StorageFile.TYP_FILE); |
| | | } |