Persoenliche Mediazentrale
ulrich
2021-04-04 cfa85894465dbf2d286e083d962babdf14641582
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"; 
c3b1d1 50
U 51   /**
52    * <p>Start-Methode dieser Anwendung</p>
53    *
54    * @param args Kommandozeilenparameter
55    */
56   public static void main(String[] args) {
2b6134 57     rb = ResourceBundle.getBundle(RB_NAME);
043915 58     logger.info(new File(".").getAbsolutePath());
U 59     
c3b1d1 60     initParams = new HashMap();
U 61     for (String arg : args) {
62       String[] argParts = arg.split("=");
63       initParams.put(argParts[0], argParts[1]);
64     }
65
2b6134 66     String portStr = getInitParameter(getRs(RB_AP_PORT));
c3b1d1 67     if (portStr != null) {
U 68       Server server = new Server(Integer.parseInt(portStr));
69       try {
2b6134 70         String ctxName = getInitParameter(getRs(RB_AP_CTX));
c3b1d1 71         if (ctxName != null) {
U 72           server.setContextName(ctxName);
73           server.start();
74         } else {
2b6134 75           logger.log(Level.INFO, getRs(RB_PARAM_FEHLT), getRs(RB_AP_CTX));
c3b1d1 76         }
2b6134 77         String conf = getInitParameter(getRs(RB_AP_CONF));
043915 78         if(conf != null) {
U 79           File confDir = new File(conf);
80           confDir.mkdirs();
81         } else {
2b6134 82           logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_CONF));
043915 83         }
c3b1d1 84       } catch (IOException ex) {
2b6134 85         logger.log(Level.SEVERE, null, ex);
c3b1d1 86       }
U 87     } else {
2b6134 88       logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_PORT));
c3b1d1 89     }
U 90   }
91
92   /**
93    * Diese Anwendung stoppen
94    */
95   public static void stop() {
96     System.exit(0);
97   }
98
99   /**
100    * Einen Kommandozeilenparameter ermitteln
101    *
102    * @param pname Names des Parameters
103    * @return Inhalt des Parameters oder null, wenn der Parameter nicht gefunden
104    * wurde
105    */
106   public static String getInitParameter(String pname) {
107     String param = null;
108     Object o = initParams.get(pname);
109     if (o != null) {
110       param = o.toString();
111     }
112     return param;
113   }
2b6134 114   
U 115   public static String getRs(String key) {
116     return rb.getString(key);
117   }
c3b1d1 118
U 119 }