Persoenliche Mediazentrale
ulrich
2021-05-07 ad3e2db5eefd3093a066e7b61df0653abc9b6f2e
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"; 
ad3e2d 53   
c3b1d1 54   /**
U 55    * <p>Start-Methode dieser Anwendung</p>
56    *
57    * @param args Kommandozeilenparameter
0e9cd3 58    * @throws java.lang.ClassNotFoundException
c3b1d1 59    */
b379f5 60   public static void main(String[] args) throws ClassNotFoundException {
f70acb 61     ResourceBundle rb = ResourceBundle.getBundle(RB_NAME);
b29119 62     logger.fine(new File(".").getAbsolutePath());
043915 63     
f70acb 64     HashMap<String,String> initParams = new HashMap();
c3b1d1 65     for (String arg : args) {
U 66       String[] argParts = arg.split("=");
67       initParams.put(argParts[0], argParts[1]);
68     }
69
f70acb 70     String portStr = initParams.get(rb.getString(RB_AP_PORT)); 
c3b1d1 71     if (portStr != null) {
0c14c0 72       //Server server = new Server(Integer.parseInt(portStr));
f70acb 73       Server server = new Server(Integer.parseInt(portStr));
c3b1d1 74       try {
f70acb 75         String ctxName = initParams.get(rb.getString(RB_AP_CTX));
c3b1d1 76         if (ctxName != null) {
U 77           server.setContextName(ctxName);
f70acb 78           server.start(initParams.get(rb.getString(RB_AP_WWW_DATA)), 
U 79                   initParams.get(rb.getString(RB_AP_CONF)));
c3b1d1 80         } else {
f70acb 81           logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CTX));
c3b1d1 82         }
f70acb 83         String conf = initParams.get(rb.getString(RB_AP_CONF));
043915 84         if(conf != null) {
U 85           File confDir = new File(conf);
86           confDir.mkdirs();
87         } else {
f70acb 88           logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CONF));
043915 89         }
c3b1d1 90       } catch (IOException ex) {
2b6134 91         logger.log(Level.SEVERE, null, ex);
c3b1d1 92       }
U 93     } else {
f70acb 94       logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_PORT));
c3b1d1 95     }
0c14c0 96   }
c3b1d1 97
U 98 }