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