/* Dateiverwaltung - File management in your browser Copyright (C) 2017 Ulrich Hilger, http://uhilger.de This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.uhilger.wbx; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; /** * */ public class WbxUtils { private static final Logger logger = Logger.getLogger(WbxUtils.class.getName()); public static final String JNDI_CTX_NAME = "java:comp/env"; public static final String NOT_FOUND = " nicht gefunden"; public static final String NO_STRING = " ist kein String"; public static final String EMPTY_STRING = ""; public int getJNDIInt(String paramName, int defaultVal) { String jndiStr = getJNDIParameter(paramName, Integer.toString(defaultVal)); try { return Integer.parseInt(jndiStr); } catch(NumberFormatException ex) { logger.log(Level.FINE, ex.getMessage()); return defaultVal; } } public String getJNDIParameter(String pname, String defaultVal) { try { // unseren environment naming context ermitteln Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(JNDI_CTX_NAME); // unseren Parameter lesen Object o = envCtx.lookup(pname); if(o instanceof String) { return o.toString(); } else { return defaultVal; } } catch (NamingException ex) { logger.log(Level.FINE, ex.getMessage()); return defaultVal; } } }