commit | author | age
|
a01889
|
1 |
/* |
U |
2 |
Dateiverwaltung - File management in your browser |
|
3 |
Copyright (C) 2017 Ulrich Hilger, http://uhilger.de |
|
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 <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.wbx; |
|
20 |
|
5ebac8
|
21 |
import java.util.logging.Level; |
a01889
|
22 |
import java.util.logging.Logger; |
5ebac8
|
23 |
import javax.naming.Context; |
U |
24 |
import javax.naming.InitialContext; |
|
25 |
import javax.naming.NamingException; |
a01889
|
26 |
|
U |
27 |
/** |
|
28 |
* |
|
29 |
*/ |
|
30 |
public class WbxUtils { |
|
31 |
|
|
32 |
private static final Logger logger = Logger.getLogger(WbxUtils.class.getName()); |
|
33 |
|
5ebac8
|
34 |
public static final String JNDI_CTX_NAME = "java:comp/env"; |
U |
35 |
|
|
36 |
public static final String NOT_FOUND = " nicht gefunden"; |
|
37 |
public static final String NO_STRING = " ist kein String"; |
|
38 |
public static final String EMPTY_STRING = ""; |
|
39 |
|
|
40 |
public int getJNDIInt(String paramName, int defaultVal) { |
|
41 |
String jndiStr = getJNDIParameter(paramName, Integer.toString(defaultVal)); |
|
42 |
try { |
|
43 |
return Integer.parseInt(jndiStr); |
|
44 |
} catch(NumberFormatException ex) { |
|
45 |
logger.log(Level.FINE, ex.getMessage()); |
|
46 |
return defaultVal; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
public String getJNDIParameter(String pname, String defaultVal) { |
|
51 |
try { |
|
52 |
// unseren environment naming context ermitteln |
|
53 |
Context initCtx = new InitialContext(); |
|
54 |
Context envCtx = (Context) initCtx.lookup(JNDI_CTX_NAME); |
|
55 |
|
|
56 |
// unseren Parameter lesen |
|
57 |
Object o = envCtx.lookup(pname); |
|
58 |
if(o instanceof String) { |
|
59 |
return o.toString(); |
|
60 |
} else { |
|
61 |
return defaultVal; |
|
62 |
} |
|
63 |
} catch (NamingException ex) { |
|
64 |
logger.log(Level.FINE, ex.getMessage()); |
|
65 |
return defaultVal; |
|
66 |
} |
|
67 |
} |
a01889
|
68 |
} |