Persoenliche Mediazentrale
ulrich
2021-05-06 f70acbb491c6421623cca57292a75f1820efad4d
commit | author | age
c3b1d1 1 /*
94b1c2 2   Tango - Personal Media Center
043915 3   Copyright (C) 2021  Ulrich Hilger
U 4
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU Affero General Public License as
7   published by the Free Software Foundation, either version 3 of the
8   License, or (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU Affero General Public License for more details.
14
15   You should have received a copy of the GNU Affero General Public License
16   along with this program.  If not, see <https://www.gnu.org/licenses/>.
c3b1d1 17  */
94b1c2 18 package de.uhilger.tango;
c3b1d1 19
043915 20 import java.io.File;
c3b1d1 21 import java.io.IOException;
U 22 import java.util.HashMap;
f70acb 23 import java.util.Map;
2b6134 24 import java.util.ResourceBundle;
c3b1d1 25 import java.util.logging.Level;
U 26 import java.util.logging.Logger;
27
28 /**
0e9cd3 29  * Die Hauptklasse der Mediazentrale mit der Methode <code>main</code>.
U 30  * 
f64984 31  * 
U 32  * args
33  * ctx=mz port=9090 conf=conf www-data=www
34  * 
35  * -Djava.util.logging.config.file=/pfad/zu/logging.properties
36  * 
0e9cd3 37  * @author Ulrich Hilger
U 38  * @version 1, 25.3.2021
c3b1d1 39  */
U 40 public class App {
41
42   private static final Logger logger = Logger.getLogger(App.class.getName());
43
2b6134 44   /* Name des ResourceBundles dieser App */
f70acb 45   public static final String RB_NAME = "tango";
0c14c0 46   
2b6134 47   /* ResourceBundle-Kennungen */
U 48   public static final String RB_PARAM_FEHLT = "msgParamFehlt";
49   public static final String RB_AP_PORT = "appParamPort";
50   public static final String RB_AP_CONF = "appParamConf";
51   public static final String RB_AP_WWW_DATA = "appParamWWWData"; 
52   public static final String RB_AP_CTX = "appParamCtx"; 
cfa858 53   public static final String RB_AP_UI = "appParamUi"; 
f45e20 54   public static final String RB_EP_LISTE = "epliste"; 
a29f5c 55   public static final String RB_EP_LISTE_ALLES = "eplisteAlles"; 
0e9cd3 56   public static final String RB_AUDIOEXTS = "audioexts";
U 57   public static final String RB_VIDEOEXTS = "videoexts";
58   public static final String RB_PLAYERPARAMS = "playerparams";
005d7a 59   public static final String RB_HOST = "host";
c3b1d1 60
U 61   /**
62    * <p>Start-Methode dieser Anwendung</p>
63    *
64    * @param args Kommandozeilenparameter
0e9cd3 65    * @throws java.lang.ClassNotFoundException
c3b1d1 66    */
b379f5 67   public static void main(String[] args) throws ClassNotFoundException {
f70acb 68     ResourceBundle rb = ResourceBundle.getBundle(RB_NAME);
b29119 69     logger.fine(new File(".").getAbsolutePath());
043915 70     
f70acb 71     HashMap<String,String> initParams = new HashMap();
c3b1d1 72     for (String arg : args) {
U 73       String[] argParts = arg.split("=");
74       initParams.put(argParts[0], argParts[1]);
75     }
76
f70acb 77     String portStr = initParams.get(rb.getString(RB_AP_PORT)); 
c3b1d1 78     if (portStr != null) {
0c14c0 79       //Server server = new Server(Integer.parseInt(portStr));
f70acb 80       Server server = new Server(Integer.parseInt(portStr));
c3b1d1 81       try {
f70acb 82         String ctxName = initParams.get(rb.getString(RB_AP_CTX));
c3b1d1 83         if (ctxName != null) {
U 84           server.setContextName(ctxName);
f70acb 85           server.start(initParams.get(rb.getString(RB_AP_WWW_DATA)), 
U 86                   initParams.get(rb.getString(RB_AP_CONF)));
c3b1d1 87         } else {
f70acb 88           logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CTX));
c3b1d1 89         }
f70acb 90         String conf = initParams.get(rb.getString(RB_AP_CONF));
043915 91         if(conf != null) {
U 92           File confDir = new File(conf);
93           confDir.mkdirs();
94         } else {
f70acb 95           logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CONF));
043915 96         }
c3b1d1 97       } catch (IOException ex) {
2b6134 98         logger.log(Level.SEVERE, null, ex);
c3b1d1 99       }
U 100     } else {
f70acb 101       logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_PORT));
c3b1d1 102     }
0c14c0 103   }
c3b1d1 104
U 105 }