Persoenliche Mediazentrale
ulrich
2022-01-10 8287036997695e731d68d380834cd63919a7a80e
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;
2b6134 23 import java.util.ResourceBundle;
c3b1d1 24 import java.util.logging.Level;
U 25 import java.util.logging.Logger;
26
27 /**
0e9cd3 28  * Die Hauptklasse der Mediazentrale mit der Methode <code>main</code>.
U 29  * 
f64984 30  * 
U 31  * args
32  * ctx=mz port=9090 conf=conf www-data=www
33  * 
34  * -Djava.util.logging.config.file=/pfad/zu/logging.properties
35  * 
0e9cd3 36  * @author Ulrich Hilger
U 37  * @version 1, 25.3.2021
c3b1d1 38  */
U 39 public class App {
40
41   private static final Logger logger = Logger.getLogger(App.class.getName());
42
2b6134 43   /* Name des ResourceBundles dieser App */
f70acb 44   public static final String RB_NAME = "tango";
0c14c0 45   
2b6134 46   /* ResourceBundle-Kennungen */
U 47   public static final String RB_PARAM_FEHLT = "msgParamFehlt";
48   public static final String RB_AP_PORT = "appParamPort";
49   public static final String RB_AP_CONF = "appParamConf";
50   public static final String RB_AP_WWW_DATA = "appParamWWWData"; 
51   public static final String RB_AP_CTX = "appParamCtx"; 
ad3e2d 52   
c3b1d1 53   /**
U 54    * <p>Start-Methode dieser Anwendung</p>
55    *
56    * @param args Kommandozeilenparameter
0e9cd3 57    * @throws java.lang.ClassNotFoundException
c3b1d1 58    */
b379f5 59   public static void main(String[] args) throws ClassNotFoundException {
f70acb 60     ResourceBundle rb = ResourceBundle.getBundle(RB_NAME);
b29119 61     logger.fine(new File(".").getAbsolutePath());
043915 62     
f70acb 63     HashMap<String,String> initParams = new HashMap();
c3b1d1 64     for (String arg : args) {
U 65       String[] argParts = arg.split("=");
66       initParams.put(argParts[0], argParts[1]);
67     }
68
f70acb 69     String portStr = initParams.get(rb.getString(RB_AP_PORT)); 
c3b1d1 70     if (portStr != null) {
0c14c0 71       //Server server = new Server(Integer.parseInt(portStr));
f70acb 72       Server server = new Server(Integer.parseInt(portStr));
c3b1d1 73       try {
f70acb 74         String ctxName = initParams.get(rb.getString(RB_AP_CTX));
c3b1d1 75         if (ctxName != null) {
U 76           server.setContextName(ctxName);
f70acb 77           server.start(initParams.get(rb.getString(RB_AP_WWW_DATA)), 
U 78                   initParams.get(rb.getString(RB_AP_CONF)));
c3b1d1 79         } else {
f70acb 80           logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CTX));
c3b1d1 81         }
f70acb 82         String conf = initParams.get(rb.getString(RB_AP_CONF));
043915 83         if(conf != null) {
U 84           File confDir = new File(conf);
85           confDir.mkdirs();
86         } else {
f70acb 87           logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_CONF));
043915 88         }
c3b1d1 89       } catch (IOException ex) {
2b6134 90         logger.log(Level.SEVERE, null, ex);
c3b1d1 91       }
U 92     } else {
f70acb 93       logger.log(Level.INFO, rb.getString(RB_PARAM_FEHLT), rb.getString(RB_AP_PORT));
c3b1d1 94     }
0c14c0 95   }
c3b1d1 96
U 97 }