NIHVIVO-1261 Convert to use the new ConfigurationProperties class.

This commit is contained in:
jeb228 2011-02-25 16:50:09 +00:00
parent b7510fa355
commit 3fccf3fa04
11 changed files with 91 additions and 71 deletions

View file

@ -9,7 +9,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
/**
@ -41,14 +41,14 @@ public class SelfEditingConfiguration {
*/
public static SelfEditingConfiguration getBean(ServletRequest request) {
if (!(request instanceof HttpServletRequest)) {
log.trace("Not an HttpServletRequest: " + request);
return buildBean();
log.error("Not an HttpServletRequest: " + request);
return new SelfEditingConfiguration(null);
}
HttpSession session = ((HttpServletRequest) request).getSession(false);
if (session == null) {
log.trace("No session; no need to create one.");
return buildBean();
return new SelfEditingConfiguration(null);
}
Object attr = session.getAttribute(BEAN_ATTRIBUTE);
@ -57,14 +57,14 @@ public class SelfEditingConfiguration {
return (SelfEditingConfiguration) attr;
}
SelfEditingConfiguration bean = buildBean();
SelfEditingConfiguration bean = buildBean(session);
log.debug("Created a bean: " + bean);
session.setAttribute(BEAN_ATTRIBUTE, bean);
return bean;
}
private static SelfEditingConfiguration buildBean() {
String selfEditingIdMatchingProperty = ConfigurationProperties
private static SelfEditingConfiguration buildBean(HttpSession session) {
String selfEditingIdMatchingProperty = ConfigurationProperties.getBean(session)
.getProperty(PROPERTY_SELF_EDITING_ID_MATCHING_PROPERTY);
return new SelfEditingConfiguration(selfEditingIdMatchingProperty);
}

View file

@ -24,8 +24,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
public class ContactMailServlet extends VitroHttpServlet {
public static final String SMTPHOST_PROPERTY = "Vitro.smtpHost";
@ -44,12 +44,14 @@ public class ContactMailServlet extends VitroHttpServlet {
private static String smtpHost = null;
public static boolean isSmtpHostConfigured(HttpServletRequest req) {
return ConfigurationProperties.getProperty(SMTPHOST_PROPERTY, "").length() > 0;
return ConfigurationProperties.getBean(req)
.getProperty(SMTPHOST_PROPERTY, "").length() > 0;
}
@Override
public void init() {
smtpHost = ConfigurationProperties.getProperty(SMTPHOST_PROPERTY, "");
smtpHost = ConfigurationProperties.getBean(getServletContext())
.getProperty(SMTPHOST_PROPERTY, "");
if (smtpHost.isEmpty()) {
log.debug("No Vitro.smtpHost specified");
} else {
@ -203,6 +205,7 @@ public class ContactMailServlet extends VitroHttpServlet {
}
@Override
public void doPost( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{

View file

@ -35,12 +35,12 @@ import com.hp.hpl.jena.vocabulary.XSD;
import com.ibm.icu.util.Calendar;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
@ -93,7 +93,8 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
/**
* The get will present a form to the user.
*/
public void doGet( HttpServletRequest req, HttpServletResponse res )
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
try {
super.doGet(req, res);
@ -217,8 +218,9 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
}
}
@Override
public void doPost(HttpServletRequest rawRequest, HttpServletResponse res)
throws ServletException,IOException {
throws ServletException, IOException {
try{
FileUploadServletRequest req = FileUploadServletRequest.parseRequest(rawRequest, maxFileSize);
if (req.hasFileUploadException()) {
@ -547,13 +549,16 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
return success;
}
@Override
public void init() throws ServletException {
super.init();
baseDirectoryForFiles = ConfigurationProperties.getProperty(
ConfigurationProperties configProperties = ConfigurationProperties
.getBean(getServletContext());
baseDirectoryForFiles = configProperties.getProperty(
"n3.baseDirectoryForFiles", DEFAULT_BASE_DIR);
String maxSize = ConfigurationProperties.getProperty("n3.maxSize", Long
String maxSize = configProperties.getProperty("n3.maxSize", Long
.toString(DEFAULT_MAX_SIZE));
try {
maxFileSize = Integer.parseInt(maxSize);
@ -669,7 +674,7 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
public FdcException(String message) {
super(message);
}
};
}
private static final String RELOAD_MSG =
"<p>The fedora configuartion file will be reloaded if " +

View file

@ -23,8 +23,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
public class MailUsersServlet extends VitroHttpServlet {
@ -37,7 +37,8 @@ public class MailUsersServlet extends VitroHttpServlet {
@Override
public void init() {
smtpHost = ConfigurationProperties.getProperty(ContactMailServlet.SMTPHOST_PROPERTY, "");
smtpHost = ConfigurationProperties.getBean(getServletContext())
.getProperty(ContactMailServlet.SMTPHOST_PROPERTY, "");
if (smtpHost.isEmpty()) {
log.debug("No Vitro.smtpHost specified");
} else {
@ -226,6 +227,7 @@ public class MailUsersServlet extends VitroHttpServlet {
}
@Override
public void doPost( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{

View file

@ -13,7 +13,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
/**
* Capture the properties used by the External Authorization system, and use
@ -58,17 +58,17 @@ public class ExternalAuthHelper {
return DUMMY_HELPER;
}
ServletContext context = session.getServletContext();
ServletContext ctx = session.getServletContext();
Object attr = context.getAttribute(BEAN_ATTRIBUTE);
Object attr = ctx.getAttribute(BEAN_ATTRIBUTE);
if (attr instanceof ExternalAuthHelper) {
log.trace("Found a bean: " + attr);
return (ExternalAuthHelper) attr;
}
ExternalAuthHelper bean = buildBean();
ExternalAuthHelper bean = buildBean(ctx);
log.debug("Created a bean: " + bean);
setBean(context, bean);
setBean(ctx, bean);
return bean;
}
@ -78,10 +78,10 @@ public class ExternalAuthHelper {
context.setAttribute(BEAN_ATTRIBUTE, bean);
}
private static ExternalAuthHelper buildBean() {
String externalAuthServerUrl = ConfigurationProperties
private static ExternalAuthHelper buildBean(ServletContext ctx) {
String externalAuthServerUrl = ConfigurationProperties.getBean(ctx)
.getProperty(PROPERTY_EXTERNAL_AUTH_SERVER_URL);
String externalAuthHeaderName = ConfigurationProperties
String externalAuthHeaderName = ConfigurationProperties.getBean(ctx)
.getProperty(PROPERTY_EXTERNAL_AUTH_USERNAME_HEADER);
return new ExternalAuthHelper(externalAuthServerUrl,

View file

@ -33,7 +33,7 @@ import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
@ -86,22 +86,21 @@ public class N3MultiPartUpload extends VitroHttpServlet {
*/
@Override
public void init() throws ServletException {
super.init();
ConfigurationProperties configProperties = ConfigurationProperties
.getBean(getServletContext());
fileUriPrefix = ConfigurationProperties.getProperty("n3.defaultUriPrefix",
fileUriPrefix = configProperties.getProperty("n3.defaultUriPrefix",
DEFAULT_FILE_URI_PREFIX);
baseDirectoryForFiles = ConfigurationProperties.getProperty("n3.baseDirectoryForFiles",
DEFAULT_BASE_DIR);
baseDirectoryForFiles = configProperties.getProperty(
"n3.baseDirectoryForFiles", DEFAULT_BASE_DIR);
String postUploadProcess = ConfigurationProperties.getProperty("n3.postUploadProcess");
String postUploadProcess = configProperties.getProperty("n3.postUploadProcess");
System.out.println("Attempting to load postUploadProcess "
+ postUploadProcess);
postUpload = getPostUpload(postUploadProcess);
String maxSize = ConfigurationProperties.getProperty("n3.maxSize", Long
.toString(DEFAULT_MAX_SIZE));
//DEBUG ADDED
System.out.println("Max size is " + maxSize);
String maxSize = configProperties.getProperty("n3.maxSize", Long.toString(DEFAULT_MAX_SIZE));
log.debug("Max size is " + maxSize);
try {
maxFileSize = Integer.parseInt(maxSize);
} catch (NumberFormatException nfe) {

View file

@ -25,8 +25,8 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException;
@ -55,7 +55,8 @@ public class ContactMailController extends FreemarkerHttpServlet {
@Override
public void init() {
smtpHost = ConfigurationProperties.getProperty(ContactMailServlet.SMTPHOST_PROPERTY, "");
smtpHost = ConfigurationProperties.getBean(getServletContext())
.getProperty(ContactMailServlet.SMTPHOST_PROPERTY, "");
if (smtpHost.isEmpty()) {
log.debug("No Vitro.smtpHost specified");
} else {

View file

@ -13,8 +13,8 @@ import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.FileTemplateLoader;
@ -89,7 +89,7 @@ public class FreemarkerConfigurationLoader {
Configuration config = new Configuration();
String buildEnv = ConfigurationProperties.getProperty("Environment.build");
String buildEnv = ConfigurationProperties.getBean(context).getProperty("Environment.build");
log.debug("Current build environment: " + buildEnv);
if ("development".equals(buildEnv)) { // Set Environment.build = development in deploy.properties
log.debug("Disabling Freemarker template caching in development build.");

View file

@ -17,7 +17,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.auth.AuthorizationHelper;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
@ -25,6 +24,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPro
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.DropObjectPropStmt;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditObjPropStmt;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
@ -50,9 +50,6 @@ public class ImageUploadController extends FreemarkerHttpServlet {
private static final String ATTRIBUTE_REFERRING_PAGE = "ImageUploadController.referringPage";
private static final String DEFAULT_NAMESPACE = ConfigurationProperties
.getProperty("Vitro.defaultNamespace");
public static final String DUMMY_THUMBNAIL_PERSON_URL = "/images/placeholders/person.thumbnail.jpg";
public static final String DUMMY_THUMBNAIL_NON_PERSON_URL = "/images/placeholders/non.person.thumbnail.jpg";
@ -477,12 +474,13 @@ public class ImageUploadController extends FreemarkerHttpServlet {
return referrer;
}
if (DEFAULT_NAMESPACE == null) {
String defaultNamespace = getDefaultNamespace();
if (defaultNamespace == null) {
return "";
} else if (!entityUri.startsWith(DEFAULT_NAMESPACE)) {
} else if (!entityUri.startsWith(defaultNamespace)) {
return "";
} else {
String tail = entityUri.substring(DEFAULT_NAMESPACE.length());
String tail = entityUri.substring(defaultNamespace.length());
if (!tail.startsWith("/")) {
tail = "/" + tail;
}
@ -641,4 +639,10 @@ public class ImageUploadController extends FreemarkerHttpServlet {
return authorized;
}
private String getDefaultNamespace() {
return ConfigurationProperties.getBean(getServletContext())
.getProperty("Vitro.defaultNamespace");
}
}

View file

@ -30,7 +30,6 @@ import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
@ -39,6 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RdfResponseValues;
@ -56,7 +56,6 @@ import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualLocalNameMethod;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ListedIndividualTemplateModel;
import freemarker.ext.beans.BeansWrapper;
@ -549,7 +548,8 @@ public class IndividualController extends FreemarkerHttpServlet {
}
private boolean getTemporalVisualizationFlag() {
String property = ConfigurationProperties.getProperty("visualization.temporal");
String property = ConfigurationProperties.getBean(getServletContext())
.getProperty("visualization.temporal");
return "enabled".equals(property);
}
@ -620,6 +620,7 @@ public class IndividualController extends FreemarkerHttpServlet {
return null;
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException {
doGet(request, response);

View file

@ -5,6 +5,9 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -22,7 +25,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Exc
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupSDB;
public class SDBSetupController extends FreemarkerHttpServlet {
@ -59,7 +61,7 @@ public class SDBSetupController extends FreemarkerHttpServlet {
body.put("sdbstatus"," ");
}
else if(setupsignal!=null && setupsignal.equals("setup")){
new Thread(new SDBSetupRunner(jenaDataSourceSetupSDB)).start();
new Thread(new SDBSetupRunner(jenaDataSourceSetupSDB, vreq)).start();
messageStr = "SDB setup started.";
getServletContext().setAttribute("sdbsetup", "showButton");
}
@ -81,15 +83,18 @@ public class SDBSetupController extends FreemarkerHttpServlet {
private JenaDataSourceSetupSDB jenaDataSourceSetupSDB;
final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
private final ServletContext ctx;
public SDBSetupRunner(JenaDataSourceSetupSDB jenaDataSourceSetupSDB) {
public SDBSetupRunner(JenaDataSourceSetupSDB jenaDataSourceSetupSDB, HttpServletRequest req) {
this.jenaDataSourceSetupSDB = jenaDataSourceSetupSDB;
this.ctx = req.getSession().getServletContext();
}
@Override
public void run() {
Boolean done = true;
getServletContext().setAttribute("done",done);
StoreDesc storeDesc = jenaDataSourceSetupSDB.makeStoreDesc();
StoreDesc storeDesc = jenaDataSourceSetupSDB.makeStoreDesc(ctx);
BasicDataSource bds = jenaDataSourceSetupSDB.makeDataSourceFromConfigurationProperties(getServletContext());
Store store = null;
try {