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 |
|
|
43 |
private static HashMap initParams; |
2b6134
|
44 |
|
U |
45 |
/* ResourceBundle dieser App */ |
|
46 |
private static ResourceBundle rb; |
|
47 |
|
|
48 |
/* Name des ResourceBundles dieser App */ |
94b1c2
|
49 |
private static final String RB_NAME = "tango"; |
2b6134
|
50 |
|
0c14c0
|
51 |
/* Der Server dieser App */ |
U |
52 |
private static Server server; |
|
53 |
|
2b6134
|
54 |
/* ResourceBundle-Kennungen */ |
U |
55 |
public static final String RB_PARAM_FEHLT = "msgParamFehlt"; |
|
56 |
public static final String RB_AP_PORT = "appParamPort"; |
|
57 |
public static final String RB_AP_CONF = "appParamConf"; |
|
58 |
public static final String RB_AP_WWW_DATA = "appParamWWWData"; |
|
59 |
public static final String RB_AP_CTX = "appParamCtx"; |
cfa858
|
60 |
public static final String RB_AP_UI = "appParamUi"; |
f45e20
|
61 |
public static final String RB_EP_LISTE = "epliste"; |
a29f5c
|
62 |
public static final String RB_EP_LISTE_ALLES = "eplisteAlles"; |
0e9cd3
|
63 |
public static final String RB_AUDIOEXTS = "audioexts"; |
U |
64 |
public static final String RB_VIDEOEXTS = "videoexts"; |
|
65 |
public static final String RB_PLAYERPARAMS = "playerparams"; |
005d7a
|
66 |
public static final String RB_HOST = "host"; |
c3b1d1
|
67 |
|
U |
68 |
/** |
|
69 |
* <p>Start-Methode dieser Anwendung</p> |
|
70 |
* |
|
71 |
* @param args Kommandozeilenparameter |
0e9cd3
|
72 |
* @throws java.lang.ClassNotFoundException |
c3b1d1
|
73 |
*/ |
b379f5
|
74 |
public static void main(String[] args) throws ClassNotFoundException { |
2b6134
|
75 |
rb = ResourceBundle.getBundle(RB_NAME); |
b29119
|
76 |
logger.fine(new File(".").getAbsolutePath()); |
043915
|
77 |
|
c3b1d1
|
78 |
initParams = new HashMap(); |
U |
79 |
for (String arg : args) { |
|
80 |
String[] argParts = arg.split("="); |
|
81 |
initParams.put(argParts[0], argParts[1]); |
|
82 |
} |
|
83 |
|
2b6134
|
84 |
String portStr = getInitParameter(getRs(RB_AP_PORT)); |
c3b1d1
|
85 |
if (portStr != null) { |
0c14c0
|
86 |
//Server server = new Server(Integer.parseInt(portStr)); |
U |
87 |
server = new Server(Integer.parseInt(portStr)); |
c3b1d1
|
88 |
try { |
2b6134
|
89 |
String ctxName = getInitParameter(getRs(RB_AP_CTX)); |
c3b1d1
|
90 |
if (ctxName != null) { |
U |
91 |
server.setContextName(ctxName); |
|
92 |
server.start(); |
|
93 |
} else { |
2b6134
|
94 |
logger.log(Level.INFO, getRs(RB_PARAM_FEHLT), getRs(RB_AP_CTX)); |
c3b1d1
|
95 |
} |
2b6134
|
96 |
String conf = getInitParameter(getRs(RB_AP_CONF)); |
043915
|
97 |
if(conf != null) { |
U |
98 |
File confDir = new File(conf); |
|
99 |
confDir.mkdirs(); |
|
100 |
} else { |
2b6134
|
101 |
logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_CONF)); |
043915
|
102 |
} |
c3b1d1
|
103 |
} catch (IOException ex) { |
2b6134
|
104 |
logger.log(Level.SEVERE, null, ex); |
c3b1d1
|
105 |
} |
U |
106 |
} else { |
2b6134
|
107 |
logger.log(Level.INFO, App.getRs(RB_PARAM_FEHLT), getRs(RB_AP_PORT)); |
c3b1d1
|
108 |
} |
U |
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Diese Anwendung stoppen |
|
113 |
*/ |
|
114 |
public static void stop() { |
|
115 |
System.exit(0); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* Einen Kommandozeilenparameter ermitteln |
|
120 |
* |
|
121 |
* @param pname Names des Parameters |
|
122 |
* @return Inhalt des Parameters oder null, wenn der Parameter nicht gefunden |
|
123 |
* wurde |
|
124 |
*/ |
|
125 |
public static String getInitParameter(String pname) { |
|
126 |
String param = null; |
|
127 |
Object o = initParams.get(pname); |
|
128 |
if (o != null) { |
|
129 |
param = o.toString(); |
|
130 |
} |
|
131 |
return param; |
|
132 |
} |
2b6134
|
133 |
|
U |
134 |
public static String getRs(String key) { |
|
135 |
return rb.getString(key); |
|
136 |
} |
0c14c0
|
137 |
|
U |
138 |
public static Server getServer() { |
|
139 |
return server; |
|
140 |
} |
c3b1d1
|
141 |
|
U |
142 |
} |