NIHVIVO-1149 Reintegrate dev-fmservlet branch after finishing restructuring of FreemarkerHttpServlet and subclasses. Two files had to be copied manually.
This commit is contained in:
parent
0abe35eb14
commit
8547665029
21 changed files with 625 additions and 482 deletions
|
@ -18,6 +18,7 @@ public class PrimitiveDelete extends PrimitiveRdfEdit {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(PrimitiveDelete.class);
|
private static final Log log = LogFactory.getLog(PrimitiveDelete.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
||||||
|
|
||||||
String uriToDelete = vreq.getParameter("deletion");
|
String uriToDelete = vreq.getParameter("deletion");
|
||||||
|
|
|
@ -4,10 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -28,38 +26,37 @@ import com.hp.hpl.jena.shared.Lock;
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.FreemarkerHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DependentResourceDeleteJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils;
|
||||||
import freemarker.template.Configuration;
|
|
||||||
|
|
||||||
public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
|
||||||
// boolean loggedIn = checkLoginStatus(request, response);
|
|
||||||
// if( !loggedIn){
|
|
||||||
// doError(response,"You must be logged in to use this servlet.",HttpStatus.SC_UNAUTHORIZED);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
return mergeBodyToTemplate("primitiveRdfEdit.ftl",new HashMap<String, Object>(), config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTitle(String siteName) {
|
protected String getTitle(String siteName) {
|
||||||
return "RDF edit";
|
return "RDF edit";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
boolean loggedIn = checkLoginStatus(vreq);
|
||||||
|
if( !loggedIn){
|
||||||
|
return new RedirectResponseValues(UrlBuilder.getUrl(Route.LOGIN));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TemplateResponseValues("primitiveRdfEdit.ftl");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request,
|
public void doPost(HttpServletRequest request,
|
||||||
HttpServletResponse response) throws ServletException, IOException {
|
HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
boolean loggedIn = checkLoginStatus(request, response);
|
boolean loggedIn = checkLoginStatus(request);
|
||||||
if( !loggedIn){
|
if( !loggedIn){
|
||||||
doError(response,"You must be logged in to use this servlet.",HttpStatus.SC_UNAUTHORIZED);
|
doError(response,"You must be logged in to use this servlet.",HttpStatus.SC_UNAUTHORIZED);
|
||||||
return;
|
return;
|
||||||
|
@ -238,7 +235,7 @@ public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
||||||
Log log = LogFactory.getLog(PrimitiveRdfEdit.class.getName());
|
Log log = LogFactory.getLog(PrimitiveRdfEdit.class.getName());
|
||||||
|
|
||||||
|
|
||||||
static public boolean checkLoginStatus(HttpServletRequest request, HttpServletResponse response){
|
static public boolean checkLoginStatus(HttpServletRequest request){
|
||||||
LoginFormBean loginBean = (LoginFormBean) request.getSession().getAttribute("loginHandler");
|
LoginFormBean loginBean = (LoginFormBean) request.getSession().getAttribute("loginHandler");
|
||||||
if (loginBean == null){
|
if (loginBean == null){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class ReorderController extends PrimitiveRdfEdit {
|
||||||
private static String RANK_PREDICATE_PARAMETER_NAME = "predicate";
|
private static String RANK_PREDICATE_PARAMETER_NAME = "predicate";
|
||||||
private static String INDIVIDUAL_PREDICATE_PARAMETER_NAME = "individuals";
|
private static String INDIVIDUAL_PREDICATE_PARAMETER_NAME = "individuals";
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
||||||
|
|
||||||
//String templateName = "autocompleteResults.ftl";
|
//String templateName = "autocompleteResults.ftl";
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -14,22 +15,22 @@ import freemarker.template.Configuration;
|
||||||
public class AboutController extends FreemarkerHttpServlet {
|
public class AboutController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(AboutController.class.getName());
|
private static final Log log = LogFactory.getLog(AboutController.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
Portal portal = vreq.getPortal();
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
body.put("aboutText", portal.getAboutText());
|
||||||
|
body.put("acknowledgeText", portal.getAcknowledgeText());
|
||||||
|
|
||||||
|
return new TemplateResponseValues("about.ftl", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String getTitle(String siteName) {
|
protected String getTitle(String siteName) {
|
||||||
return "About " + siteName;
|
return "About " + siteName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
|
||||||
|
|
||||||
Portal portal = vreq.getPortal();
|
|
||||||
|
|
||||||
body.put("aboutText", portal.getAboutText());
|
|
||||||
body.put("acknowledgeText", portal.getAcknowledgeText());
|
|
||||||
|
|
||||||
String bodyTemplate = "about.ftl";
|
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||||
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;
|
||||||
|
@ -69,13 +71,15 @@ public class BrowseController extends FreemarkerHttpServlet {
|
||||||
_cacheRebuildThread.informOfQueueChange();
|
_cacheRebuildThread.informOfQueueChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String getTitle(String siteName) {
|
protected String getTitle(String siteName) {
|
||||||
return "Index to " + siteName + " Contents";
|
return "Index to " + siteName + " Contents";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
String bodyTemplate = "classGroups.ftl";
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
String message = null;
|
String message = null;
|
||||||
|
|
||||||
if( vreq.getParameter("clearcache") != null ) //mainly for debugging
|
if( vreq.getParameter("clearcache") != null ) //mainly for debugging
|
||||||
|
@ -103,7 +107,7 @@ public class BrowseController extends FreemarkerHttpServlet {
|
||||||
body.put("message", message);
|
body.put("message", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
return new TemplateResponseValues("classGroups.ftl", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
|
|
|
@ -19,6 +19,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
|
@ -31,27 +33,30 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(ContactFormController.class.getName());
|
private static final Log log = LogFactory.getLog(ContactFormController.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String getTitle(String siteName) {
|
protected String getTitle(String siteName) {
|
||||||
return siteName + " Feedback Form";
|
return siteName + " Feedback Form";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
String bodyTemplate;
|
String templateName;
|
||||||
Portal portal = vreq.getPortal();
|
Portal portal = vreq.getPortal();
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
if (!ContactMailServlet.isSmtpHostConfigured()) {
|
if (!ContactMailServlet.isSmtpHostConfigured()) {
|
||||||
body.put("errorMessage",
|
body.put("errorMessage",
|
||||||
"This application has not yet been configured to send mail. " +
|
"This application has not yet been configured to send mail. " +
|
||||||
"An smtp host has not been specified in the configuration properties file.");
|
"An smtp host has not been specified in the configuration properties file.");
|
||||||
bodyTemplate = "contactForm-error.ftl";
|
templateName = "contactForm-error.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (StringUtils.isEmpty(portal.getContactMail())) {
|
else if (StringUtils.isEmpty(portal.getContactMail())) {
|
||||||
body.put("errorMessage",
|
body.put("errorMessage",
|
||||||
"The feedback form is currently disabled. In order to activate the form, a site administrator must provide a contact email address in the <a href='editForm?home=1&controller=Portal&id=1'>Site Configuration</a>");
|
"The feedback form is currently disabled. In order to activate the form, a site administrator must provide a contact email address in the <a href='editForm?home=1&controller=Portal&id=1'>Site Configuration</a>");
|
||||||
|
|
||||||
bodyTemplate = "contactForm-error.ftl";
|
templateName = "contactForm-error.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -84,9 +89,9 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
||||||
vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer"));
|
vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyTemplate = "contactForm-form.ftl";
|
templateName = "contactForm-form.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
return new TemplateResponseValues(templateName, body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
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.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
public class ContactMailController extends FreemarkerHttpServlet {
|
public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
|
@ -66,14 +67,18 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
return (host != null && host.length() > 0) ? host : null;
|
return (host != null && host.length() > 0) ? host : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String getTitle(String siteName) {
|
protected String getTitle(String siteName) {
|
||||||
return siteName + " Feedback Form";
|
return siteName + " Feedback Form";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
Portal portal = vreq.getPortal();
|
Portal portal = vreq.getPortal();
|
||||||
String bodyTemplate = null;
|
String templateName = null;
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
String statusMsg = null; // holds the error status
|
String statusMsg = null; // holds the error status
|
||||||
|
|
||||||
|
@ -81,7 +86,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
body.put("errorMessage",
|
body.put("errorMessage",
|
||||||
"This application has not yet been configured to send mail. " +
|
"This application has not yet been configured to send mail. " +
|
||||||
"An smtp host has not been specified in the configuration properties file.");
|
"An smtp host has not been specified in the configuration properties file.");
|
||||||
bodyTemplate = "contactForm-error.ftl";
|
templateName = "contactForm-error.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -97,7 +102,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
// rjy7 We should reload the form, not go to the error page!
|
// rjy7 We should reload the form, not go to the error page!
|
||||||
body.put("errorMessage",
|
body.put("errorMessage",
|
||||||
"Invalid submission");
|
"Invalid submission");
|
||||||
bodyTemplate = "contactForm-error.ftl";
|
templateName = "contactForm-error.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -159,6 +164,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
+ "specify at least one email address in the current portal.");
|
+ "specify at least one email address in the current portal.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Configuration config = (Configuration) vreq.getAttribute("freemarkerConfig");
|
||||||
String msgText = composeEmail(webusername, webuseremail, comments,
|
String msgText = composeEmail(webusername, webuseremail, comments,
|
||||||
deliveryfrom, originalReferer, vreq.getRemoteAddr(), config);
|
deliveryfrom, originalReferer, vreq.getRemoteAddr(), config);
|
||||||
|
|
||||||
|
@ -204,15 +210,15 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
// Message was sent successfully
|
// Message was sent successfully
|
||||||
if (statusMsg == null && spamReason == null) {
|
if (statusMsg == null && spamReason == null) {
|
||||||
bodyTemplate = "contactForm-confirmation.ftl";
|
templateName = "contactForm-confirmation.ftl";
|
||||||
} else {
|
} else {
|
||||||
body.put("errorMessage", statusMsg);
|
body.put("errorMessage", statusMsg);
|
||||||
bodyTemplate = "contactForm-error.ftl";
|
templateName = "contactForm-error.ftl";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
return new TemplateResponseValues(templateName, body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +247,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
email.put("referrer", UrlBuilder.urlDecode(originalReferer));
|
email.put("referrer", UrlBuilder.urlDecode(originalReferer));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate(template, email, config);
|
return mergeMapToTemplate(template, email, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeBackupCopy(PrintWriter outFile, String msgText,
|
private void writeBackupCopy(PrintWriter outFile, String msgText,
|
||||||
|
@ -259,7 +265,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
backup.put("msgText", msgText);
|
backup.put("msgText", msgText);
|
||||||
|
|
||||||
String backupText = mergeBodyToTemplate(template, backup, config);
|
String backupText = mergeMapToTemplate(template, backup, config);
|
||||||
outFile.print(backupText);
|
outFile.print(backupText);
|
||||||
outFile.flush();
|
outFile.flush();
|
||||||
//outFile.close();
|
//outFile.close();
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class FreemarkerHelper {
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String mergeMapToTemplate(String templateName, Map<String, Object> map) {
|
public String mergeMapToTemplate(String templateName, Map<String, Object> map) {
|
||||||
return mergeToTemplate(templateName, map).toString();
|
return mergeToTemplate(templateName, map).toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -63,25 +64,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
Configuration config = getConfig(vreq);
|
Configuration config = getConfig(vreq);
|
||||||
vreq.setAttribute("freemarkerConfig", config);
|
vreq.setAttribute("freemarkerConfig", config);
|
||||||
|
|
||||||
// We can't use shared variables in the Freemarker configuration to store anything
|
ResponseValues responseValues = processRequest(vreq);
|
||||||
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
doResponse(vreq, response, responseValues);
|
||||||
// just put the shared variables in both root and body.
|
|
||||||
Map<String, Object> sharedVariables = getSharedVariables(vreq); // start by getting the title here
|
|
||||||
|
|
||||||
// root is the map used to create the page shell - header, footer, menus, etc.
|
|
||||||
Map<String, Object> root = new HashMap<String, Object>(sharedVariables);
|
|
||||||
|
|
||||||
// body is the map used to create the page body
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>(sharedVariables);
|
|
||||||
|
|
||||||
setUpRoot(vreq, root);
|
|
||||||
root.put("body", getBody(vreq, body, config)); // need config to get and process template
|
|
||||||
|
|
||||||
// getBody() may have changed the title, so put the new value in the root map. (E.g., the title may
|
|
||||||
// include an individual's name, which is only discovered when processing the body.)
|
|
||||||
root.put("title", body.get("title"));
|
|
||||||
|
|
||||||
writePage(root, config, response);
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("FreeMarkerHttpServlet could not forward to view.", e);
|
log.error("FreeMarkerHttpServlet could not forward to view.", e);
|
||||||
|
@ -94,7 +78,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Configuration getConfig(VitroRequest vreq) {
|
protected Configuration getConfig(VitroRequest vreq) {
|
||||||
|
|
||||||
String themeDir = getThemeDir(vreq.getPortal());
|
String themeDir = getThemeDir(vreq.getPortal());
|
||||||
return getConfigForTheme(themeDir);
|
return getConfigForTheme(themeDir);
|
||||||
}
|
}
|
||||||
|
@ -106,9 +89,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
// load templates from. Thus configurations are associated with themes rather than portals.
|
// load templates from. Thus configurations are associated with themes rather than portals.
|
||||||
Map<String, Configuration> themeToConfigMap = (Map<String, Configuration>) (getServletContext().getAttribute("themeToConfigMap"));
|
Map<String, Configuration> themeToConfigMap = (Map<String, Configuration>) (getServletContext().getAttribute("themeToConfigMap"));
|
||||||
|
|
||||||
if( themeToConfigMap == null )
|
if( themeToConfigMap == null ) {
|
||||||
log.error("The templating system is not configured correctly. Make sure that you have the FreemarkerSetup context listener in your web.xml");
|
log.error("The templating system is not configured correctly. Make sure that you have the FreemarkerSetup context listener in your web.xml.");
|
||||||
if (themeToConfigMap.containsKey(themeDir)) {
|
return null; // RY should we throw an error here instead?
|
||||||
|
} else if (themeToConfigMap.containsKey(themeDir)) {
|
||||||
return themeToConfigMap.get(themeDir);
|
return themeToConfigMap.get(themeDir);
|
||||||
} else {
|
} else {
|
||||||
Configuration config = getNewConfig(themeDir);
|
Configuration config = getNewConfig(themeDir);
|
||||||
|
@ -192,6 +176,105 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subclasses will override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doResponse(VitroRequest vreq, HttpServletResponse response, ResponseValues values) {
|
||||||
|
try {
|
||||||
|
// switch (values.getType()) {
|
||||||
|
// case TEMPLATE:
|
||||||
|
// doTemplate(vreq, response, values);
|
||||||
|
// break;
|
||||||
|
// case REDIRECT:
|
||||||
|
// doRedirect(vreq, response, values);
|
||||||
|
// break;
|
||||||
|
// case FORWARD:
|
||||||
|
// doForward(vreq, response, values);
|
||||||
|
// break;
|
||||||
|
// case EXCEPTION:
|
||||||
|
// doException(vreq, response, values);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// RY Discuss with Jim - doing this instead of the switch allows us to get rid of the
|
||||||
|
// type field. We could also cast the values to the appropriate type: e.g.,
|
||||||
|
// doException(vreq, response, (ExceptionResponseValues) values
|
||||||
|
// then method signature is doException(VitroRequest vreq, HttpServletResponse response, ExceptionResponseValues values)
|
||||||
|
// which seems to make more sense
|
||||||
|
if (values instanceof ExceptionResponseValues) {
|
||||||
|
doException(vreq, response, values);
|
||||||
|
} else if (values instanceof TemplateResponseValues) {
|
||||||
|
doTemplate(vreq, response, values);
|
||||||
|
} else if (values instanceof RedirectResponseValues) {
|
||||||
|
doRedirect(vreq, response, values);
|
||||||
|
} else if (values instanceof ForwardResponseValues) {
|
||||||
|
doForward(vreq, response, values);
|
||||||
|
}
|
||||||
|
} catch (ServletException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// RY *** A lot of this is shared with doException(). Factor out shared parts.
|
||||||
|
protected void doTemplate(VitroRequest vreq, HttpServletResponse response, ResponseValues values) {
|
||||||
|
|
||||||
|
Configuration config = getConfig(vreq);
|
||||||
|
|
||||||
|
// We can't use shared variables in the Freemarker configuration to store anything
|
||||||
|
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
||||||
|
// just put the shared variables in both root and body.
|
||||||
|
Map<String, Object> sharedVariables = getSharedVariables(vreq);
|
||||||
|
|
||||||
|
// root is the map used to create the page shell - header, footer, menus, etc.
|
||||||
|
Map<String, Object> root = new HashMap<String, Object>(sharedVariables);
|
||||||
|
|
||||||
|
// body is the map used to create the page body
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>(sharedVariables);
|
||||||
|
setUpRoot(vreq, root);
|
||||||
|
|
||||||
|
// Add the values that we got, and merge to the template.
|
||||||
|
body.putAll(values.getMap());
|
||||||
|
root.put("body", mergeMapToTemplate(values.getTemplateName(), body, config));
|
||||||
|
|
||||||
|
// Subclass processing may have changed the title, so put the new value in the root map. (E.g., the title may
|
||||||
|
// include an individual's name, which is only discovered when processing the body.)
|
||||||
|
root.put("title", body.get("title"));
|
||||||
|
|
||||||
|
writePage(root, config, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doRedirect(HttpServletRequest request, HttpServletResponse response, ResponseValues values)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
String redirectUrl = values.getRedirectUrl();
|
||||||
|
response.sendRedirect(redirectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doForward(HttpServletRequest request, HttpServletResponse response, ResponseValues values)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
String forwardUrl = values.getForwardUrl();
|
||||||
|
if (forwardUrl.contains("://")) {
|
||||||
|
// It's a full URL, so redirect.
|
||||||
|
response.sendRedirect(forwardUrl);
|
||||||
|
} else {
|
||||||
|
// It's a relative URL, so forward within the application.
|
||||||
|
request.getRequestDispatcher(forwardUrl).forward(request, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doException(VitroRequest vreq, HttpServletResponse response, ResponseValues values) {
|
||||||
|
// Log the error, and display an error message on the page.
|
||||||
|
log.error(values.getException(), values.getException());
|
||||||
|
TemplateResponseValues trv = new TemplateResponseValues(values.getTemplateName(), values.getMap());
|
||||||
|
doTemplate(vreq, response, trv);
|
||||||
|
}
|
||||||
|
|
||||||
// We can't use shared variables in the Freemarker configuration to store anything
|
// We can't use shared variables in the Freemarker configuration to store anything
|
||||||
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
||||||
// we'll get all the shared variables here, and put them in both root and body maps.
|
// we'll get all the shared variables here, and put them in both root and body maps.
|
||||||
|
@ -377,23 +460,25 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
return siteName;
|
return siteName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Most subclasses will override. Some (e.g., ajax controllers) don't need to define a page body.
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected StringWriter mergeToTemplate(String templateName, Map<String, Object> map, Configuration config) {
|
protected StringWriter mergeToTemplate(String templateName, Map<String, Object> map, Configuration config) {
|
||||||
FreemarkerHelper helper = new FreemarkerHelper(config);
|
FreemarkerHelper helper = new FreemarkerHelper(config);
|
||||||
return helper.mergeToTemplate(templateName, map);
|
return helper.mergeToTemplate(templateName, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String mergeBodyToTemplate(String templateName, Map<String, Object> map, Configuration config) {
|
protected StringWriter mergeToTemplate(ResponseValues values, Configuration config) {
|
||||||
|
return mergeToTemplate(values.getTemplateName(), values.getMap(), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String mergeMapToTemplate(String templateName, Map<String, Object> map, Configuration config) {
|
||||||
return mergeToTemplate(templateName, map, config).toString();
|
return mergeToTemplate(templateName, map, config).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String mergeResponseValuesToTemplate(ResponseValues values, Configuration config) {
|
||||||
|
return mergeMapToTemplate(values.getTemplateName(), values.getMap(), config);
|
||||||
|
}
|
||||||
|
|
||||||
protected void writePage(Map<String, Object> root, Configuration config, HttpServletResponse response) {
|
protected void writePage(Map<String, Object> root, Configuration config, HttpServletResponse response) {
|
||||||
String templateName = getPageTemplateName();
|
writeTemplate(getPageTemplateName(), root, config, response);
|
||||||
writeTemplate(templateName, root, config, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeTemplate(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
|
protected void writeTemplate(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
|
||||||
|
@ -424,4 +509,215 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
||||||
new FreemarkerComponentGenerator(request);
|
new FreemarkerComponentGenerator(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static interface ResponseValues {
|
||||||
|
// enum ResponseType {
|
||||||
|
// TEMPLATE, REDIRECT, FORWARD, EXCEPTION
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// ResponseType getType();
|
||||||
|
|
||||||
|
String getTemplateName();
|
||||||
|
|
||||||
|
Map<String, Object> getMap();
|
||||||
|
|
||||||
|
String getRedirectUrl();
|
||||||
|
|
||||||
|
String getForwardUrl();
|
||||||
|
|
||||||
|
Throwable getException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class TemplateResponseValues implements ResponseValues {
|
||||||
|
private final String templateName;
|
||||||
|
private final Map<String, Object> map;
|
||||||
|
|
||||||
|
public TemplateResponseValues(String templateName) {
|
||||||
|
this.templateName = templateName;
|
||||||
|
this.map = new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateResponseValues(String templateName, Map<String, Object> map) {
|
||||||
|
this.templateName = templateName;
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TemplateResponseValues put(String key, Object value) {
|
||||||
|
this.map.put(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public ResponseType getType() {
|
||||||
|
// return ResponseType.TEMPLATE;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMap() {
|
||||||
|
return Collections.unmodifiableMap(this.map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
return this.templateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a redirect response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getForwardUrl() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a forwarding response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Throwable getException() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not an exception response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class RedirectResponseValues implements ResponseValues {
|
||||||
|
private final String redirectUrl;
|
||||||
|
|
||||||
|
public RedirectResponseValues(String redirectUrl) {
|
||||||
|
this.redirectUrl = redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public ResponseType getType() {
|
||||||
|
// return ResponseType.REDIRECT;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
return this.redirectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a template response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMap() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a template response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getForwardUrl() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a forwarding response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Throwable getException() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not an exception response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class ForwardResponseValues implements ResponseValues {
|
||||||
|
private final String forwardUrl;
|
||||||
|
|
||||||
|
public ForwardResponseValues(String forwardUrl) {
|
||||||
|
this.forwardUrl = forwardUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public ResponseType getType() {
|
||||||
|
// return ResponseType.FORWARD;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getForwardUrl() {
|
||||||
|
return this.forwardUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a template response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMap() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a template response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a redirect response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Throwable getException() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not an exception response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class ExceptionResponseValues extends TemplateResponseValues {
|
||||||
|
private final static String DEFAULT_TEMPLATE_NAME = "error.ftl";
|
||||||
|
private final Throwable cause;
|
||||||
|
|
||||||
|
public ExceptionResponseValues(Throwable cause) {
|
||||||
|
super(DEFAULT_TEMPLATE_NAME);
|
||||||
|
this.cause = cause;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExceptionResponseValues(String templateName, Throwable cause) {
|
||||||
|
super(templateName);
|
||||||
|
this.cause = cause;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExceptionResponseValues(String templateName, Map<String, Object> map, Throwable cause) {
|
||||||
|
super(templateName, map);
|
||||||
|
this.cause = cause;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public ResponseType getType() {
|
||||||
|
// return ResponseType.EXCEPTION;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Throwable getException() {
|
||||||
|
return cause;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTemplateName() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a template response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMap() {
|
||||||
|
throw new IllegalStateException("This is not a template response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRedirectUrl() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a redirect response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getForwardUrl() {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"This is not a forwarding response.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -25,6 +25,8 @@ public class FreemarkerSetup implements ServletContextListener {
|
||||||
BaseTemplateModel.setServletContext(sc);
|
BaseTemplateModel.setServletContext(sc);
|
||||||
FreemarkerComponentGenerator.setServletContext(sc);
|
FreemarkerComponentGenerator.setServletContext(sc);
|
||||||
UrlBuilder.contextPath = sc.getContextPath();
|
UrlBuilder.contextPath = sc.getContextPath();
|
||||||
|
|
||||||
|
log.info("Freemarker templating system initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void contextDestroyed(ServletContextEvent event) {
|
public void contextDestroyed(ServletContextEvent event) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -41,6 +40,10 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAct
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.ImageUploadHelper;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
||||||
|
@ -160,94 +163,31 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws IOException, ServletException {
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
try {
|
try {
|
||||||
// Parse the multi-part request.
|
// Parse the multi-part request.
|
||||||
request = FileUploadServletRequest.parseRequest(request,
|
FileUploadServletRequest request = FileUploadServletRequest.parseRequest(vreq,
|
||||||
MAXIMUM_FILE_SIZE);
|
MAXIMUM_FILE_SIZE);
|
||||||
if (log.isTraceEnabled()) {
|
if (log.isTraceEnabled()) {
|
||||||
dumpRequestDetails(request);
|
dumpRequestDetails(vreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do setup defined in VitroHttpServlet
|
|
||||||
setup(request);
|
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
|
||||||
|
|
||||||
// If they aren't authorized to do this, send them to login.
|
// If they aren't authorized to do this, send them to login.
|
||||||
if (!checkAuthorized(vreq)) {
|
if (!checkAuthorized(vreq)) {
|
||||||
String loginPage = request.getContextPath() + Controllers.LOGIN;
|
String loginPage = request.getContextPath() + Controllers.LOGIN;
|
||||||
response.sendRedirect(loginPage);
|
return new RedirectResponseValues(loginPage);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseValues values = buildTheResponse(vreq);
|
return buildTheResponse(vreq);
|
||||||
|
|
||||||
switch (values.getType()) {
|
|
||||||
case FORWARD:
|
|
||||||
doForward(vreq, response, values);
|
|
||||||
break;
|
|
||||||
case TEMPLATE:
|
|
||||||
doTemplate(vreq, response, values);
|
|
||||||
break;
|
|
||||||
case EXCEPTION:
|
|
||||||
doException(vreq, response, values);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Could not produce response page", e);
|
//log.error("Could not produce response page", e);
|
||||||
|
return new ExceptionResponseValues(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* We processed a response, and want to show a template.
|
|
||||||
*/
|
|
||||||
private void doTemplate(VitroRequest vreq, HttpServletResponse response,
|
|
||||||
ResponseValues values) {
|
|
||||||
// Set it up like FreeMarkerHttpServlet.doGet() would do.
|
|
||||||
Configuration config = getConfig(vreq);
|
|
||||||
Map<String, Object> sharedVariables = getSharedVariables(vreq);
|
|
||||||
Map<String, Object> root = new HashMap<String, Object>(sharedVariables);
|
|
||||||
Map<String, Object> body = new HashMap<String, Object>(sharedVariables);
|
|
||||||
setUpRoot(vreq, root);
|
|
||||||
|
|
||||||
// Add the values that we got, and merge to the template.
|
|
||||||
body.putAll(values.getBodyMap());
|
|
||||||
root.put("body",
|
|
||||||
mergeBodyToTemplate(values.getTemplateName(), body, config));
|
|
||||||
|
|
||||||
// Continue to simulate FreeMarkerHttpServlet.doGet()
|
|
||||||
root.put("title", body.get("title"));
|
|
||||||
writePage(root, config, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We processsed a response, and want to forward to another page.
|
|
||||||
*/
|
|
||||||
private void doForward(HttpServletRequest req, HttpServletResponse resp,
|
|
||||||
ResponseValues values) throws ServletException, IOException {
|
|
||||||
String forwardUrl = values.getForwardUrl();
|
|
||||||
if (forwardUrl.contains("://")) {
|
|
||||||
// It's a full URL, so redirect.
|
|
||||||
resp.sendRedirect(forwardUrl);
|
|
||||||
} else {
|
|
||||||
// It's a relative URL, so forward within the application.
|
|
||||||
req.getRequestDispatcher(forwardUrl).forward(req, resp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We processed a response, and need to display an internal exception.
|
|
||||||
*/
|
|
||||||
private void doException(VitroRequest vreq, HttpServletResponse resp,
|
|
||||||
ResponseValues values) {
|
|
||||||
log.error(values.getException(), values.getException());
|
|
||||||
doTemplate(vreq, resp, new TemplateResponseValues(TEMPLATE_ERROR));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the different actions. If not specified, the default action is to
|
* Handle the different actions. If not specified, the default action is to
|
||||||
* show the intro screen.
|
* show the intro screen.
|
||||||
|
@ -658,136 +598,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface ResponseValues {
|
|
||||||
enum ResponseType {
|
|
||||||
TEMPLATE, FORWARD, EXCEPTION
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseType getType();
|
|
||||||
|
|
||||||
String getTemplateName();
|
|
||||||
|
|
||||||
Map<? extends String, ? extends Object> getBodyMap();
|
|
||||||
|
|
||||||
String getForwardUrl();
|
|
||||||
|
|
||||||
Throwable getException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TemplateResponseValues implements ResponseValues {
|
|
||||||
private final String templateName;
|
|
||||||
private final Map<String, Object> bodyMap = new HashMap<String, Object>();
|
|
||||||
|
|
||||||
public TemplateResponseValues(String templateName) {
|
|
||||||
this.templateName = templateName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateResponseValues put(String key, Object value) {
|
|
||||||
this.bodyMap.put(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResponseType getType() {
|
|
||||||
return ResponseType.TEMPLATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<? extends String, ? extends Object> getBodyMap() {
|
|
||||||
return Collections.unmodifiableMap(this.bodyMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTemplateName() {
|
|
||||||
return this.templateName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Throwable getException() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not an exception response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getForwardUrl() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not a forwarding response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ForwardResponseValues implements ResponseValues {
|
|
||||||
private final String forwardUrl;
|
|
||||||
|
|
||||||
public ForwardResponseValues(String forwardUrl) {
|
|
||||||
this.forwardUrl = forwardUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResponseType getType() {
|
|
||||||
return ResponseType.FORWARD;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getForwardUrl() {
|
|
||||||
return this.forwardUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTemplateName() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not a template response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<? extends String, ? extends Object> getBodyMap() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not a template response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Throwable getException() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not an exception response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ExceptionResponseValues implements ResponseValues {
|
|
||||||
private final Throwable cause;
|
|
||||||
|
|
||||||
public ExceptionResponseValues(Throwable cause) {
|
|
||||||
this.cause = cause;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResponseType getType() {
|
|
||||||
return ResponseType.EXCEPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Throwable getException() {
|
|
||||||
return cause;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTemplateName() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not a template response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<? extends String, ? extends Object> getBodyMap() {
|
|
||||||
throw new IllegalStateException("This is not a template response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getForwardUrl() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This is not a forwarding response.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If they are logged in as an Editor or better, they can do whatever they
|
* If they are logged in as an Editor or better, they can do whatever they
|
||||||
|
|
|
@ -44,6 +44,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
||||||
|
@ -74,7 +75,8 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
private ApplicationBean appBean;
|
private ApplicationBean appBean;
|
||||||
|
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
HttpSession session = vreq.getSession();
|
HttpSession session = vreq.getSession();
|
||||||
|
@ -92,13 +94,13 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") );
|
String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") );
|
||||||
if( redirectURL != null ){
|
if( redirectURL != null ){
|
||||||
//doRedirect( vreq, res, redirectURL );
|
//doRedirect( vreq, res, redirectURL );
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
|
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
|
||||||
if( rdfFormat != null ){
|
if( rdfFormat != null ){
|
||||||
//doRdf( vreq, res, rdfFormat );
|
//doRdf( vreq, res, rdfFormat );
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Individual individual = null;
|
Individual individual = null;
|
||||||
|
@ -106,21 +108,22 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
individual = getEntityFromRequest( vreq);
|
individual = getEntityFromRequest( vreq);
|
||||||
}catch(Throwable th){
|
}catch(Throwable th){
|
||||||
//doHelp(res);
|
//doHelp(res);
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
|
if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
|
||||||
//doNotFound(vreq, res);
|
//doNotFound(vreq, res);
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is an uploaded file, redirect to its "alias URL".
|
// If this is an uploaded file, redirect to its "alias URL".
|
||||||
String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, individual);
|
String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, individual);
|
||||||
if (aliasUrl != null) {
|
if (aliasUrl != null) {
|
||||||
//res.sendRedirect(vreq.getContextPath() + aliasUrl);
|
//res.sendRedirect(vreq.getContextPath() + aliasUrl);
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
int securityLevel = getSecurityLevel(session);
|
int securityLevel = getSecurityLevel(session);
|
||||||
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
|
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
|
||||||
|
@ -128,15 +131,11 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
body.putAll(getIndividualData(vreq, individual));
|
body.putAll(getIndividualData(vreq, individual));
|
||||||
body.put("title", individual.getName());
|
body.put("title", individual.getName());
|
||||||
|
|
||||||
String bodyTemplate = "individual.ftl";
|
return new TemplateResponseValues("individual.ftl", body);
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
//vreq.setAttribute("javax.servlet.jsp.jspException",e);
|
return new ExceptionResponseValues(e);
|
||||||
// RequestDispatcher rd = vreq.getRequestDispatcher("/error.jsp");
|
|
||||||
//rd.forward(vreq, res);
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.IndividualTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.IndividualTemplateModel;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
@ -28,9 +29,11 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
||||||
// private VClass vclass = null;
|
// private VClass vclass = null;
|
||||||
// private String title = null;
|
// private String title = null;
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
String bodyTemplate = "individualList.ftl";
|
String templateName = "individualList.ftl";
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
String message = null;
|
String message = null;
|
||||||
|
|
||||||
|
@ -90,17 +93,17 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
||||||
} catch (HelpException help){
|
} catch (HelpException help){
|
||||||
errorMessage = "Request attribute 'vclass' or request parameter 'vclassId' must be set before calling. Its value must be a class uri.";
|
errorMessage = "Request attribute 'vclass' or request parameter 'vclassId' must be set before calling. Its value must be a class uri.";
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
bodyTemplate = "error.ftl";
|
return new ExceptionResponseValues(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorMessage != null) {
|
if (errorMessage != null) {
|
||||||
bodyTemplate = "errorMessage.ftl";
|
templateName = "errorMessage.ftl";
|
||||||
body.put("errorMessage", errorMessage);
|
body.put("errorMessage", errorMessage);
|
||||||
} else if (message != null) {
|
} else if (message != null) {
|
||||||
body.put("message", message);
|
body.put("message", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
return new TemplateResponseValues(templateName, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HelpException extends Throwable {
|
private class HelpException extends Throwable {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ public class NavigationController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
OntModel displayOntModel = (OntModel)getServletContext().getAttribute("displayOntModel");
|
OntModel displayOntModel = (OntModel)getServletContext().getAttribute("displayOntModel");
|
||||||
OntModel jenaOntModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
OntModel jenaOntModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||||
|
|
||||||
|
@ -56,7 +57,7 @@ public class NavigationController extends FreemarkerHttpServlet {
|
||||||
Map<String,Object> values = getValues(ind, displayOntModel,jenaOntModel, getValuesFromRequest(/*?*/) );
|
Map<String,Object> values = getValues(ind, displayOntModel,jenaOntModel, getValuesFromRequest(/*?*/) );
|
||||||
String template = getTemplate(ind, displayOntModel);
|
String template = getTemplate(ind, displayOntModel);
|
||||||
|
|
||||||
return mergeBodyToTemplate(template, values, config);
|
return new TemplateResponseValues(template, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,Object>getValuesFromRequest(){
|
private Map<String,Object>getValuesFromRequest(){
|
||||||
|
|
|
@ -15,6 +15,7 @@ import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
import edu.cornell.mannlib.vedit.util.FormUtils;
|
import edu.cornell.mannlib.vedit.util.FormUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginTemplateHelper;
|
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginTemplateHelper;
|
||||||
|
@ -27,11 +28,13 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(SiteAdminController.class);
|
private static final Log log = LogFactory.getLog(SiteAdminController.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getTitle(String siteName) {
|
public String getTitle(String siteName) {
|
||||||
return siteName + " Site Administration";
|
return siteName + " Site Administration";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
String loginStatus = null;
|
String loginStatus = null;
|
||||||
|
|
||||||
|
@ -40,9 +43,13 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
||||||
loginStatus = loginHandler.getLoginStatus();
|
loginStatus = loginHandler.getLoginStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
// NOT LOGGED IN: just show login form
|
// NOT LOGGED IN: just show login form
|
||||||
if (loginHandler == null || !"authenticated".equals(loginStatus)) {
|
if (loginHandler == null || !"authenticated".equals(loginStatus)) {
|
||||||
body.put("loginPanel", new LoginTemplateHelper(vreq).showLoginPage(vreq, body, config));
|
// Unlike the other panels on this page, we put the data directly in the body, because the templates are also used
|
||||||
|
// by the JSP version, where the data is placed directly in the body map.
|
||||||
|
body.putAll(getLoginPanelData(vreq));
|
||||||
|
|
||||||
// LOGGED IN: show editing options based on user role
|
// LOGGED IN: show editing options based on user role
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,10 +86,24 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
||||||
// }
|
// }
|
||||||
// body.put("languageModeStr", languageMode);
|
// body.put("languageModeStr", languageMode);
|
||||||
|
|
||||||
return mergeBodyToTemplate("siteAdmin-main.ftl", body, config);
|
return new TemplateResponseValues("siteAdmin-main.ftl", body);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> getLoginPanelData(VitroRequest vreq) {
|
||||||
|
Map<String, Object> map = null;
|
||||||
|
// This is somewhat awkward, because we are trying to use the login code with as few modifications as possible
|
||||||
|
// as it was set up for the JSP version as well. We have to unpack the TemplateResponseValues
|
||||||
|
// object and put everything in a map.
|
||||||
|
TemplateResponseValues trv = new LoginTemplateHelper(vreq).showLoginPanel(vreq);
|
||||||
|
if (trv != null) {
|
||||||
|
map = new HashMap<String, Object>();
|
||||||
|
map.putAll(trv.getMap());
|
||||||
|
map.put("loginTemplate", trv.getTemplateName());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Object> getDataInputData(VitroRequest vreq) {
|
private Map<String, Object> getDataInputData(VitroRequest vreq) {
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
|
@ -10,29 +10,33 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
public class TermsOfUseController extends FreemarkerHttpServlet {
|
public class TermsOfUseController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(TermsOfUseController.class.getName());
|
private static final Log log = LogFactory.getLog(TermsOfUseController.class);
|
||||||
|
|
||||||
protected String getTitle(String siteName) {
|
|
||||||
return siteName + " Terms of Use";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
Portal portal = vreq.getPortal();
|
Portal portal = vreq.getPortal();
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
String rootBreadCrumbAnchor = portal.getRootBreadCrumbAnchor();
|
String rootBreadCrumbAnchor = portal.getRootBreadCrumbAnchor();
|
||||||
String websiteName = StringUtils.isEmpty(rootBreadCrumbAnchor) ? portal.getAppName() : rootBreadCrumbAnchor;
|
String websiteName = StringUtils.isEmpty(rootBreadCrumbAnchor) ? portal.getAppName() : rootBreadCrumbAnchor;
|
||||||
|
|
||||||
body.put("websiteName", websiteName);
|
body.put("websiteName", websiteName);
|
||||||
|
|
||||||
body.put("copyrightAnchor", portal.getCopyrightAnchor());
|
body.put("copyrightAnchor", portal.getCopyrightAnchor());
|
||||||
|
|
||||||
String bodyTemplate = "termsOfUse.ftl";
|
return new TemplateResponseValues("termsOfUse.ftl", body);
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTitle(String siteName) {
|
||||||
|
return siteName + " Terms of Use";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,10 @@ import java.util.Map;
|
||||||
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 edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,12 +28,11 @@ public class TestController extends FreemarkerHttpServlet {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(TestController.class);
|
private static final Log log = LogFactory.getLog(TestController.class);
|
||||||
|
|
||||||
protected String getTitle() {
|
@Override
|
||||||
return "Test";
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
}
|
Portal portal = vreq.getPortal();
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
// Test of #list directive in template on undefined, null, and empty values.
|
// Test of #list directive in template on undefined, null, and empty values.
|
||||||
// Basic idea: empty list okay, null or undefined value not okay.
|
// Basic idea: empty list okay, null or undefined value not okay.
|
||||||
List<String> apples = new ArrayList<String>(); // no error
|
List<String> apples = new ArrayList<String>(); // no error
|
||||||
|
@ -86,9 +88,21 @@ public class TestController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
body.put("title", "VIVO Test");
|
body.put("title", "VIVO Test");
|
||||||
|
|
||||||
|
return new TemplateResponseValues("test.ftl", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTitle(String siteName) {
|
||||||
|
return "Test";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create the template to see the examples live.
|
// Create the template to see the examples live.
|
||||||
String bodyTemplate = "test.ftl";
|
String bodyTemplate = "test.ftl";
|
||||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
return mergeMapToTemplate(bodyTemplate, body, config);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,23 +77,26 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Version for Freemarker page */
|
/** Version for Freemarker page */
|
||||||
public String showLoginPage(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
public TemplateResponseValues showLoginPanel(VitroRequest vreq) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
State state = getCurrentLoginState(vreq);
|
State state = getCurrentLoginState(vreq);
|
||||||
log.debug("State on exit: " + state);
|
log.debug("State on exit: " + state);
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
// RY Why does this case exist? We don't call this method if a user is logged in.
|
||||||
case LOGGED_IN:
|
case LOGGED_IN:
|
||||||
return "";
|
return null;
|
||||||
case FORCED_PASSWORD_CHANGE:
|
case FORCED_PASSWORD_CHANGE:
|
||||||
return doTemplate(vreq, showPasswordChangeScreen(vreq), body, config);
|
//return doTemplate(vreq, showPasswordChangeScreen(vreq), body, config);
|
||||||
|
return showPasswordChangeScreen(vreq);
|
||||||
default:
|
default:
|
||||||
return doTemplate(vreq, showLoginScreen(vreq), body, config);
|
//return doTemplate(vreq, showLoginScreen(vreq), body, config);
|
||||||
|
return showLoginScreen(vreq);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
return doTemplate(vreq, showError(vreq, e), body, config);
|
return showError(vreq, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +124,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
||||||
if (!errorMessage.isEmpty()) {
|
if (!errorMessage.isEmpty()) {
|
||||||
trv.put(BODY_ERROR_MESSAGE, errorMessage);
|
trv.put(BODY_ERROR_MESSAGE, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return trv;
|
return trv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,20 +169,10 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
||||||
setUpRoot(vreq, root);
|
setUpRoot(vreq, root);
|
||||||
|
|
||||||
// Add the values that we got, and merge to the template.
|
// Add the values that we got, and merge to the template.
|
||||||
body.putAll(values.getBodyMap());
|
body.putAll(values.getMap());
|
||||||
return mergeBodyToTemplate(values.getTemplateName(), body, config);
|
return mergeMapToTemplate(values.getTemplateName(), body, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* We processed a response, and want to show a template.
|
|
||||||
* Version for Freemarker page.
|
|
||||||
*/
|
|
||||||
private String doTemplate(VitroRequest vreq, TemplateResponseValues values, Map<String, Object> body, Configuration config) {
|
|
||||||
|
|
||||||
// Add the values that we got, and merge to the template.
|
|
||||||
body.putAll(values.getBodyMap());
|
|
||||||
return mergeBodyToTemplate(values.getTemplateName(), body, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where are we in the process? Logged in? Not? Somewhere in between?
|
* Where are we in the process? Logged in? Not? Somewhere in between?
|
||||||
|
@ -240,29 +234,4 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
||||||
return portalIdParameter;
|
return portalIdParameter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds the name of the template and the map of values.
|
|
||||||
*/
|
|
||||||
private static class TemplateResponseValues {
|
|
||||||
private final String templateName;
|
|
||||||
private final Map<String, Object> bodyMap = new HashMap<String, Object>();
|
|
||||||
|
|
||||||
public TemplateResponseValues(String templateName) {
|
|
||||||
this.templateName = templateName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TemplateResponseValues put(String key, Object value) {
|
|
||||||
this.bodyMap.put(key, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<? extends String, ? extends Object> getBodyMap() {
|
|
||||||
return Collections.unmodifiableMap(this.bodyMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTemplateName() {
|
|
||||||
return this.templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,11 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Portal portal = vreq.getPortal();
|
Portal portal = vreq.getPortal();
|
||||||
|
@ -116,7 +120,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
if( vreq.getWebappDaoFactory() == null
|
if( vreq.getWebappDaoFactory() == null
|
||||||
|| vreq.getWebappDaoFactory().getIndividualDao() == null ){
|
|| vreq.getWebappDaoFactory().getIndividualDao() == null ){
|
||||||
log.error("makeUsableBeans() could not get IndividualDao ");
|
log.error("makeUsableBeans() could not get IndividualDao ");
|
||||||
return doSearchError("Could not access Model.", config);
|
return doSearchError("Could not access Model.");
|
||||||
}
|
}
|
||||||
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
|
IndividualDao iDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||||
VClassGroupDao grpDao = vreq.getWebappDaoFactory().getVClassGroupDao();
|
VClassGroupDao grpDao = vreq.getWebappDaoFactory().getVClassGroupDao();
|
||||||
|
@ -153,7 +157,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
log.debug("query for '" + qtxt +"' is " + query.toString());
|
log.debug("query for '" + qtxt +"' is " + query.toString());
|
||||||
|
|
||||||
if (query == null ) {
|
if (query == null ) {
|
||||||
return doNoQuery(config, portal);
|
return doNoQuery(portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexSearcher searcherForRequest = getIndexSearcher(indexDir);
|
IndexSearcher searcherForRequest = getIndexSearcher(indexDir);
|
||||||
|
@ -173,19 +177,19 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
msg = "The search request contained errors.";
|
msg = "The search request contained errors.";
|
||||||
}
|
}
|
||||||
return doFailedSearch(msg, qtxt, config);
|
return doFailedSearch(msg, qtxt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( topDocs == null || topDocs.scoreDocs == null){
|
if( topDocs == null || topDocs.scoreDocs == null){
|
||||||
log.error("topDocs for a search was null");
|
log.error("topDocs for a search was null");
|
||||||
String msg = "The search request contained errors.";
|
String msg = "The search request contained errors.";
|
||||||
return doFailedSearch(msg, qtxt, config);
|
return doFailedSearch(msg, qtxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
int hitsLength = topDocs.scoreDocs.length;
|
int hitsLength = topDocs.scoreDocs.length;
|
||||||
if ( hitsLength < 1 ){
|
if ( hitsLength < 1 ){
|
||||||
return doNoHits(qtxt, config);
|
return doNoHits(qtxt);
|
||||||
}
|
}
|
||||||
log.debug("found "+hitsLength+" hits");
|
log.debug("found "+hitsLength+" hits");
|
||||||
|
|
||||||
|
@ -287,11 +291,10 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error(e, e);
|
return doSearchError(e);
|
||||||
return doSearchError(e.getMessage(), config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeBodyToTemplate("search-pagedResults.ftl", body, config);
|
return new TemplateResponseValues("search-pagedResults.ftl", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void alphaSortIndividuals(List<Individual> beans) {
|
private void alphaSortIndividuals(List<Individual> beans) {
|
||||||
|
@ -749,34 +752,40 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doSearchError(String message, Configuration config) {
|
private TemplateResponseValues doSearchError(String message) {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("message", "Search failed: " + message);
|
body.put("message", "Search failed: " + message);
|
||||||
return mergeBodyToTemplate("search-error.ftl", body, config);
|
return new TemplateResponseValues("search-error.ftl", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doNoQuery(Configuration config, Portal portal) {
|
private ExceptionResponseValues doSearchError(Throwable e) {
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
body.put("message", "Search failed: " + e.getMessage());
|
||||||
|
return new ExceptionResponseValues("search-error.ftl", body, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TemplateResponseValues doNoQuery(Portal portal) {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("title", "Search " + portal.getAppName());
|
body.put("title", "Search " + portal.getAppName());
|
||||||
body.put("message", "No query entered.");
|
body.put("message", "No query entered.");
|
||||||
return mergeBodyToTemplate("search-error.ftl", body, config);
|
return new TemplateResponseValues("search-error.ftl", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doFailedSearch(String message, String querytext, Configuration config) {
|
private TemplateResponseValues doFailedSearch(String message, String querytext) {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("title", "Search for '" + querytext + "'");
|
body.put("title", "Search for '" + querytext + "'");
|
||||||
if ( StringUtils.isEmpty(message) ) {
|
if ( StringUtils.isEmpty(message) ) {
|
||||||
message = "Search failed.";
|
message = "Search failed.";
|
||||||
}
|
}
|
||||||
body.put("message", message);
|
body.put("message", message);
|
||||||
return mergeBodyToTemplate("search-error.ftl", body, config);
|
return new TemplateResponseValues("search-error.ftl", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String doNoHits(String querytext, Configuration config) {
|
private TemplateResponseValues doNoHits(String querytext) {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
body.put("title", "Search for '" + querytext + "'");
|
body.put("title", "Search for '" + querytext + "'");
|
||||||
body.put("message", "No matching results.");
|
body.put("message", "No matching results.");
|
||||||
return mergeBodyToTemplate("search-error.ftl", body, config);
|
return new TemplateResponseValues("search-error.ftl", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,23 +2,19 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
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 edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
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.FreemarkerHttpServlet;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
||||||
import freemarker.template.Configuration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts requests to rebuild or update the search index. It uses
|
* Accepts requests to rebuild or update the search index. It uses
|
||||||
|
@ -74,29 +70,31 @@ public class IndexController extends FreemarkerHttpServlet {
|
||||||
// String msg = "Search index complete. Elapsed time " + delta + " msec.";
|
// String msg = "Search index complete. Elapsed time " + delta + " msec.";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
protected String getTitle(String siteName) {
|
protected String getTitle(String siteName) {
|
||||||
return "Full Search Index Rebuild";
|
return "Full Search Index Rebuild";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBody(VitroRequest request, Map<String, Object> body, Configuration config) {
|
@Override
|
||||||
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
|
Object obj = vreq.getSession().getAttribute("loginHandler");
|
||||||
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
Object obj = request.getSession().getAttribute("loginHandler");
|
|
||||||
LoginFormBean loginHandler = null;
|
LoginFormBean loginHandler = null;
|
||||||
if( obj != null && obj instanceof LoginFormBean )
|
if( obj != null && obj instanceof LoginFormBean )
|
||||||
loginHandler = ((LoginFormBean)obj);
|
loginHandler = ((LoginFormBean)obj);
|
||||||
if( loginHandler == null ||
|
if( loginHandler == null ||
|
||||||
! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
||||||
Integer.parseInt(loginHandler.getLoginRole()) <= 5 ){
|
Integer.parseInt(loginHandler.getLoginRole()) <= LoginFormBean.CURATOR ){
|
||||||
|
|
||||||
body.put("message","You must log in to rebuild the search index.");
|
return new RedirectResponseValues(UrlBuilder.getUrl(Route.LOGIN));
|
||||||
return mergeBodyToTemplate("message.ftl", body, config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
// long start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
||||||
if( request.getParameter("update") != null ){
|
if( vreq.getParameter("update") != null ){
|
||||||
builder.doUpdateIndex();
|
builder.doUpdateIndex();
|
||||||
}else{
|
}else{
|
||||||
builder.doIndexRebuild();
|
builder.doIndexRebuild();
|
||||||
|
@ -105,10 +103,10 @@ public class IndexController extends FreemarkerHttpServlet {
|
||||||
} catch (IndexingException e) {
|
} catch (IndexingException e) {
|
||||||
log.error("Error rebuilding search index",e);
|
log.error("Error rebuilding search index",e);
|
||||||
body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage());
|
body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage());
|
||||||
return mergeBodyToTemplate("errorMessage.ftl", body, config);
|
return new ExceptionResponseValues("errorMessage.ftl", body, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
body.put("message","Rebuilding of index started.");
|
body.put("message","Rebuilding of index started.");
|
||||||
return mergeBodyToTemplate("message.ftl", body, config);
|
return new TemplateResponseValues("message.ftl", body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
<#-- Main template for the login panel -->
|
<#-- Main template for the login panel -->
|
||||||
|
|
||||||
<#if loginPanel??>
|
<#if loginTemplate??>
|
||||||
${loginPanel}
|
<#include loginTemplate>
|
||||||
|
|
||||||
${stylesheets.add("/css/login.css")}
|
${stylesheets.add("/css/login.css")}
|
||||||
${stylesheets.addFromTheme("/css/formedit.css")}
|
${stylesheets.addFromTheme("/css/formedit.css")}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue