Mercurial > dive4elements > gnv-client
comparison gnv/src/main/java/de/intevation/gnv/propertiesreader/ServletPropertiesReader.java @ 3:d7b4a77ba892
Infrastructur for Providing Applicationsettings
gnv/trunk@72 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 11 Sep 2009 15:19:52 +0000 |
parents | |
children | ad381cc47217 |
comparison
equal
deleted
inserted
replaced
2:5e94403971af | 3:d7b4a77ba892 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.propertiesreader; | |
5 | |
6 import java.util.Enumeration; | |
7 import java.util.HashMap; | |
8 import java.util.Map; | |
9 | |
10 import javax.servlet.ServletConfig; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 | |
14 /** | |
15 * @author Tim Englich <tim.englich@intevation.de> | |
16 * | |
17 */ | |
18 public class ServletPropertiesReader implements PropertiesReader { | |
19 | |
20 /** | |
21 * the logger, used to log exceptions and additonaly information | |
22 */ | |
23 private static Logger log = Logger.getLogger(ServletPropertiesReader.class); | |
24 | |
25 private Map<String,String> properties = null; | |
26 /** | |
27 * Constructor | |
28 */ | |
29 public ServletPropertiesReader(ServletConfig config) { | |
30 super(); | |
31 log.info("ServletPropertiesReader will be initialized"); | |
32 if (config != null){ | |
33 | |
34 Enumeration<String> keys = config.getInitParameterNames(); | |
35 properties = new HashMap<String, String>(); | |
36 while(keys.hasMoreElements()){ | |
37 String key = keys.nextElement(); | |
38 String value = config.getInitParameter(key); | |
39 log.info("New ConbfigurationValue; "+ key + " ==> "+ value); | |
40 this.properties.put(key, value); | |
41 } | |
42 } | |
43 } | |
44 | |
45 /** | |
46 * @see de.intevation.gnv.propertiesreader.PropertiesReader#getPropertieValue(java.lang.String, java.lang.String) | |
47 */ | |
48 public String getPropertieValue(String key, String defaultValue) { | |
49 String value = this.properties.get(key); | |
50 if (value == null){ | |
51 value = defaultValue; | |
52 } | |
53 return value; | |
54 } | |
55 | |
56 } |