ingo@1022: /* ingo@1022: * Copyright (c) 2010 by Intevation GmbH ingo@1022: * ingo@1022: * This program is free software under the LGPL (>=v2.1) ingo@1022: * Read the file LGPL.txt coming with the software for details ingo@1022: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1022: */ ingo@1022: tim@3: package de.intevation.gnv.propertiesreader; tim@3: tim@3: import java.util.Enumeration; tim@3: import java.util.HashMap; tim@3: import java.util.Map; tim@3: tim@3: import javax.servlet.ServletConfig; tim@3: tim@3: import org.apache.log4j.Logger; ingo@690: tim@3: /** tim@960: * This reader fetches the properties it will provide from the tim@960: * ServletConfig of an Context. tim@960: * It will read the InitParameters which could be configured using tim@960: * the web.xmlcontext. tim@960: * sascha@684: * @author Tim Englich sascha@681: * tim@3: */ tim@3: public class ServletPropertiesReader implements PropertiesReader { tim@3: tim@3: /** tim@3: * the logger, used to log exceptions and additonaly information tim@3: */ tim@3: private static Logger log = Logger.getLogger(ServletPropertiesReader.class); tim@3: tim@960: /** tim@960: * The properties which are read from the ServletConfig. tim@960: */ tim@36: private Map properties = null; tim@36: tim@3: /** tim@3: * Constructor tim@960: * tim@960: * @param config the ServletConfig where tim@960: * the properties should be read from. tim@3: */ tim@3: public ServletPropertiesReader(ServletConfig config) { tim@3: super(); tim@3: log.info("ServletPropertiesReader will be initialized"); tim@36: if (config != null) { tim@36: tim@3: Enumeration keys = config.getInitParameterNames(); tim@3: properties = new HashMap(); tim@36: while (keys.hasMoreElements()) { tim@3: String key = keys.nextElement(); tim@3: String value = config.getInitParameter(key); tim@36: log.info("New ConbfigurationValue; " + key + " ==> " + value); tim@3: this.properties.put(key, value); tim@3: } tim@3: } tim@3: } tim@3: ingo@690: tim@3: public String getPropertieValue(String key, String defaultValue) { tim@3: String value = this.properties.get(key); tim@36: if (value == null) { tim@3: value = defaultValue; tim@3: } tim@3: return value; tim@3: } tim@3: } sascha@700: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :