From 70e814d54221e41a48f9bb545da74994e246830f Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Mon, 4 Mar 2013 16:56:57 -0500 Subject: [PATCH] Adds another config option (by MasterKey config) --- .../config/Pz2ConfigureByMk2Config.java | 44 ++++++++++++++++++++ .../pz2utils4jsf/config/Pz2ConfigureByWebXml.java | 4 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java new file mode 100644 index 0000000..91cc08e --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java @@ -0,0 +1,44 @@ +package com.indexdata.pz2utils4jsf.config; + +import java.io.IOException; + +import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Alternative; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; + +import com.indexdata.masterkey.config.MasterkeyConfiguration; +import com.indexdata.masterkey.config.ModuleConfiguration; + +@Named @SessionScoped @Alternative +public class Pz2ConfigureByMk2Config implements Pz2Configurator { + + private static final long serialVersionUID = 8865086878660568870L; + private static Logger logger = Logger.getLogger(Pz2ConfigureByMk2Config.class); + private Pz2Config pz2config = null; + + public Pz2ConfigureByMk2Config () throws IOException { + logger.debug("Instantiating Pazpar2 service configuration by MasterKey configuration scheme."); + ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); + ServletContext servletContext = (ServletContext) externalContext.getContext(); + MasterkeyConfiguration mkConfigContext = + MasterkeyConfiguration.getInstance(servletContext, + "faces-component", ((HttpServletRequest) externalContext.getRequest()).getServerName()); + ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client"); + String pazpar2Url = moduleConfig.get("PAZPAR2_URL"); + String pazpar2ServiceId = moduleConfig.get("PAZPAR2_SERVICE_ID"); + pz2config = new Pz2Config(pazpar2Url,pazpar2ServiceId); + } + + @Override + public Pz2Config getConfig() { + return pz2config; + } + + +} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java index 92ea7d8..3c6223f 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java @@ -1,6 +1,7 @@ package com.indexdata.pz2utils4jsf.config; import javax.enterprise.context.SessionScoped; +import javax.enterprise.inject.Alternative; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.inject.Named; @@ -8,7 +9,8 @@ import javax.servlet.ServletContext; import org.apache.log4j.Logger; -@SessionScoped @Named + +@Named @SessionScoped @Alternative public class Pz2ConfigureByWebXml implements Pz2Configurator { private static final long serialVersionUID = 144390224959311772L; -- 1.7.10.4