Merge branch 'develop' of https://github.com/vivo-project/Vitro into develop
um, just mergin' in the remote changes before a push?
This commit is contained in:
commit
cd7fe20cac
28 changed files with 334 additions and 351 deletions
|
@ -49,15 +49,6 @@ public class ApplicationBean {
|
|||
private String copyrightAnchor;
|
||||
private String themeDir;
|
||||
|
||||
public static ApplicationBean getAppBean(ServletContext sc){
|
||||
if( sc != null ){
|
||||
Object obj = sc.getAttribute("applicationBean");
|
||||
if( obj != null )
|
||||
return (ApplicationBean)obj;
|
||||
}
|
||||
return new ApplicationBean();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String output = "Application Bean Contents:\n";
|
||||
output += " initialized from DB: [" + initialized + "]\n";
|
||||
|
|
|
@ -33,9 +33,6 @@ import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
|||
public class OntologyController extends VitroHttpServlet{
|
||||
private static final Log log = LogFactory.getLog(OntologyController.class.getName());
|
||||
|
||||
private String default_jsp = Controllers.BASIC_JSP;
|
||||
private ApplicationBean appBean;
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException,IOException{
|
||||
doGet(request, response);
|
||||
|
@ -242,7 +239,7 @@ public class OntologyController extends VitroHttpServlet{
|
|||
throws IOException, ServletException {
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
ApplicationBean appBean = ApplicationBean.getAppBean(getServletContext());
|
||||
ApplicationBean appBean = vreq.getAppBean();
|
||||
|
||||
//set title before we do the highlighting so we don't get markup in it.
|
||||
req.setAttribute("title","not found");
|
||||
|
|
|
@ -283,12 +283,8 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
|||
}
|
||||
|
||||
public ApplicationBean getAppBean(){
|
||||
//return (ApplicationBean) getAttribute("appBean");
|
||||
return getWebappDaoFactory().getApplicationDao().getApplicationBean();
|
||||
}
|
||||
public void setAppBean(ApplicationBean ab){
|
||||
setAttribute("appBean",ab);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Map;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
|
@ -31,7 +30,7 @@ public class StartupStatusController extends FreemarkerHttpServlet {
|
|||
body.put("title", "Startup Status");
|
||||
body.put("status", StartupStatus.getBean(getServletContext()));
|
||||
body.put("contextPath", getContextPath());
|
||||
body.put("applicationName", getApplicationName());
|
||||
body.put("applicationName", getApplicationName(vreq));
|
||||
|
||||
return new TemplateResponseValues("startupStatus-display.ftl", body);
|
||||
}
|
||||
|
@ -45,11 +44,10 @@ public class StartupStatusController extends FreemarkerHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
private Object getApplicationName() {
|
||||
private Object getApplicationName(VitroRequest vreq) {
|
||||
String name = "";
|
||||
try {
|
||||
ApplicationBean app = ApplicationBean.getAppBean(getServletContext());
|
||||
name = app.getApplicationName();
|
||||
name = vreq.getAppBean().getApplicationName();
|
||||
} catch (Exception e) {
|
||||
// deal with problems below
|
||||
}
|
||||
|
|
|
@ -15,12 +15,6 @@ public interface IndividualRequestAnalysisContext {
|
|||
*/
|
||||
String getDefaultNamespace();
|
||||
|
||||
/**
|
||||
* Is there a namespace for this prefix? If not, return an empty string, but
|
||||
* never null.
|
||||
*/
|
||||
String getNamespaceForPrefix(String prefix);
|
||||
|
||||
/**
|
||||
* Use the IndividualDao to get this individual.
|
||||
*
|
||||
|
|
|
@ -15,8 +15,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
||||
|
||||
/**
|
||||
* Implement all of the fiddly-bits that we need for analyzing the request for
|
||||
|
@ -45,25 +43,6 @@ public class IndividualRequestAnalysisContextImpl implements
|
|||
return wadf.getDefaultNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespaceForPrefix(String prefix) {
|
||||
if (prefix == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
NamespaceMapper namespaceMapper = NamespaceMapperFactory
|
||||
.getNamespaceMapper(ctx);
|
||||
if (namespaceMapper == null) {
|
||||
log.warn("No NamespaceMapper in ServletContext. Request URL was '"
|
||||
+ vreq.getRequestURL() + "'");
|
||||
return "";
|
||||
}
|
||||
|
||||
String ns = namespaceMapper.getNamespaceForPrefix(prefix);
|
||||
|
||||
return (ns == null) ? "" : ns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Individual getIndividualByURI(String individualUri) {
|
||||
if (individualUri == null) {
|
||||
|
|
|
@ -30,7 +30,6 @@ public class IndividualRequestAnalyzer {
|
|||
private static Pattern RDF_REQUEST = Pattern.compile("^/individual/([^/]+)/\\1\\.(rdf|n3|ttl)$");
|
||||
private static Pattern HTML_REQUEST = Pattern.compile("^/display/([^/]+)$");
|
||||
private static Pattern LINKED_DATA_URL = Pattern.compile("^/individual/([^/]+)$");
|
||||
private static Pattern NS_PREFIX_URL = Pattern.compile("^/individual/([^/]*)/([^/]+)$");
|
||||
|
||||
private final VitroRequest vreq;
|
||||
private final IndividualRequestAnalysisContext analysisContext;
|
||||
|
@ -164,7 +163,6 @@ public class IndividualRequestAnalyzer {
|
|||
* /individual/localname/localname.rdf
|
||||
* /individual/localname/localname.n3
|
||||
* /individual/localname/localname.ttl
|
||||
* /individual/nsprefix/localname
|
||||
* </pre>
|
||||
*
|
||||
* @return null on failure.
|
||||
|
@ -202,14 +200,6 @@ public class IndividualRequestAnalyzer {
|
|||
return getIndividualByLocalname(rdfMatch.group(1));
|
||||
}
|
||||
|
||||
// Does the URL look like a namespace prefix followed by a local
|
||||
// name?
|
||||
Matcher prefix_match = NS_PREFIX_URL.matcher(url);
|
||||
if (prefix_match.matches() && prefix_match.groupCount() == 2) {
|
||||
return getIndividualByPrefixAndLocalname(prefix_match.group(1),
|
||||
prefix_match.group(2));
|
||||
}
|
||||
|
||||
// Couldn't match it to anything.
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
|
@ -299,12 +289,6 @@ public class IndividualRequestAnalyzer {
|
|||
return getIndividualByUri(uri);
|
||||
}
|
||||
|
||||
private Individual getIndividualByPrefixAndLocalname(String prefix,
|
||||
String localName) {
|
||||
String ns = analysisContext.getNamespaceForPrefix(prefix);
|
||||
return getIndividualByUri(ns + localName);
|
||||
}
|
||||
|
||||
private Individual getIndividualByNetId(String netId) {
|
||||
return analysisContext.getIndividualByNetId(netId);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
implements EditConfigurationGenerator {
|
||||
|
||||
final static String vivoCore = "http://vivoweb.org/ontology/core#";
|
||||
final static String toDateTimeValue = vivoCore + "dateTimeValue";
|
||||
final String toDateTimeValue = vivoCore + "dateTimeValue";
|
||||
final static String valueType = vivoCore + "DateTimeValue";
|
||||
final static String dateTimeValue = vivoCore + "dateTime";
|
||||
final static String dateTimePrecision = vivoCore + "dateTimePrecision";
|
||||
|
@ -41,23 +41,23 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
|
||||
conf.setTemplate("dateTimeValueForm.ftl");
|
||||
conf.setTemplate(this.getTemplate());
|
||||
|
||||
conf.setVarNameForSubject("subject");
|
||||
conf.setVarNameForPredicate("toDateTimeValue");
|
||||
conf.setVarNameForObject("valueNode");
|
||||
|
||||
conf.setN3Optional(Arrays.asList(n3ForValue));
|
||||
conf.setN3Optional(Arrays.asList(getN3ForValue()));
|
||||
|
||||
conf.addNewResource("valueNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
conf.addSparqlForExistingLiteral(
|
||||
"dateTimeField-value", existingDateTimeValueQuery);
|
||||
"dateTimeField-value", getExistingDateTimeValueQuery());
|
||||
conf.addSparqlForExistingUris(
|
||||
"dateTimeField-precision", existingPrecisionQuery);
|
||||
conf.addSparqlForExistingUris("valueNode", existingNodeQuery);
|
||||
"dateTimeField-precision", getExistingPrecisionQuery());
|
||||
conf.addSparqlForExistingUris("valueNode", getExistingNodeQuery());
|
||||
|
||||
FieldVTwo dateTimeField = new FieldVTwo().setName("dateTimeField");
|
||||
FieldVTwo dateTimeField = new FieldVTwo().setName(this.getDateTimeFieldName());
|
||||
dateTimeField.setEditElement(new DateTimeWithPrecisionVTwo(dateTimeField,
|
||||
VitroVocabulary.Precision.SECOND.uri(),
|
||||
VitroVocabulary.Precision.NONE.uri()));
|
||||
|
@ -67,34 +67,40 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
//Adding additional data, specifically edit mode
|
||||
addFormSpecificData(conf, vreq);
|
||||
//prepare
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
final static String n3ForValue =
|
||||
"?subject <" + toDateTimeValue + "> ?valueNode . \n" +
|
||||
|
||||
//Writing these as methods instead of static strings allows the method getToDateTimeValuePredicate
|
||||
//to be called after the class has been initialized - this is important for subclasses of this generator
|
||||
//that rely on vreq for predicate
|
||||
protected String getN3ForValue() {
|
||||
return "?subject <" + this.getToDateTimeValuePredicate() + "> ?valueNode . \n" +
|
||||
"?valueNode a <" + valueType + "> . \n" +
|
||||
"?valueNode <" + dateTimeValue + "> ?dateTimeField-value . \n" +
|
||||
"?valueNode <" + dateTimePrecision + "> ?dateTimeField-precision .";
|
||||
"?valueNode <" + dateTimePrecision + "> ?dateTimeField-precision .";
|
||||
}
|
||||
|
||||
final static String existingDateTimeValueQuery =
|
||||
"SELECT ?existingDateTimeValue WHERE { \n" +
|
||||
"?subject <" + toDateTimeValue + "> ?existingValueNode . \n" +
|
||||
protected String getExistingDateTimeValueQuery () {
|
||||
return "SELECT ?existingDateTimeValue WHERE { \n" +
|
||||
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" +
|
||||
"?existingValueNode a <" + valueType + "> . \n" +
|
||||
"?existingValueNode <" + dateTimeValue + "> ?existingDateTimeValue }";
|
||||
}
|
||||
|
||||
final static String existingPrecisionQuery =
|
||||
"SELECT ?existingPrecision WHERE { \n" +
|
||||
"?subject <" + toDateTimeValue + "> ?existingValueNode . \n" +
|
||||
protected String getExistingPrecisionQuery() {
|
||||
return "SELECT ?existingPrecision WHERE { \n" +
|
||||
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" +
|
||||
"?existingValueNode a <" + valueType + "> . \n" +
|
||||
"?existingValueNode <" + dateTimePrecision + "> ?existingPrecision }";
|
||||
|
||||
final static String existingNodeQuery =
|
||||
"SELECT ?existingNode WHERE { \n" +
|
||||
"?subject <" + toDateTimeValue + "> ?existingNode . \n" +
|
||||
}
|
||||
protected String getExistingNodeQuery() {
|
||||
return "SELECT ?existingNode WHERE { \n" +
|
||||
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingNode . \n" +
|
||||
"?existingNode a <" + valueType + "> }";
|
||||
|
||||
|
||||
}
|
||||
public static String getNodeVar() {
|
||||
return "valueNode";
|
||||
}
|
||||
|
@ -103,6 +109,19 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
return "?" + getNodeVar();
|
||||
}
|
||||
|
||||
//isolating the predicate in this fashion allows this class to be subclassed for other date time value
|
||||
//properties
|
||||
protected String getToDateTimeValuePredicate() {
|
||||
return this.toDateTimeValue;
|
||||
}
|
||||
|
||||
protected String getDateTimeFieldName() {
|
||||
return "dateTimeField";
|
||||
}
|
||||
|
||||
protected String getTemplate() {
|
||||
return "dateTimeValueForm.ftl";
|
||||
}
|
||||
//Adding form specific data such as edit mode
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
|
|
|
@ -94,6 +94,10 @@ public class FileServingServlet extends VitroHttpServlet {
|
|||
String actualFilename = findAndValidateFilename(fileInfo, path);
|
||||
|
||||
in = openImageInputStream(fileInfo, actualFilename);
|
||||
} catch (FileServingException e) {
|
||||
log.info("Failed to serve the file at '" + path + "' -- " + e.getMessage());
|
||||
in = openMissingLinkImage(request);
|
||||
mimeType = "image/png";
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to serve the file at '" + path + "' -- " + e.getMessage());
|
||||
in = openMissingLinkImage(request);
|
||||
|
|
|
@ -21,6 +21,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||
import freemarker.cache.WebappTemplateLoader;
|
||||
import freemarker.template.Configuration;
|
||||
|
@ -67,36 +69,36 @@ public class StartupStatusDisplayFilter implements Filter {
|
|||
statusAlreadyDisplayed = true;
|
||||
}
|
||||
|
||||
private void displayStartupStatus(ServletRequest req, ServletResponse resp) throws IOException,
|
||||
ServletException {
|
||||
HttpServletResponse hResp = (HttpServletResponse) resp;
|
||||
private void displayStartupStatus(ServletRequest req, ServletResponse resp)
|
||||
throws IOException, ServletException {
|
||||
HttpServletResponse hresp = (HttpServletResponse) resp;
|
||||
HttpServletRequest hreq = (HttpServletRequest) req;
|
||||
|
||||
try {
|
||||
Map<String, Object> bodyMap = new HashMap<String, Object>();
|
||||
bodyMap.put("status", ss);
|
||||
bodyMap.put("showLink", !isFatal());
|
||||
bodyMap.put("contextPath", getContextPath());
|
||||
bodyMap.put("applicationName", getApplicationName());
|
||||
|
||||
HttpServletRequest httpreq = (HttpServletRequest) req;
|
||||
String url = "";
|
||||
|
||||
String path = httpreq.getRequestURI();
|
||||
if( path != null ){
|
||||
url = path;
|
||||
}
|
||||
|
||||
String query = httpreq.getQueryString();
|
||||
if( !StringUtils.isEmpty( query )){
|
||||
url = url + "?" + query;
|
||||
}
|
||||
|
||||
bodyMap.put("url", url );
|
||||
bodyMap.put("applicationName", getApplicationName());
|
||||
|
||||
hResp.setContentType("text/html;charset=UTF-8");
|
||||
hResp.setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
String url = "";
|
||||
|
||||
String path = hreq.getRequestURI();
|
||||
if (path != null) {
|
||||
url = path;
|
||||
}
|
||||
|
||||
String query = hreq.getQueryString();
|
||||
if (!StringUtils.isEmpty(query)) {
|
||||
url = url + "?" + query;
|
||||
}
|
||||
|
||||
bodyMap.put("url", url);
|
||||
|
||||
hresp.setContentType("text/html;charset=UTF-8");
|
||||
hresp.setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||
Template tpl = loadFreemarkerTemplate();
|
||||
tpl.process(bodyMap, hResp.getWriter());
|
||||
tpl.process(bodyMap, hresp.getWriter());
|
||||
} catch (TemplateException e) {
|
||||
throw new ServletException("Problem with Freemarker Template", e);
|
||||
}
|
||||
|
@ -114,7 +116,9 @@ public class StartupStatusDisplayFilter implements Filter {
|
|||
private Object getApplicationName() {
|
||||
String name = "";
|
||||
try {
|
||||
ApplicationBean app = ApplicationBean.getAppBean(ctx);
|
||||
WebappDaoFactory wadf = (WebappDaoFactory) ctx
|
||||
.getAttribute("webappDaoFactory");
|
||||
ApplicationBean app = wadf.getApplicationDao().getApplicationBean();
|
||||
name = app.getApplicationName();
|
||||
} catch (Exception e) {
|
||||
// deal with problems below
|
||||
|
|
|
@ -38,7 +38,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -82,19 +81,10 @@ public class VitroRequestPrep implements Filter {
|
|||
};
|
||||
|
||||
private ServletContext _context;
|
||||
private ApplicationBean _appbean;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
_context = filterConfig.getServletContext();
|
||||
|
||||
Object o = _context.getAttribute("applicationBean");
|
||||
if (o instanceof ApplicationBean) {
|
||||
_appbean = (ApplicationBean) o;
|
||||
} else {
|
||||
_appbean = new ApplicationBean();
|
||||
}
|
||||
log.debug("VitroRequestPrep: AppBean theme " + _appbean.getThemeDir());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,9 +122,6 @@ public class VitroRequestPrep implements Filter {
|
|||
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
//-- setup appBean --//
|
||||
vreq.setAppBean(_appbean);
|
||||
|
||||
//-- setup DAO factory --//
|
||||
WebappDaoFactory wdf = getWebappDaoFactory(vreq);
|
||||
//TODO: get accept-language from request and set as preferred languages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue