package com.indexdata.pz2utils4jsf.config;\r
\r
-import java.io.IOException;\r
+import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
+\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+\r
\r
@Named @SessionScoped @Alternative\r
public class Pz2ConfigureByWebXml implements Pz2Configurator {\r
private static final long serialVersionUID = 144390224959311772L;\r
private static Logger logger = Logger.getLogger(Pz2ConfigureByWebXml.class);\r
private Pz2Config pz2config = null;\r
+ private Map<String,String> parameters = new HashMap<String,String>(); \r
\r
public Pz2ConfigureByWebXml () {\r
logger.info("Instantiating Pazpar2 service configuration by web.xml parameters");\r
}\r
\r
@Override\r
- public Pz2Config getConfig() throws IOException {\r
+ public Pz2Config getConfig() throws ConfigurationException {\r
if (pz2config == null) {\r
createConfig();\r
}\r
return pz2config;\r
}\r
\r
- private void createConfig () throws IOException {\r
+ private void createConfig () throws ConfigurationException {\r
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();\r
- ServletContext servletContext = (ServletContext) externalContext.getContext();\r
- Map<String,String> parameters = new HashMap<String,String>();\r
+ ServletContext servletContext = (ServletContext) externalContext.getContext(); \r
parameters.put("PAZPAR2_URL", servletContext.getInitParameter("PAZPAR2_URL"));\r
+ if (parameters.get("PAZPAR2_URL")==null || parameters.get("PAZPAR2_URL").length()==0) { \r
+ throw new ConfigurationException("Pz2ConfigureByWebXml could not find mandatory context-param 'PAZPAR2_URL'");\r
+ }\r
parameters.put("PAZPAR2_SERVICE_ID", servletContext.getInitParameter("PAZPAR2_SERVICE_ID"));\r
- pz2config = new Pz2Config(parameters); \r
+ if (parameters.get("PAZPAR2_SERVICE_ID")==null || parameters.get("PAZPAR2_SERVICE_ID").length()==0) { \r
+ throw new ConfigurationException("Pz2ConfigureByWebXml could not find mandatory context-param 'PAZPAR2_SERVICE_ID'");\r
+ }\r
+ pz2config = new Pz2Config(parameters);\r
}\r
\r
public List<String> document() {\r
- List<String> doc = new ArrayList<String>();\r
- doc.add("No documentation written yet for this configurator");\r
- return doc;\r
+ List<String> doc = new ArrayList<String>(); \r
+ doc.add("Attempted to configure service using web.xml context-parameters ");\r
+ doc.add(nl+"-- Configured to access Pazpar2 at [" +parameters.get("PAZPAR2_URL") + "]");\r
+ doc.add(nl+"-- Configured to use the server side service definition identified by service id [" +parameters.get("PAZPAR2_SERVICE_ID") + "]");\r
+ return doc; \r
}\r
}\r