NIHVIVO-15 Merge three configuration properties files into one. Create ConfigProperties as a central mechanism for reading configuration properties.
This commit is contained in:
parent
863992f4ce
commit
a874f4b88a
21 changed files with 382 additions and 585 deletions
|
@ -161,9 +161,7 @@
|
||||||
|
|
||||||
<!-- copy properties files -->
|
<!-- copy properties files -->
|
||||||
<copy todir="${webapp.build}/WEB-INF/classes">
|
<copy todir="${webapp.build}/WEB-INF/classes">
|
||||||
<fileset dir="${webapp.dir}/config" includes="connection.properties" />
|
<fileset dir="${webapp.dir}/config" includes="deploy.properties" />
|
||||||
<fileset file="${webapp.dir}/config/upload.properties" />
|
|
||||||
<fileset file="${webapp.dir}/config/LuceneSetup.properties" />
|
|
||||||
</copy>
|
</copy>
|
||||||
|
|
||||||
<copy todir="${webapp.build}/WEB-INF/tlds">
|
<copy todir="${webapp.build}/WEB-INF/tlds">
|
||||||
|
@ -208,6 +206,9 @@
|
||||||
<exclude name="servlet-api.jar"/>
|
<exclude name="servlet-api.jar"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
|
|
||||||
|
<copy file="${webapp.dir}/context.xml"
|
||||||
|
tofile="${webapp.build}/META-INF/context.xml" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<!-- ==================== Local Modifications ============================ -->
|
<!-- ==================== Local Modifications ============================ -->
|
||||||
|
|
|
@ -19,10 +19,11 @@ log4j.appender.AllAppender.MaxBackupIndex=10
|
||||||
log4j.appender.AllAppender.layout=org.apache.log4j.PatternLayout
|
log4j.appender.AllAppender.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.AllAppender.layout.ConversionPattern=%p %t %c - %m%n
|
log4j.appender.AllAppender.layout.ConversionPattern=%p %t %c - %m%n
|
||||||
|
|
||||||
log4j.logger.org.apache.catalina=INFO, AllAppender
|
log4j.logger.org.apache.catalina=INFO
|
||||||
log4j.logger.org.diretwebremoting=ERROR, AllAppender
|
log4j.logger.org.diretwebremoting=ERROR
|
||||||
|
|
||||||
#log4j.logger.edu.cornell.mannlib.vitro.webapp.auth=INFO, AllAppender
|
log4j.logger.edu.cornell.mannlib.vitro.webapp.ConfigurationProperties=INFO
|
||||||
|
#log4j.logger.edu.cornell.mannlib.vitro.webapp.auth=INFO
|
||||||
|
|
||||||
#### setup a debugging logger
|
#### setup a debugging logger
|
||||||
log4j.appender.DebuggingAppender=org.apache.log4j.FileAppender
|
log4j.appender.DebuggingAppender=org.apache.log4j.FileAppender
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
#this is an example of what needs to be in this
|
|
||||||
#file to setup the lucene index directory
|
|
||||||
#
|
|
||||||
# The default location is /usr/local/lucene/vitrodefault
|
|
||||||
|
|
||||||
#You could hard code the location like this:
|
|
||||||
#LuceneSetup.indexDir=/usr/local/lucene/example
|
|
||||||
|
|
||||||
#this line will be setup by ant to work for clones
|
|
||||||
#if you hardcode the dir, this line should be commented out
|
|
||||||
LuceneSetup.indexDir=${luceneIndexDir}
|
|
|
@ -1,80 +0,0 @@
|
||||||
################################################################################
|
|
||||||
# DataSource properties file
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
######################### DataSource Properties ################################
|
|
||||||
|
|
||||||
VitroConnection.DataSource.url=jdbc:mysql://localhost/vitro
|
|
||||||
VitroConnection.DataSource.username=vitroweb
|
|
||||||
VitroConnection.DataSource.password=vitrovitro
|
|
||||||
|
|
||||||
####################### Other Important Properties #############################
|
|
||||||
|
|
||||||
# CHANGE the following property unless you're using Cornell's VIVO ontology
|
|
||||||
Vitro.defaultNamespace=http://vivo.library.cornell.edu/ns/0.1#
|
|
||||||
|
|
||||||
# Uncomment this next line and specify an SMTP host to activate the Contact Us form
|
|
||||||
#Vitro.smtpHost=
|
|
||||||
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# maximum number of connections to the db server
|
|
||||||
# This must not be greater than the mysql max_connection parameter.
|
|
||||||
# defaults to 40
|
|
||||||
#VitroConnection.DataSource.MaxActive=40
|
|
||||||
|
|
||||||
# maximum number of connections to the db server to keep
|
|
||||||
# around when nothing is happening.
|
|
||||||
# defaults to 10
|
|
||||||
#VitroConnection.DataSource.MaxIdle=10
|
|
||||||
|
|
||||||
# Time to wait in msec for a result from the sql server
|
|
||||||
# defaults to 10000
|
|
||||||
#VitroConnection.DataSource.MaxWait=10000
|
|
||||||
|
|
||||||
# query to use to test to see if a connection to the db server is live.
|
|
||||||
# defaults to SELECT 1
|
|
||||||
#VitroConnection.DataSource.ValidationQuery=SELECT 1
|
|
||||||
|
|
||||||
# should the connection pool test the connections it gets from the pool?
|
|
||||||
#defaults to true
|
|
||||||
#VitroConnection.DataSource.TestOnBorrow=true
|
|
||||||
|
|
||||||
# should the connection pool test connections it puts back in pool?
|
|
||||||
#defaults to true
|
|
||||||
#VitroConnection.DataSource.TestOnReturn=true
|
|
||||||
|
|
||||||
# Nnumber of milliseconds to sleep between runs of the idle object
|
|
||||||
# evictor thread. When non-positive, no idle object evictor thread will
|
|
||||||
# be run. defaults to 30min
|
|
||||||
#VitroConnection.DataSource.TimeBetweenEvictions=
|
|
||||||
|
|
||||||
# The number of objects to examine during each
|
|
||||||
# run of the idle object evictor thread (if any).
|
|
||||||
# defaults to 3
|
|
||||||
#VitroConnection.DataSource.TestsPerEviction=3
|
|
||||||
|
|
||||||
# The minimum amount of time
|
|
||||||
# an object may sit idle in the pool before it is eligable for eviction
|
|
||||||
# by the idle object evictor (if any).
|
|
||||||
# defaults to 30min
|
|
||||||
#VitroConnection.DataSource.MinEvictionIdleTime=
|
|
||||||
|
|
||||||
################################################ # other notes:
|
|
||||||
# The file checked into source control is example.connection.properties so
|
|
||||||
# that if you have a connection.properties on your machine it will not be
|
|
||||||
# under source control. This is useful so that your customizations for your
|
|
||||||
# database setup are less likely to be checked into source control and then
|
|
||||||
# overwrite other folks' customizations.
|
|
48
webapp/config/example.deploy.properties
Normal file
48
webapp/config/example.deploy.properties
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# VIVO deployment properties
|
||||||
|
#
|
||||||
|
# This file is provided as example.deploy.properties.
|
||||||
|
#
|
||||||
|
# Save a copy of this file as deploy.properties, and edit the properties as
|
||||||
|
# needed for your deployment.
|
||||||
|
#
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#
|
||||||
|
# The location where the VIVO application will store uploaded files
|
||||||
|
# (usually images). You should arrange for these files to be backed up in some
|
||||||
|
# way.
|
||||||
|
#
|
||||||
|
UploadImagesServlet.sourceDirName = /usr/local/vivo/data/uploads
|
||||||
|
|
||||||
|
#
|
||||||
|
# The location where the VIVO application will create its Lucene search
|
||||||
|
# index.
|
||||||
|
#
|
||||||
|
LuceneSetup.indexDir = /usr/local/vivo/data/luceneIndex
|
||||||
|
|
||||||
|
#
|
||||||
|
# This namespace will be used when generating URIs for objects created in the
|
||||||
|
# editor. Change it to reflect your own domain. For example, Cornell's
|
||||||
|
# namespace is http://vivo.cornell.edu/individual/
|
||||||
|
#
|
||||||
|
# Note: it is essential that this namespace end with a trailing slash.
|
||||||
|
#
|
||||||
|
Vitro.defaultNamespace = http://vitro.mydomain.edu/individual/
|
||||||
|
|
||||||
|
#
|
||||||
|
# SMTP host which the "Contact Us" form can use to send mail. If this is left
|
||||||
|
# empty, the "Contact Us" form will be disabled.
|
||||||
|
#
|
||||||
|
#Vitro.smtpHost =
|
||||||
|
|
||||||
|
#
|
||||||
|
# The basic parameters for a MySQL database connection. Change the end of the
|
||||||
|
# URL to reflect your database name (if it is not "vitro"). Change the username
|
||||||
|
# and password to match the authorized user you created in MySQL.
|
||||||
|
#
|
||||||
|
VitroConnection.DataSource.url = jdbc:mysql://localhost/vitro
|
||||||
|
VitroConnection.DataSource.username = vitroweb
|
||||||
|
VitroConnection.DataSource.password = vitrovitro
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
# The UploadImagesServlet will upload the images to a directory
|
|
||||||
# that is under tomcat and serve them from there.
|
|
||||||
# This causes a problem when the tomcat/webapps dir is deleted
|
|
||||||
# or deployed because you will lose all the images that the
|
|
||||||
# curators have uploaded. We deal with this by copying
|
|
||||||
# the files to another directory, one that is under version control.
|
|
||||||
|
|
||||||
# This property indicates which non-tomcat directory to save the images in.
|
|
||||||
# ${uploadDir} is defined in the main build.xml via the following statements:
|
|
||||||
#
|
|
||||||
# <!-- defined in globalbuild.properties -->
|
|
||||||
# <property name="source.dir" value="{source.home}"/>
|
|
||||||
# <property name="uploadDir" value="{source.dir}/webapp/web" />
|
|
||||||
#
|
|
||||||
# But, this value will be replaced by the Vitro/clones/build.xml
|
|
||||||
# to point to the clones/{clone}/modifications directory based on the following
|
|
||||||
# <property file="./config/globalbuild.properties"/>
|
|
||||||
# <property name="source.dir" value="{source.home}"/>
|
|
||||||
# <property name="uploadDir" value="${source.dir}/clones/${clone}/modifications"/>
|
|
||||||
#
|
|
||||||
# The UploadImagesServlet.getSourceDirName() method then looks at this parameter
|
|
||||||
# in the upload.properties file, which file is stuck by the clones/build.xml file
|
|
||||||
# into the clone's modifications/WEB-INF/classes directory:
|
|
||||||
UploadImagesServlet.sourceDirName=${uploadDir}
|
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
<env-entry>
|
<env-entry>
|
||||||
<env-entry-name>jdbc/vitro/connectionType</env-entry-name>
|
<env-entry-name>jdbc/vitro/connectionType</env-entry-name>
|
||||||
<!--
|
<!--
|
||||||
How to get a DataSource, Valid valies:
|
How to get a DataSource, Valid values:
|
||||||
SERVER_XML_POOL gets a named DataSource connection from the
|
SERVER_XML_POOL gets a named DataSource connection from the JNDI context,
|
||||||
JNDI context, most likely that was set up tomcat/conf/server.xml
|
most likely that was set up tomcat/conf/server.xml
|
||||||
PROPERTIES_FILE_POOL makes a DataSource using properties from
|
PROPERTIES_FILE_POOL makes a DataSource using properties from a file that
|
||||||
a file in the classpath at /beans/connection.properties
|
is pointed to by the JNDI name "java:comp/env/path.configuration"
|
||||||
|
(set in the Tomcat context).
|
||||||
-->
|
-->
|
||||||
<!-- <env-entry-value>SERVER_XML_POOL</env-entry-value> -->
|
<!-- <env-entry-value>SERVER_XML_POOL</env-entry-value> -->
|
||||||
<env-entry-type>java.lang.String</env-entry-type>
|
<env-entry-type>java.lang.String</env-entry-type>
|
||||||
|
|
14
webapp/context.xml
Normal file
14
webapp/context.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<Context override="true">
|
||||||
|
<!--
|
||||||
|
Vitro will interpret this as either a file path or a resource path. So,
|
||||||
|
if a simple resource path is used, such as "deploy.properties", Vitro
|
||||||
|
will find the file at:
|
||||||
|
${Tomcat}/webapps/vitro/WEB-INF/classes/deploy.properties
|
||||||
|
For an external file, specify a full file path, like
|
||||||
|
"/usr/local/vitro/deploy.properties".
|
||||||
|
-->
|
||||||
|
<Environment type="java.lang.String" override="false"
|
||||||
|
name="path.configuration"
|
||||||
|
value="deploy.properties"
|
||||||
|
/>
|
||||||
|
</Context>
|
|
@ -0,0 +1,144 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the configuration properties from a properties file. The path to the
|
||||||
|
* file is specified an an Environment name in the Context, like this:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <Context override="true">
|
||||||
|
* <Environment name="path.configuration"
|
||||||
|
* value="/wherever/the/file/lives/deploy.properties"
|
||||||
|
* type="java.lang.String"
|
||||||
|
* override="false" />
|
||||||
|
* </Context>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* This initializer will look for a file at this path. If it does not find one,
|
||||||
|
* it will look for a resource at this path. So, one might reasonable set this
|
||||||
|
* to a value like <code>/usr/local/vitro/stuff/deploy.properties</code> for a
|
||||||
|
* file, or like <code>deploy.properties</code> for a resource in the classpath.
|
||||||
|
*
|
||||||
|
* @author jeb228
|
||||||
|
*/
|
||||||
|
public class ConfigurationProperties {
|
||||||
|
private static final Logger LOG = Logger
|
||||||
|
.getLogger(ConfigurationProperties.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the JNDI environment mapping for the path to the
|
||||||
|
* configuration file (or resource).
|
||||||
|
*/
|
||||||
|
private static final String PATH_CONFIGURATION = "path.configuration";
|
||||||
|
private static volatile Map<String, String> theMap;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
// Obtain our environment naming context
|
||||||
|
Context initCtx = new InitialContext();
|
||||||
|
Context envCtx = (Context) initCtx.lookup("java:comp/env");
|
||||||
|
|
||||||
|
// Get the name of the configuration properties file.
|
||||||
|
String configPath = (String) envCtx.lookup(PATH_CONFIGURATION);
|
||||||
|
if (configPath == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Could not find a JNDI Environment naming for '"
|
||||||
|
+ PATH_CONFIGURATION + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream inStream = null;
|
||||||
|
// Try to find this as a file.
|
||||||
|
File file = new File(configPath);
|
||||||
|
try {
|
||||||
|
inStream = new FileInputStream(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
inStream = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no file, try to find it as a resource.
|
||||||
|
if (inStream == null) {
|
||||||
|
inStream = ConfigurationProperties.class.getClassLoader()
|
||||||
|
.getResourceAsStream(configPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If neither file nor resource, give up.
|
||||||
|
if (inStream == null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Failed to find a configuration properties file at '"
|
||||||
|
+ file.getAbsolutePath()
|
||||||
|
+ "', or a resource at '" + configPath + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load a properties object - it will handle the syntax of the file.
|
||||||
|
Properties props = new Properties();
|
||||||
|
try {
|
||||||
|
props.load(inStream);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Problem while reading the "
|
||||||
|
+ "configuration properties file at '" + configPath
|
||||||
|
+ "'", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// It's awkward to copy from Properties to a Map.
|
||||||
|
Map<String, String> newMap = new HashMap<String, String>();
|
||||||
|
for (Enumeration<?> keys = props.keys(); keys.hasMoreElements();) {
|
||||||
|
String key = (String) keys.nextElement();
|
||||||
|
newMap.put(key, props.getProperty(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Configuration properties are: " + newMap);
|
||||||
|
|
||||||
|
// Save an unmodifiable version of the Map
|
||||||
|
theMap = Collections.unmodifiableMap(newMap);
|
||||||
|
} catch (NamingException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an unmodifiable copy of the map of configuration properties.
|
||||||
|
*/
|
||||||
|
public static Map<String, String> getMap() {
|
||||||
|
return theMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the specified property, or <code>null</code> if the
|
||||||
|
* property has not been assigned a value.
|
||||||
|
*/
|
||||||
|
public static String getProperty(String key) {
|
||||||
|
return theMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of the specified property, or use the default value if the
|
||||||
|
* property has not been assigned a value.
|
||||||
|
*/
|
||||||
|
public static String getProperty(String key, String defaultValue) {
|
||||||
|
String value = theMap.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return defaultValue;
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,8 @@ public class CommentsController extends VitroHttpServlet{
|
||||||
if (!ContactMailServlet.isSmtpHostConfigured()) {
|
if (!ContactMailServlet.isSmtpHostConfigured()) {
|
||||||
request.setAttribute("title", "Comments and Feedback Form");
|
request.setAttribute("title", "Comments and Feedback Form");
|
||||||
request.setAttribute("bodyJsp", "/contact_err.jsp");// <<< this is where the body gets set
|
request.setAttribute("bodyJsp", "/contact_err.jsp");// <<< this is where the body gets set
|
||||||
request.setAttribute("ERR","This application has not yet been configured to send mail -- smtp host has not been specified in connection.properties");
|
request.setAttribute("ERR","This application has not yet been configured to send mail -- " +
|
||||||
|
"smtp host has not been specified in the configuration properties file.");
|
||||||
RequestDispatcher errd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
RequestDispatcher errd = request.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||||
errd.forward(request, response);
|
errd.forward(request, response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,8 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -22,31 +18,29 @@ import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy.ContextSetup;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.BrowseController.RebuildGroupCacheThread;
|
|
||||||
|
|
||||||
public class ContactMailServlet extends VitroHttpServlet {
|
public class ContactMailServlet extends VitroHttpServlet {
|
||||||
|
private static final Logger LOG = Logger.getLogger(ContactMailServlet.class);
|
||||||
|
|
||||||
public static HttpServletRequest request;
|
public static HttpServletRequest request;
|
||||||
public static HttpServletRequest response;
|
public static HttpServletRequest response;
|
||||||
protected final static String CONNECTION_PROP_LOCATION = "/WEB-INF/classes/connection.properties";
|
|
||||||
private static String smtpHost = null;
|
private static String smtpHost = null;
|
||||||
private static final Log log = LogFactory.getLog(ContactMailServlet.class.getName());
|
private static final Log log = LogFactory.getLog(ContactMailServlet.class.getName());
|
||||||
|
|
||||||
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
|
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
|
||||||
super.init(servletConfig);
|
super.init(servletConfig);
|
||||||
ServletContext sContext = servletConfig.getServletContext();
|
smtpHost = getSmtpHostFromProperties();
|
||||||
smtpHost = getSmtpHostFromPropertiesFile(sContext.getRealPath(CONNECTION_PROP_LOCATION));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSmtpHostConfigured() {
|
public static boolean isSmtpHostConfigured() {
|
||||||
|
@ -56,42 +50,14 @@ public class ContactMailServlet extends VitroHttpServlet {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSmtpHostFromPropertiesFile(final String filename){
|
private String getSmtpHostFromProperties() {
|
||||||
|
String host = ConfigurationProperties.getProperty("Vitro.smtpHost");
|
||||||
if (filename == null || filename.length() <= 0) {
|
if (host != null && !host.equals("")) {
|
||||||
throw new Error(
|
LOG.info("Found Vitro.smtpHost value of " + host);
|
||||||
"To establish the Contact Us mail capability you must "
|
} else {
|
||||||
+ "specify an SMTP server host name in the "
|
System.out.println("No Vitro.smtpHost specified");
|
||||||
+ "connection.properties file along with the "
|
|
||||||
+ "database connection parameters.");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
File propF = new File(filename );
|
|
||||||
InputStream is;
|
|
||||||
try {
|
|
||||||
is = new FileInputStream(propF);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
log.error("Could not load file "+filename);
|
|
||||||
throw new Error("Could not load file " + filename
|
|
||||||
+ '\n' + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties dbProps = new Properties();
|
|
||||||
try {
|
|
||||||
dbProps.load(is);
|
|
||||||
String host = dbProps.getProperty("Vitro.smtpHost");
|
|
||||||
/* doesn't display in catalina.out, not sure why
|
|
||||||
if (host!=null && !host.equals("")){
|
|
||||||
System.out.println("Found Vitro.smtpHost value of "+host+" in "+filename);
|
|
||||||
} else {
|
|
||||||
System.out.println("No Vitro.smtpHost specified in "+filename);
|
|
||||||
} */
|
|
||||||
return (host != null && host.length()>0) ? host : null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new Error("Could not load any properties from file " + filename + '\n'
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
return (host != null && host.length() > 0) ? host : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||||
|
@ -104,7 +70,8 @@ if (host!=null && !host.equals("")){
|
||||||
String status = null; // holds the error status
|
String status = null; // holds the error status
|
||||||
|
|
||||||
if (smtpHost==null || smtpHost.equals("")){
|
if (smtpHost==null || smtpHost.equals("")){
|
||||||
status = "This application has not yet been configured to send mail -- smtp host has not been identified in connection.properties";
|
status = "This application has not yet been configured to send mail " +
|
||||||
|
"-- smtp host has not been identified in the Configuration Properties file.";
|
||||||
response.sendRedirect( "test?bodyJsp=" + errpage + "&ERR=" + status + "&home=" + portal.getPortalId() );
|
response.sendRedirect( "test?bodyJsp=" + errpage + "&ERR=" + status + "&home=" + portal.getPortalId() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.controller;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
@ -31,12 +30,11 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.edit.N3MultiPartUpload;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.edit.N3MultiPartUpload.PostUpload;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
@ -54,7 +52,6 @@ import fedora.server.types.gen.Datastream;
|
||||||
*/
|
*/
|
||||||
public class FedoraDatastreamController extends VitroHttpServlet implements Constants{
|
public class FedoraDatastreamController extends VitroHttpServlet implements Constants{
|
||||||
private static String FEDORA_PROPERTIES = "/WEB-INF/fedora.properties";
|
private static String FEDORA_PROPERTIES = "/WEB-INF/fedora.properties";
|
||||||
private static String FEDORA_FOXML_1_1 = "info:fedora/fedora-system:FOXML-1.1";
|
|
||||||
private static String DEFAULT_DSID = "DS1";
|
private static String DEFAULT_DSID = "DS1";
|
||||||
|
|
||||||
private String fedoraUrl = null;
|
private String fedoraUrl = null;
|
||||||
|
@ -71,7 +68,6 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
private static String fileUriPrefix = DEFAULT_FILE_URI_PREFIX;
|
private static String fileUriPrefix = DEFAULT_FILE_URI_PREFIX;
|
||||||
private static String baseDirectoryForFiles = DEFAULT_BASE_DIR;
|
private static String baseDirectoryForFiles = DEFAULT_BASE_DIR;
|
||||||
private static int maxFileSize = DEFAULT_MAX_SIZE;
|
private static int maxFileSize = DEFAULT_MAX_SIZE;
|
||||||
private static PostUpload postUpload = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The get will present a form to the user.
|
* The get will present a form to the user.
|
||||||
|
@ -396,44 +392,13 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
|
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
String realPropFile = getServletContext().getRealPath(
|
|
||||||
N3MultiPartUpload.FILE_UPLOAD_PROP_FILE);
|
|
||||||
File propF = new File(realPropFile);
|
|
||||||
if (propF != null && propF.exists() && propF.isFile()) {
|
|
||||||
if (!propF.canRead()) {
|
|
||||||
log.error("There is a file upload configuration file at "
|
|
||||||
+ realPropFile + " but is is not readable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream is;
|
fileUriPrefix = ConfigurationProperties.getProperty(
|
||||||
try {
|
"n3.defaultUriPrefix", DEFAULT_FILE_URI_PREFIX);
|
||||||
is = new FileInputStream(propF);
|
baseDirectoryForFiles = ConfigurationProperties.getProperty(
|
||||||
} catch (FileNotFoundException e) {
|
"n3.baseDirectoryForFiles", DEFAULT_BASE_DIR);
|
||||||
log.error("Could not load file " + realPropFile, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
String maxSize = ConfigurationProperties.getProperty("n3.maxSize", Long
|
||||||
try {
|
|
||||||
props.load(is);
|
|
||||||
is.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(
|
|
||||||
"could not load properties from file " + realPropFile,
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
fileUriPrefix = props.getProperty("defaultUriPrefix",
|
|
||||||
DEFAULT_FILE_URI_PREFIX);
|
|
||||||
baseDirectoryForFiles = props.getProperty("baseDirectoryForFiles",
|
|
||||||
DEFAULT_BASE_DIR);
|
|
||||||
|
|
||||||
// String postUploadProcess = props.getProperty("postUploadProcess");
|
|
||||||
// System.out.println("Attempting to load postUploadProcess "
|
|
||||||
// + postUploadProcess);
|
|
||||||
// postUpload = getPostUpload(postUploadProcess);
|
|
||||||
|
|
||||||
String maxSize = props.getProperty("maxSize", Long
|
|
||||||
.toString(DEFAULT_MAX_SIZE));
|
.toString(DEFAULT_MAX_SIZE));
|
||||||
try {
|
try {
|
||||||
maxFileSize = Integer.parseInt(maxSize);
|
maxFileSize = Integer.parseInt(maxSize);
|
||||||
|
@ -441,11 +406,6 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
|
||||||
log.error(nfe);
|
log.error(nfe);
|
||||||
maxFileSize = DEFAULT_MAX_SIZE;
|
maxFileSize = DEFAULT_MAX_SIZE;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
System.out
|
|
||||||
.println("No properties file found for N3MultiPartUpload at "
|
|
||||||
+ realPropFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup(OntModel model, ServletContext context) {
|
private void setup(OntModel model, ServletContext context) {
|
||||||
|
|
|
@ -9,8 +9,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,7 +43,7 @@ import com.hp.hpl.jena.shared.Lock;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.FedoraDatastreamController;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
|
@ -96,44 +94,18 @@ public class N3MultiPartUpload extends VitroHttpServlet {
|
||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException {
|
public void init() throws ServletException {
|
||||||
super.init();
|
super.init();
|
||||||
String realPropFile = getServletContext().getRealPath(
|
|
||||||
FILE_UPLOAD_PROP_FILE);
|
|
||||||
File propF = new File(realPropFile);
|
|
||||||
if (propF != null && propF.exists() && propF.isFile()) {
|
|
||||||
if (!propF.canRead()) {
|
|
||||||
log.error("There is a file upload configuration file at "
|
|
||||||
+ realPropFile + " but is is not readable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream is;
|
fileUriPrefix = ConfigurationProperties.getProperty("n3.defaultUriPrefix",
|
||||||
try {
|
|
||||||
is = new FileInputStream(propF);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
log.error("Could not load file " + realPropFile, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
|
||||||
try {
|
|
||||||
props.load(is);
|
|
||||||
is.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(
|
|
||||||
"could not load properties from file " + realPropFile,
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
fileUriPrefix = props.getProperty("defaultUriPrefix",
|
|
||||||
DEFAULT_FILE_URI_PREFIX);
|
DEFAULT_FILE_URI_PREFIX);
|
||||||
baseDirectoryForFiles = props.getProperty("baseDirectoryForFiles",
|
baseDirectoryForFiles = ConfigurationProperties.getProperty("n3.baseDirectoryForFiles",
|
||||||
DEFAULT_BASE_DIR);
|
DEFAULT_BASE_DIR);
|
||||||
|
|
||||||
String postUploadProcess = props.getProperty("postUploadProcess");
|
String postUploadProcess = ConfigurationProperties.getProperty("n3.postUploadProcess");
|
||||||
System.out.println("Attempting to load postUploadProcess "
|
System.out.println("Attempting to load postUploadProcess "
|
||||||
+ postUploadProcess);
|
+ postUploadProcess);
|
||||||
postUpload = getPostUpload(postUploadProcess);
|
postUpload = getPostUpload(postUploadProcess);
|
||||||
|
|
||||||
String maxSize = props.getProperty("maxSize", Long
|
String maxSize = ConfigurationProperties.getProperty("n3.maxSize", Long
|
||||||
.toString(DEFAULT_MAX_SIZE));
|
.toString(DEFAULT_MAX_SIZE));
|
||||||
try {
|
try {
|
||||||
maxFileSize = Integer.parseInt(maxSize);
|
maxFileSize = Integer.parseInt(maxSize);
|
||||||
|
@ -141,11 +113,6 @@ public class N3MultiPartUpload extends VitroHttpServlet {
|
||||||
log.error(nfe);
|
log.error(nfe);
|
||||||
maxFileSize = DEFAULT_MAX_SIZE;
|
maxFileSize = DEFAULT_MAX_SIZE;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
System.out
|
|
||||||
.println("No properties file found for N3MultiPartUpload at "
|
|
||||||
+ realPropFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -624,8 +591,6 @@ public class N3MultiPartUpload extends VitroHttpServlet {
|
||||||
|
|
||||||
static Random random = new Random();
|
static Random random = new Random();
|
||||||
|
|
||||||
public static final String FILE_UPLOAD_PROP_FILE = "/WEB-INF/N3MultiPartUpload.properties";
|
|
||||||
|
|
||||||
private static Property FILE_LOCATION_PROP = ResourceFactory
|
private static Property FILE_LOCATION_PROP = ResourceFactory
|
||||||
.createProperty(VitroVocabulary.FILE_LOCATION);
|
.createProperty(VitroVocabulary.FILE_LOCATION);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
@ -42,10 +43,6 @@ public class UploadImagesServlet extends VitroHttpServlet {
|
||||||
private static final Log log = LogFactory.getLog(UploadImagesServlet.class.getName());
|
private static final Log log = LogFactory.getLog(UploadImagesServlet.class.getName());
|
||||||
private String sourceDirName; // all uploaded images are copied to the source directory, not just the application context
|
private String sourceDirName; // all uploaded images are copied to the source directory, not just the application context
|
||||||
private String websiteDirName; // the application context
|
private String websiteDirName; // the application context
|
||||||
private String webAppName; // the name of the application context (e.g., vivo, usaep)
|
|
||||||
|
|
||||||
private static String UPLOAD_SERVLET_PROPERTIES = "/upload.properties";
|
|
||||||
private static String UPLOAD_SERVLET_PROPERTIES_WIN="\\upload.properties";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notice that init() gets called the first time the servlet is requested,
|
* Notice that init() gets called the first time the servlet is requested,
|
||||||
|
@ -57,15 +54,6 @@ public class UploadImagesServlet extends VitroHttpServlet {
|
||||||
// something like: /usr/local/tomcat/webapps/vivo
|
// something like: /usr/local/tomcat/webapps/vivo
|
||||||
websiteDirName = getServletContext().getRealPath("");
|
websiteDirName = getServletContext().getRealPath("");
|
||||||
|
|
||||||
//get the last directory, which should be the webapp name.
|
|
||||||
String[] dirs = new String[0];
|
|
||||||
if (File.separator.equals("\\")) {
|
|
||||||
dirs = websiteDirName.split("\\\\");
|
|
||||||
} else {
|
|
||||||
dirs = websiteDirName.split(File.separator);
|
|
||||||
}
|
|
||||||
webAppName = dirs[dirs.length-1];
|
|
||||||
|
|
||||||
// something like: /usr/local/src/Vitro/dream/common/web
|
// something like: /usr/local/src/Vitro/dream/common/web
|
||||||
try{
|
try{
|
||||||
sourceDirName = getSourceDirName();
|
sourceDirName = getSourceDirName();
|
||||||
|
@ -546,24 +534,9 @@ public class UploadImagesServlet extends VitroHttpServlet {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private String getSourceDirName() throws IOException{
|
private String getSourceDirName() throws IOException{
|
||||||
Properties props = new Properties();
|
String dirName = ConfigurationProperties.getProperty("UploadImagesServlet.sourceDirName");
|
||||||
InputStream raw = this.getClass().getResourceAsStream( UPLOAD_SERVLET_PROPERTIES );
|
|
||||||
if (raw == null) {
|
|
||||||
raw = this.getClass().getResourceAsStream( UPLOAD_SERVLET_PROPERTIES_WIN );
|
|
||||||
if (raw == null)
|
|
||||||
throw new IOException("UploadImagesServlet.getSourceDirName()" +
|
|
||||||
" Failed to find resource: " + UPLOAD_SERVLET_PROPERTIES );
|
|
||||||
}
|
|
||||||
try{
|
|
||||||
props.load( raw );
|
|
||||||
} catch (Exception ex){
|
|
||||||
throw new IOException("unable to load upload.properties file: " + ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
raw.close();
|
|
||||||
}
|
|
||||||
String dirName = props.getProperty("UploadImagesServlet.sourceDirName");
|
|
||||||
if( dirName == null ) {
|
if( dirName == null ) {
|
||||||
log.error("getSourceDirName(): property sourceDirName not defined in upload.properties");
|
log.error("getSourceDirName(): property sourceDirName not defined in configuration properties");
|
||||||
} else {
|
} else {
|
||||||
File dir = new File(dirName);
|
File dir = new File(dirName);
|
||||||
if(!dir.exists()) {
|
if(!dir.exists()) {
|
||||||
|
|
|
@ -4,11 +4,9 @@ package edu.cornell.mannlib.vitro.webapp.search.lucene;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
@ -18,6 +16,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
|
||||||
|
@ -55,13 +54,13 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
||||||
/**
|
/**
|
||||||
* Gets run to set up DataSource when the webapp servlet context gets created.
|
* Gets run to set up DataSource when the webapp servlet context gets created.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "static-access", "unchecked" })
|
@SuppressWarnings("unchecked")
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
try {
|
try {
|
||||||
ServletContext context = sce.getServletContext();
|
ServletContext context = sce.getServletContext();
|
||||||
log.info("**** Running "+this.getClass().getName()+".contextInitialized()");
|
log.info("**** Running "+this.getClass().getName()+".contextInitialized()");
|
||||||
|
|
||||||
indexDir = getIndexDirName(sce.getServletContext());
|
indexDir = getIndexDirName();
|
||||||
log.info("Directory of full text index: " + indexDir );
|
log.info("Directory of full text index: " + indexDir );
|
||||||
|
|
||||||
setBoolMax();
|
setBoolMax();
|
||||||
|
@ -135,59 +134,37 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
||||||
BooleanQuery.setMaxClauseCount(16384);
|
BooleanQuery.setMaxClauseCount(16384);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Directory to store lucene index use when none is specified. */
|
|
||||||
private String DEFAULT_INDEX_DIR = "/fullTextIndex";
|
|
||||||
|
|
||||||
/** name of the properties file to look for in the 'resources' */
|
|
||||||
private String LUCENE_PROPERTIES = "/LuceneSetup.properties";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the directory to store the lucene index in.
|
* Gets the name of the directory to store the lucene index in. The
|
||||||
* This is stored in a file named LuceneSetup.properties
|
* {@link ConfigurationProperties} should have a property named
|
||||||
* which should be on the classpath in the default package.
|
* 'LuceneSetup.indexDir' which has the directory to store the lucene index
|
||||||
* That file should have a property named 'LuceneSetup.indexDir'
|
* for this clone in. If the property is not found, an exception will be
|
||||||
* which has the directory to store the lucene index for this
|
* thrown.
|
||||||
* clone in. If the property file is not found or the
|
|
||||||
* LuceneSetup.indexDir is not found, then DEFAULT_INDEX_DIR will
|
|
||||||
* be used.
|
|
||||||
* @param servletContext
|
|
||||||
* @return a string that is the directory to store the lucene
|
|
||||||
* index.
|
|
||||||
*
|
*
|
||||||
|
* @return a string that is the directory to store the lucene index.
|
||||||
|
* @throws IllegalStateException
|
||||||
|
* if the property is not found.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
* if the directory doesn't exist and we fail to create it.
|
||||||
*/
|
*/
|
||||||
private String getIndexDirName(ServletContext servletContext) {
|
private String getIndexDirName()
|
||||||
String dirName = null;
|
throws IOException {
|
||||||
|
String dirName = ConfigurationProperties
|
||||||
// Check if we can get the properties file
|
.getProperty("LuceneSetup.indexDir");
|
||||||
Properties props = new Properties();
|
if (dirName == null) {
|
||||||
InputStream raw = this.getClass().getResourceAsStream( LUCENE_PROPERTIES );
|
throw new IllegalStateException(
|
||||||
if (raw != null){
|
"LuceneSetup.indexDir not found in properties file.");
|
||||||
try{
|
|
||||||
props.load( raw );
|
|
||||||
}catch (Exception ex){
|
|
||||||
log.info("Could not load properties file " + LUCENE_PROPERTIES);
|
|
||||||
props = null;
|
|
||||||
}finally {
|
|
||||||
try{ raw.close(); }
|
|
||||||
catch(Exception ex){}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we can get the indexDir property from the file
|
File dir = new File(dirName);
|
||||||
if( props != null ){
|
if (!dir.exists()) {
|
||||||
dirName = props.getProperty("LuceneSetup.indexDir");
|
boolean created = dir.mkdir();
|
||||||
if( dirName == null ){
|
if (!created) {
|
||||||
log.info("LuceneSetup.indexDir not found in file " + LUCENE_PROPERTIES + " using default.");
|
throw new IOException(
|
||||||
|
"Unable to create Lucene index directory at '" + dir
|
||||||
|
+ "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( dirName == null ){
|
|
||||||
dirName = servletContext.getRealPath(DEFAULT_INDEX_DIR);
|
|
||||||
File dir = new File( dirName);
|
|
||||||
if( !dir.exists() )
|
|
||||||
dir.mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
return dirName;
|
return dirName;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +175,6 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("static-access")
|
|
||||||
private Analyzer getAnalyzer() {
|
private Analyzer getAnalyzer() {
|
||||||
return new VitroAnalyzer();
|
return new VitroAnalyzer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.search.lucene;
|
package edu.cornell.mannlib.vitro.webapp.search.lucene;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
@ -18,6 +17,7 @@ import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.cjk.CJKAnalyzer;
|
import org.apache.lucene.analysis.cjk.CJKAnalyzer;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
|
import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
|
||||||
|
@ -55,7 +55,7 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
|
||||||
/**
|
/**
|
||||||
* Gets run to set up DataSource when the webapp servlet context gets created.
|
* Gets run to set up DataSource when the webapp servlet context gets created.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "static-access", "unchecked" })
|
@SuppressWarnings("unchecked")
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
ServletContext context = sce.getServletContext();
|
ServletContext context = sce.getServletContext();
|
||||||
log.info("**** Running "+this.getClass().getName()+".contextInitialized()");
|
log.info("**** Running "+this.getClass().getName()+".contextInitialized()");
|
||||||
|
@ -130,51 +130,38 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
|
||||||
BooleanQuery.setMaxClauseCount(16384);
|
BooleanQuery.setMaxClauseCount(16384);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** directory to use when none is specified */
|
|
||||||
private String DEFAULT_INDEX_DIR = "/usr/local/lucene/vitrodefault";
|
|
||||||
|
|
||||||
/** name of the properties file to look for in the 'resources' */
|
|
||||||
private String LUCENE_PROPERTIES = "/LuceneSetup.properties";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the directory to store the lucene index in.
|
* Gets the name of the directory to store the lucene index in. The
|
||||||
* This is stored in a file named LuceneSetup.properties
|
* {@link ConfigurationProperties} should have a property named
|
||||||
* which should be on the classpath in the default package.
|
* 'LuceneSetup.indexDir' which has the directory to store the lucene index
|
||||||
* That file should have a property named 'LuceneSetup.indexDir'
|
* for this clone in. If the property is not found, an exception will be
|
||||||
* which has the directory to store the lucene index for this
|
* thrown.
|
||||||
* clone in. If the property file is not found or the
|
|
||||||
* LuceneSetup.indexDir is not found, then DEFAULT_INDEX_DIR will
|
|
||||||
* be used.
|
|
||||||
* @return a string that is the directory to store the lucene
|
|
||||||
* index.
|
|
||||||
*
|
*
|
||||||
|
* @return a string that is the directory to store the lucene index.
|
||||||
|
* @throws IllegalStateException
|
||||||
|
* if the property is not found.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
* if the directory doesn't exist and we fail to create it.
|
||||||
*/
|
*/
|
||||||
private String getIndexDirName() {
|
private String getIndexDirName()
|
||||||
Properties props = new Properties();
|
throws IOException {
|
||||||
InputStream raw = this.getClass().getResourceAsStream( LUCENE_PROPERTIES );
|
String dirName = ConfigurationProperties
|
||||||
if (raw == null){
|
.getProperty("LuceneSetup.indexDir");
|
||||||
log.warn("LuceneSetup.getIndexDirName()" +
|
if (dirName == null) {
|
||||||
" Failed to find resource: " + LUCENE_PROPERTIES +
|
throw new IllegalStateException(
|
||||||
". Using default directory " + DEFAULT_INDEX_DIR);
|
"LuceneSetup.indexDir not found in properties file.");
|
||||||
return DEFAULT_INDEX_DIR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try{ props.load( raw ); }
|
File dir = new File(dirName);
|
||||||
catch (Exception ex){
|
if (!dir.exists()) {
|
||||||
log.error("LuceneSetup.getIndexDirName()" +
|
boolean created = dir.mkdir();
|
||||||
"unable to load properties: \n" + ex.getMessage() +
|
if (!created) {
|
||||||
"\nUsing default directory " + DEFAULT_INDEX_DIR);
|
throw new IOException(
|
||||||
return DEFAULT_INDEX_DIR;
|
"Unable to create Lucene index directory at '" + dir
|
||||||
|
+ "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally { try{raw.close();} catch(Exception ex){} }
|
|
||||||
|
|
||||||
String dirName = props.getProperty("LuceneSetup.indexDir");
|
|
||||||
if( dirName == null ){
|
|
||||||
log.error("LuceneSetup.getIndexDir: " +
|
|
||||||
"indexDir not found. Using default directory "+DEFAULT_INDEX_DIR );
|
|
||||||
return DEFAULT_INDEX_DIR;
|
|
||||||
}
|
|
||||||
return dirName;
|
return dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +171,6 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("static-access")
|
|
||||||
private Analyzer getAnalyzer() {
|
private Analyzer getAnalyzer() {
|
||||||
return new CJKAnalyzer();
|
return new CJKAnalyzer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,29 +2,21 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
import com.hp.hpl.jena.graph.Graph;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy.ContextSetup;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RegeneratingGraph;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RegeneratingGraph;
|
||||||
|
|
||||||
|
@ -42,8 +34,6 @@ public class JenaDataSourceSetupBase {
|
||||||
DEFAULT_TESTONRETURN = true,
|
DEFAULT_TESTONRETURN = true,
|
||||||
DEFAULT_TESTWHILEIDLE = true;
|
DEFAULT_TESTWHILEIDLE = true;
|
||||||
|
|
||||||
protected final static String CONNECTION_PROP_LOCATION = "/WEB-INF/classes/connection.properties";
|
|
||||||
|
|
||||||
protected static String BASE = "/WEB-INF/ontologies/";
|
protected static String BASE = "/WEB-INF/ontologies/";
|
||||||
protected static String USERPATH = BASE+"user/";
|
protected static String USERPATH = BASE+"user/";
|
||||||
protected static String SYSTEMPATH = BASE+"system/";
|
protected static String SYSTEMPATH = BASE+"system/";
|
||||||
|
@ -53,19 +43,19 @@ public class JenaDataSourceSetupBase {
|
||||||
String DB_PASSWD = "jenatest"; // database password
|
String DB_PASSWD = "jenatest"; // database password
|
||||||
String DB = "MySQL"; // database type
|
String DB = "MySQL"; // database type
|
||||||
String DB_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
|
String DB_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
|
||||||
String JENA_DB_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-2";
|
static final String JENA_DB_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-2";
|
||||||
String JENA_AUDIT_MODEL = "http://vitro.mannlib.cornell.edu/ns/db/experimental/audit";
|
static final String JENA_AUDIT_MODEL = "http://vitro.mannlib.cornell.edu/ns/db/experimental/audit";
|
||||||
String JENA_INF_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf";
|
static final String JENA_INF_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf";
|
||||||
String JENA_USER_ACCOUNTS_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-userAccounts";
|
static final String JENA_USER_ACCOUNTS_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-userAccounts";
|
||||||
String JENA_APPLICATION_METADATA_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-applicationMetadata";
|
static final String JENA_APPLICATION_METADATA_MODEL = "http://vitro.mannlib.cornell.edu/default/vitro-kb-applicationMetadata";
|
||||||
|
|
||||||
static final String DEFAULT_DEFAULT_NAMESPACE = "http://vitro.mannlib.cornell.edu/ns/default#";
|
static final String DEFAULT_DEFAULT_NAMESPACE = "http://vitro.mannlib.cornell.edu/ns/default#";
|
||||||
|
|
||||||
static String defaultNamespace = DEFAULT_DEFAULT_NAMESPACE; // TODO: improve this
|
static String defaultNamespace = DEFAULT_DEFAULT_NAMESPACE; // TODO: improve this
|
||||||
|
|
||||||
// use OWL models with no reasoning
|
// use OWL models with no reasoning
|
||||||
OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
static final OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
||||||
OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
static final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(JenaDataSourceSetupBase.class.getName());
|
private static final Log log = LogFactory.getLog(JenaDataSourceSetupBase.class.getName());
|
||||||
|
|
||||||
|
@ -73,53 +63,23 @@ public class JenaDataSourceSetupBase {
|
||||||
* Sets up a Model and DB connection using values from
|
* Sets up a Model and DB connection using values from
|
||||||
* a properties file.
|
* a properties file.
|
||||||
*/
|
*/
|
||||||
public final Model makeDBModelFromPropertiesFile(final String filename) {
|
public final Model makeDBModelFromConfigurationProperties(String jenaDbModelName, OntModelSpec jenaDbOntModelSpec){
|
||||||
return makeDBModelFromPropertiesFile(filename, null, null);
|
String dbDriverClassname = ConfigurationProperties.getProperty("VitroConnection.DataSource.driver", DB_DRIVER_CLASS_NAME);
|
||||||
}
|
String jdbcUrl = ConfigurationProperties.getProperty("VitroConnection.DataSource.url") + "?useUnicode=yes&characterEncoding=utf8";
|
||||||
|
String username = ConfigurationProperties.getProperty("VitroConnection.DataSource.username");
|
||||||
|
String password = ConfigurationProperties.getProperty("VitroConnection.DataSource.password");
|
||||||
|
BasicDataSource ds = makeBasicDataSource(dbDriverClassname, jdbcUrl, username, password);
|
||||||
|
|
||||||
/**
|
String dns = ConfigurationProperties.getProperty("Vitro.defaultNamespace");
|
||||||
* Sets up a Model and DB connection using values from
|
|
||||||
* a properties file.
|
|
||||||
*/
|
|
||||||
public final Model makeDBModelFromPropertiesFile(final String filename, String jenaDbModelName, OntModelSpec jenaDbOntModelSpec){
|
|
||||||
|
|
||||||
if (filename == null || filename.length() <= 0) {
|
|
||||||
throw new Error(
|
|
||||||
"To establish the DB model you MUST set the "
|
|
||||||
+ "filename to the location of a "
|
|
||||||
+ "connection.properties file with the database connection parameters.");
|
|
||||||
}
|
|
||||||
|
|
||||||
File propF = new File(filename );
|
|
||||||
InputStream is;
|
|
||||||
try {
|
|
||||||
is = new FileInputStream(propF);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
log.error("Could not load file "+filename);
|
|
||||||
throw new Error("Could not load file " + filename
|
|
||||||
+ '\n' + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties dbProps = new Properties();
|
|
||||||
try {
|
|
||||||
dbProps.load(is);
|
|
||||||
if (jenaDbModelName == null) {
|
|
||||||
String specifiedModelName = dbProps.getProperty("Jena.modelName");
|
|
||||||
jenaDbModelName = (specifiedModelName != null) ? specifiedModelName : JENA_DB_MODEL;
|
|
||||||
}
|
|
||||||
jenaDbOntModelSpec = (jenaDbOntModelSpec != null) ? jenaDbOntModelSpec : DB_ONT_MODEL_SPEC;
|
|
||||||
String dns = dbProps.getProperty("Vitro.defaultNamespace");
|
|
||||||
defaultNamespace = (dns != null && dns.length()>0) ? dns : null;
|
defaultNamespace = (dns != null && dns.length()>0) ? dns : null;
|
||||||
return makeDBModelFromProperties(dbProps, jenaDbModelName, jenaDbOntModelSpec);
|
|
||||||
} catch (IOException e) {
|
jenaDbOntModelSpec = (jenaDbOntModelSpec != null) ? jenaDbOntModelSpec : DB_ONT_MODEL_SPEC;
|
||||||
throw new Error("Could not load properties from file " + filename + '\n'
|
return makeDBModel(ds, jenaDbModelName, jenaDbOntModelSpec);
|
||||||
+ e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BasicDataSource makeBasicDataSource(String dbDriverClassname, String jdbcUrl, String username, String password) {
|
protected BasicDataSource makeBasicDataSource(String dbDriverClassname, String jdbcUrl, String username, String password) {
|
||||||
BasicDataSource ds = new BasicDataSource();
|
BasicDataSource ds = new BasicDataSource();
|
||||||
ds.setDriverClassName( (dbDriverClassname==null) ? DB_DRIVER_CLASS_NAME : dbDriverClassname );
|
ds.setDriverClassName(dbDriverClassname);
|
||||||
ds.setUrl(jdbcUrl);
|
ds.setUrl(jdbcUrl);
|
||||||
ds.setUsername(username);
|
ds.setUsername(username);
|
||||||
ds.setPassword(password);
|
ds.setPassword(password);
|
||||||
|
@ -139,14 +99,6 @@ public class JenaDataSourceSetupBase {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Class.forName(DB_DRIVER_CLASS_NAME);
|
|
||||||
//Create database connection
|
|
||||||
//IDBConnection conn = new DBConnection ( jdbcUrl, username, password, DB );
|
|
||||||
//IDBConnection conn = new DBConnection(ds.getConnection(),DB);
|
|
||||||
//ModelMaker maker = ModelFactory.createModelRDBMaker(conn) ;
|
|
||||||
|
|
||||||
//ReconnectingGraphRDBMaker maker = new ReconnectingGraphRDBMaker(jdbcUrl, username, password, DB, null, ReificationStyle.Convenient);
|
|
||||||
|
|
||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,15 +126,6 @@ public class JenaDataSourceSetupBase {
|
||||||
return dbModel;
|
return dbModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Model makeDBModelFromProperties(Properties dbProps, String jenaDbModelName, OntModelSpec jenaDbOntModelSpec) {
|
|
||||||
String dbDriverClassname = dbProps.getProperty("VitroConnection.DataSource.driver");
|
|
||||||
String jdbcUrl = dbProps.getProperty("VitroConnection.DataSource.url") + "?useUnicode=yes&characterEncoding=utf8";
|
|
||||||
String username = dbProps.getProperty("VitroConnection.DataSource.username");
|
|
||||||
String password = dbProps.getProperty("VitroConnection.DataSource.password");
|
|
||||||
BasicDataSource ds = makeBasicDataSource(dbDriverClassname, jdbcUrl, username, password);
|
|
||||||
return makeDBModel(ds, jenaDbModelName, jenaDbOntModelSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void readOntologyFilesInPathSet(String path, ServletContext ctx, Model model) {
|
public static void readOntologyFilesInPathSet(String path, ServletContext ctx, Model model) {
|
||||||
Set<String> paths = ctx.getResourcePaths(path);
|
Set<String> paths = ctx.getResourcePaths(path);
|
||||||
for(String p : paths) {
|
for(String p : paths) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
OntModel memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
OntModel dbModel = null;
|
OntModel dbModel = null;
|
||||||
try {
|
try {
|
||||||
Model dbPlainModel = makeDBModelFromPropertiesFile(sce.getServletContext().getRealPath(CONNECTION_PROP_LOCATION), JENA_DB_MODEL, DB_ONT_MODEL_SPEC);
|
Model dbPlainModel = makeDBModelFromConfigurationProperties(JENA_DB_MODEL, DB_ONT_MODEL_SPEC);
|
||||||
dbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,dbPlainModel);
|
dbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,dbPlainModel);
|
||||||
boolean isEmpty = true;
|
boolean isEmpty = true;
|
||||||
ClosableIterator stmtIt = dbModel.listStatements();
|
ClosableIterator stmtIt = dbModel.listStatements();
|
||||||
|
@ -57,7 +57,7 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.out.println("**** ERROR *****");
|
System.out.println("**** ERROR *****");
|
||||||
System.out.println("Vitro unable to open Jena database model.");
|
System.out.println("Vitro unable to open Jena database model.");
|
||||||
System.out.println("Check that connection.properties has been created WEB-INF/classes, ");
|
System.out.println("Check that the configuration properties file has been created in WEB-INF/classes, ");
|
||||||
System.out.println("and that the database connection parameters are accurate. ");
|
System.out.println("and that the database connection parameters are accurate. ");
|
||||||
System.out.println("****************");
|
System.out.println("****************");
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
|
|
||||||
// default inference graph
|
// default inference graph
|
||||||
try {
|
try {
|
||||||
Model infDbPlainModel = makeDBModelFromPropertiesFile(sce.getServletContext().getRealPath(CONNECTION_PROP_LOCATION), JENA_INF_MODEL, DB_ONT_MODEL_SPEC);
|
Model infDbPlainModel = makeDBModelFromConfigurationProperties(JENA_INF_MODEL, DB_ONT_MODEL_SPEC);
|
||||||
OntModel infDbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,infDbPlainModel);
|
OntModel infDbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,infDbPlainModel);
|
||||||
sce.getServletContext().setAttribute("inferenceOntModel",infDbModel);
|
sce.getServletContext().setAttribute("inferenceOntModel",infDbModel);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase imple
|
||||||
boolean firstStartup = false;
|
boolean firstStartup = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dbModel = makeDBModelFromPropertiesFile(sce.getServletContext().getRealPath(CONNECTION_PROP_LOCATION), JENA_DB_MODEL, DB_ONT_MODEL_SPEC);
|
dbModel = makeDBModelFromConfigurationProperties(JENA_DB_MODEL, DB_ONT_MODEL_SPEC);
|
||||||
|
|
||||||
ClosableIterator stmtIt = dbModel.listStatements();
|
ClosableIterator stmtIt = dbModel.listStatements();
|
||||||
try {
|
try {
|
||||||
|
@ -63,14 +63,14 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase imple
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.out.println("**** ERROR *****");
|
System.out.println("**** ERROR *****");
|
||||||
System.out.println("Vitro unable to open Jena database model.");
|
System.out.println("Vitro unable to open Jena database model.");
|
||||||
System.out.println("Check that connection.properties has been created WEB-INF/classes, ");
|
System.out.println("Check that the configuration properties file has been created in WEB-INF/classes, ");
|
||||||
System.out.println("and that the database connection parameters are accurate. ");
|
System.out.println("and that the database connection parameters are accurate. ");
|
||||||
System.out.println("****************");
|
System.out.println("****************");
|
||||||
}
|
}
|
||||||
|
|
||||||
// default inference graph
|
// default inference graph
|
||||||
try {
|
try {
|
||||||
Model infDbModel = makeDBModelFromPropertiesFile(sce.getServletContext().getRealPath(CONNECTION_PROP_LOCATION), JENA_INF_MODEL, DB_ONT_MODEL_SPEC);
|
Model infDbModel = makeDBModelFromConfigurationProperties(JENA_INF_MODEL, DB_ONT_MODEL_SPEC);
|
||||||
OntModel infModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel infModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
if (infDbModel != null) {
|
if (infDbModel != null) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
@ -86,7 +86,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase imple
|
||||||
|
|
||||||
// user accounts Model
|
// user accounts Model
|
||||||
try {
|
try {
|
||||||
Model userAccountsDbModel = makeDBModelFromPropertiesFile(sce.getServletContext().getRealPath(CONNECTION_PROP_LOCATION), JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC);
|
Model userAccountsDbModel = makeDBModelFromConfigurationProperties(JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC);
|
||||||
if (firstStartup) {
|
if (firstStartup) {
|
||||||
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsDbModel);
|
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsDbModel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class ModelAuditorSetup extends JenaDataSourceSetupBase implements Servle
|
||||||
Model baseModel = ontModel.getBaseModel();
|
Model baseModel = ontModel.getBaseModel();
|
||||||
OntModel dynamicUnionModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
|
OntModel dynamicUnionModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
|
||||||
log.debug("Setting model auditor database...");
|
log.debug("Setting model auditor database...");
|
||||||
OntModel auditModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,makeDBModelFromPropertiesFile(sce.getServletContext().getRealPath(CONNECTION_PROP_LOCATION), JENA_AUDIT_MODEL, DB_ONT_MODEL_SPEC));
|
OntModel auditModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,makeDBModelFromConfigurationProperties(JENA_AUDIT_MODEL, DB_ONT_MODEL_SPEC));
|
||||||
sce.getServletContext().setAttribute("jenaAuditModel", auditModel);
|
sce.getServletContext().setAttribute("jenaAuditModel", auditModel);
|
||||||
ModelAuditor ma = new ModelAuditor(auditModel,ontModel);
|
ModelAuditor ma = new ModelAuditor(auditModel,ontModel);
|
||||||
baseModel.register(ma);
|
baseModel.register(ma);
|
||||||
|
|
|
@ -2,29 +2,22 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.db.DBConnection;
|
import com.hp.hpl.jena.db.DBConnection;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy.ContextSetup;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
||||||
|
|
||||||
public class VitroJenaModelMakerSetup implements ServletContextListener {
|
public class VitroJenaModelMakerSetup implements ServletContextListener {
|
||||||
|
private static final Logger LOG = Logger
|
||||||
|
.getLogger(VitroJenaModelMakerSetup.class);
|
||||||
|
|
||||||
protected final static String CONNECTION_PROP_LOCATION = "/WEB-INF/classes/connection.properties";
|
|
||||||
protected final static String DB_TYPE = "MySQL";
|
protected final static String DB_TYPE = "MySQL";
|
||||||
|
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
public void contextDestroyed(ServletContextEvent arg0) {
|
||||||
|
@ -32,78 +25,19 @@ public class VitroJenaModelMakerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void contextInitialized(ServletContextEvent arg0) {
|
public void contextInitialized(ServletContextEvent arg0) {
|
||||||
|
|
||||||
/* Sometimes this class fails for no apparent reason and stops
|
|
||||||
the context from loading. Trying to eliminate all uncaught errors. */
|
|
||||||
Log log = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log = LogFactory.getLog(VitroJenaModelMakerSetup.class.getName());
|
String jdbcUrl = ConfigurationProperties.getProperty("VitroConnection.DataSource.url")
|
||||||
} catch (Throwable t) {
|
+ "?useUnicode=yes&characterEncoding=utf8";
|
||||||
System.out.println("Unable to use error log for "+this.getClass().getName());
|
String username = ConfigurationProperties.getProperty("VitroConnection.DataSource.username");
|
||||||
}
|
String password = ConfigurationProperties.getProperty("VitroConnection.DataSource.password");
|
||||||
|
|
||||||
try {
|
DBConnection dbConn = new DBConnection(jdbcUrl, username, password, DB_TYPE);
|
||||||
String filename = arg0.getServletContext().getRealPath(CONNECTION_PROP_LOCATION);
|
|
||||||
if (filename == null || filename.length() <= 0) {
|
|
||||||
if (log != null) {
|
|
||||||
log.error(
|
|
||||||
"Error setting up VitroModelMaker:\n" +
|
|
||||||
"To establish the DB model you MUST set the "
|
|
||||||
+ "filename to the location of a "
|
|
||||||
+ "connection.properties file with the database connection parameters.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
File propF = new File(filename );
|
|
||||||
InputStream is = null;
|
|
||||||
try {
|
|
||||||
is = new FileInputStream(propF);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
String msg = "Error setting up VitroJenaModelMaker:\nCould not load file "+filename;
|
|
||||||
if (log != null) {
|
|
||||||
log.error(msg);
|
|
||||||
} else {
|
|
||||||
System.out.println(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties dbProps = new Properties();
|
|
||||||
try {
|
|
||||||
dbProps.load(is);
|
|
||||||
String dns = dbProps.getProperty("Vitro.defaultNamespace");
|
|
||||||
String dbDriverClassname = dbProps.getProperty("VitroConnection.DataSource.driver");
|
|
||||||
String jdbcUrl = dbProps.getProperty("VitroConnection.DataSource.url") + "?useUnicode=yes&characterEncoding=utf8";
|
|
||||||
String username = dbProps.getProperty("VitroConnection.DataSource.username");
|
|
||||||
String password = dbProps.getProperty("VitroConnection.DataSource.password");
|
|
||||||
DBConnection dbConn = new DBConnection(jdbcUrl,username,password,DB_TYPE);
|
|
||||||
ModelMaker mMaker = ModelFactory.createModelRDBMaker(dbConn);
|
ModelMaker mMaker = ModelFactory.createModelRDBMaker(dbConn);
|
||||||
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(mMaker);
|
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(mMaker);
|
||||||
arg0.getServletContext().setAttribute("vitroJenaModelMaker",vjmm);
|
arg0.getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
|
||||||
String msg = "VitroJenaModelMaker set up";
|
LOG.debug("VitroJenaModelMaker set up");
|
||||||
if (log != null) {
|
|
||||||
log.debug(msg);
|
|
||||||
} else {
|
|
||||||
System.out.println(msg);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
String msg = "Error setting up VitroJenaModelMaker:\nCould not load properties from file " + filename + '\n'
|
|
||||||
+ e.getMessage();
|
|
||||||
if (log != null) {
|
|
||||||
log.error(msg);
|
|
||||||
} else {
|
|
||||||
System.out.println(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
String msg = "Unable to set up default VitroJenaModelMaker";
|
LOG.error("Unable to set up default VitroJenaModelMaker", t);
|
||||||
if (log != null) {
|
|
||||||
log.error(msg);
|
|
||||||
log.error(t);
|
|
||||||
} else {
|
|
||||||
System.out.println(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue