Persoenliche Mediazentrale
ulrich
2021-04-08 dfb7d34f88efbb3eb7632ae628ccfd4576824477
commit | author | age
c3b1d1 1 /*
043915 2   Mediazentrale - Personal Media Center
U 3   Copyright (C) 2021  Ulrich Hilger
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  */
U 18 package de.uhilger.mediaz;
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 /**
28  *
29  * @author ulrich
30  */
31 public class App {
32
33   private static final Logger logger = Logger.getLogger(App.class.getName());
34
35   private static HashMap initParams;
2b6134 36   
U 37   /* ResourceBundle dieser App */
38   private static ResourceBundle rb;
39   
40   /* Name des ResourceBundles dieser App */
41   private static final String RB_NAME = "mediaz";
42   
43   /* ResourceBundle-Kennungen */
44   public static final String RB_PARAM_FEHLT = "msgParamFehlt";
45   public static final String RB_AP_PORT = "appParamPort";
46   public static final String RB_AP_CONF = "appParamConf";
47   public static final String RB_AP_WWW_DATA = "appParamWWWData"; 
48   public static final String RB_AP_CTX = "appParamCtx"; 
cfa858 49   public static final String RB_AP_UI = "appParamUi"; 
f45e20 50   public static final String RB_EP_LISTE = "epliste"; 
c3b1d1 51
U 52   /**
53    * <p>Start-Methode dieser Anwendung</p>
54    *
55    * @param args Kommandozeilenparameter
56    */
b379f5 57   public static void main(String[] args) throws ClassNotFoundException {
2b6134 58     rb = ResourceBundle.getBundle(RB_NAME);
b29119 59     logger.fine(new File(".").getAbsolutePath());
043915 60     
c3b1d1 61     initParams = new HashMap();
U 62     for (String arg : args) {
63       String[] argParts = arg.split("=");
64       initParams.put(argParts[0], argParts[1]);
65     }
66
2b6134 67     String portStr = getInitParameter(getRs(RB_AP_PORT));
c3b1d1 68     if (portStr != null) {
U 69       Server server = new Server(Integer.parseInt(portStr));
70       try {
2b6134 71         String ctxName = getInitParameter(getRs(RB_AP_CTX));
c3b1d1 72         if (ctxName != null) {
U 73           server.setContextName(ctxName);
74           server.start();
75         } else {
2b6134 76           logger.log(Level.INFO, getRs(RB_PARAM_FEHLT), getRs(RB_AP_CTX));
c3b1d1 77         }
2b6134 78         String conf = getInitParameter(getRs(RB_AP_CONF));
043915 79         if(conf != null) {
U 80           File confDir = new File(conf);
81           confDir.mkdirs();
82         } else {
2b6134 83           logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_CONF));
043915 84         }
c3b1d1 85       } catch (IOException ex) {
2b6134 86         logger.log(Level.SEVERE, null, ex);
c3b1d1 87       }
U 88     } else {
2b6134 89       logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_PORT));
c3b1d1 90     }
U 91   }
92
93   /**
94    * Diese Anwendung stoppen
95    */
96   public static void stop() {
97     System.exit(0);
98   }
99
100   /**
101    * Einen Kommandozeilenparameter ermitteln
102    *
103    * @param pname Names des Parameters
104    * @return Inhalt des Parameters oder null, wenn der Parameter nicht gefunden
105    * wurde
106    */
107   public static String getInitParameter(String pname) {
108     String param = null;
109     Object o = initParams.get(pname);
110     if (o != null) {
111       param = o.toString();
112     }
113     return param;
114   }
2b6134 115   
U 116   public static String getRs(String key) {
117     return rb.getString(key);
118   }
c3b1d1 119
U 120 }