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