1 package com.indexdata.mkjsf.config;
\r
3 import static com.indexdata.mkjsf.utils.Utils.nl;
\r
5 import java.util.ArrayList;
\r
6 import java.util.Enumeration;
\r
7 import java.util.HashMap;
\r
8 import java.util.List;
\r
9 import java.util.Map;
\r
11 import javax.enterprise.context.SessionScoped;
\r
12 import javax.enterprise.inject.Alternative;
\r
13 import javax.faces.context.ExternalContext;
\r
14 import javax.faces.context.FacesContext;
\r
15 import javax.inject.Named;
\r
16 import javax.servlet.ServletContext;
\r
18 import org.apache.log4j.Logger;
\r
20 import com.indexdata.mkjsf.errors.ConfigurationException;
\r
23 * Reads a configuration from the context parameters of the deployment descriptor (web.xml)
\r
25 * @author Niels Erik
\r
28 @Named @SessionScoped @Alternative
\r
29 public class WebXmlConfigReader implements ConfigurationReader {
\r
31 private static final long serialVersionUID = 144390224959311772L;
\r
32 private static Logger logger = Logger.getLogger(WebXmlConfigReader.class);
\r
33 private Configuration config = null;
\r
34 private Map<String,String> parameters = new HashMap<String,String>();
\r
36 public WebXmlConfigReader () {
\r
37 logger.info("Instantiating Pazpar2 service configuration by web.xml parameters");
\r
40 public Configuration getConfiguration(Configurable configurable) throws ConfigurationException {
\r
41 if (config == null) {
\r
42 parameters.putAll(configurable.getDefaults());
\r
43 parameters.putAll(readConfig());
\r
44 config = new Configuration(parameters);
\r
49 private Map<String,String> readConfig () throws ConfigurationException {
\r
50 Map<String,String> map = new HashMap<String,String>();
\r
51 ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
\r
52 ServletContext servletContext = (ServletContext) externalContext.getContext();
\r
53 Enumeration<String> enumer = servletContext.getInitParameterNames();
\r
54 while (enumer.hasMoreElements()) {
\r
55 String name = enumer.nextElement();
\r
56 map.put(name,servletContext.getInitParameter(name));
\r
61 public List<String> document() {
\r
62 List<String> doc = new ArrayList<String>();
\r
63 doc.add("Application properties as read by " + this.getClass());
\r
64 for (String key : parameters.keySet()) {
\r
65 doc.add(nl+key+": "+ parameters.get(key));
\r