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 Log log = LogFactory.getLog(PrimitiveDelete.class);
|
||||
|
||||
@Override
|
||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
||||
|
||||
String uriToDelete = vreq.getParameter("deletion");
|
||||
|
|
|
@ -4,10 +4,8 @@ package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
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.dao.jena.DependentResourceDeleteJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Utils;
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
||||
|
||||
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
|
||||
protected String getTitle(String siteName) {
|
||||
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
|
||||
public void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
boolean loggedIn = checkLoginStatus(request, response);
|
||||
boolean loggedIn = checkLoginStatus(request);
|
||||
if( !loggedIn){
|
||||
doError(response,"You must be logged in to use this servlet.",HttpStatus.SC_UNAUTHORIZED);
|
||||
return;
|
||||
|
@ -238,7 +235,7 @@ public class PrimitiveRdfEdit extends FreemarkerHttpServlet{
|
|||
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");
|
||||
if (loginBean == null){
|
||||
return false;
|
||||
|
|
|
@ -29,6 +29,7 @@ public class ReorderController extends PrimitiveRdfEdit {
|
|||
private static String RANK_PREDICATE_PARAMETER_NAME = "predicate";
|
||||
private static String INDIVIDUAL_PREDICATE_PARAMETER_NAME = "individuals";
|
||||
|
||||
@Override
|
||||
protected void processRequest(VitroRequest vreq, HttpServletResponse response) {
|
||||
|
||||
//String templateName = "autocompleteResults.ftl";
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -14,22 +15,22 @@ import freemarker.template.Configuration;
|
|||
public class AboutController extends FreemarkerHttpServlet {
|
||||
|
||||
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) {
|
||||
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.BaseResourceBean.RoleLevel;
|
||||
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.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
@ -68,14 +70,16 @@ public class BrowseController extends FreemarkerHttpServlet {
|
|||
_cacheRebuildThread.start();
|
||||
_cacheRebuildThread.informOfQueueChange();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getTitle(String siteName) {
|
||||
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;
|
||||
|
||||
if( vreq.getParameter("clearcache") != null ) //mainly for debugging
|
||||
|
@ -103,7 +107,7 @@ public class BrowseController extends FreemarkerHttpServlet {
|
|||
body.put("message", message);
|
||||
}
|
||||
|
||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
||||
return new TemplateResponseValues("classGroups.ftl", body);
|
||||
}
|
||||
|
||||
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.Controllers;
|
||||
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 freemarker.template.Configuration;
|
||||
|
||||
|
@ -31,27 +33,30 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
|||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(ContactFormController.class.getName());
|
||||
|
||||
@Override
|
||||
protected String getTitle(String siteName) {
|
||||
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();
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
if (!ContactMailServlet.isSmtpHostConfigured()) {
|
||||
body.put("errorMessage",
|
||||
"This application has not yet been configured to send mail. " +
|
||||
"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())) {
|
||||
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>");
|
||||
|
||||
bodyTemplate = "contactForm-error.ftl";
|
||||
templateName = "contactForm-error.ftl";
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -84,9 +89,9 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
|||
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.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
public class ContactMailController extends FreemarkerHttpServlet {
|
||||
|
@ -66,14 +67,18 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
return (host != null && host.length() > 0) ? host : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle(String siteName) {
|
||||
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();
|
||||
String bodyTemplate = null;
|
||||
String templateName = null;
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
String statusMsg = null; // holds the error status
|
||||
|
||||
|
@ -81,7 +86,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
body.put("errorMessage",
|
||||
"This application has not yet been configured to send mail. " +
|
||||
"An smtp host has not been specified in the configuration properties file.");
|
||||
bodyTemplate = "contactForm-error.ftl";
|
||||
templateName = "contactForm-error.ftl";
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -97,7 +102,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
// rjy7 We should reload the form, not go to the error page!
|
||||
body.put("errorMessage",
|
||||
"Invalid submission");
|
||||
bodyTemplate = "contactForm-error.ftl";
|
||||
templateName = "contactForm-error.ftl";
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -158,7 +163,8 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
"To establish the Contact Us mail capability the system administrators must "
|
||||
+ "specify at least one email address in the current portal.");
|
||||
}
|
||||
|
||||
|
||||
Configuration config = (Configuration) vreq.getAttribute("freemarkerConfig");
|
||||
String msgText = composeEmail(webusername, webuseremail, comments,
|
||||
deliveryfrom, originalReferer, vreq.getRemoteAddr(), config);
|
||||
|
||||
|
@ -204,15 +210,15 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
|
||||
// Message was sent successfully
|
||||
if (statusMsg == null && spamReason == null) {
|
||||
bodyTemplate = "contactForm-confirmation.ftl";
|
||||
templateName = "contactForm-confirmation.ftl";
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
|
||||
return mergeBodyToTemplate(template, email, config);
|
||||
return mergeMapToTemplate(template, email, config);
|
||||
}
|
||||
|
||||
private void writeBackupCopy(PrintWriter outFile, String msgText,
|
||||
|
@ -259,7 +265,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
|
||||
backup.put("msgText", msgText);
|
||||
|
||||
String backupText = mergeBodyToTemplate(template, backup, config);
|
||||
String backupText = mergeMapToTemplate(template, backup, config);
|
||||
outFile.print(backupText);
|
||||
outFile.flush();
|
||||
//outFile.close();
|
||||
|
|
|
@ -45,6 +45,7 @@ public class FreemarkerHelper {
|
|||
}
|
||||
return sw;
|
||||
}
|
||||
|
||||
|
||||
public String mergeMapToTemplate(String templateName, Map<String, Object> map) {
|
||||
return mergeToTemplate(templateName, map).toString();
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -63,25 +64,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
Configuration config = getConfig(vreq);
|
||||
vreq.setAttribute("freemarkerConfig", config);
|
||||
|
||||
// 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); // 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);
|
||||
ResponseValues responseValues = processRequest(vreq);
|
||||
doResponse(vreq, response, responseValues);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error("FreeMarkerHttpServlet could not forward to view.", e);
|
||||
|
@ -93,8 +77,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
doGet(request, response);
|
||||
}
|
||||
|
||||
protected Configuration getConfig(VitroRequest vreq) {
|
||||
|
||||
protected Configuration getConfig(VitroRequest vreq) {
|
||||
String themeDir = getThemeDir(vreq.getPortal());
|
||||
return getConfigForTheme(themeDir);
|
||||
}
|
||||
|
@ -106,9 +89,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
// load templates from. Thus configurations are associated with themes rather than portals.
|
||||
Map<String, Configuration> themeToConfigMap = (Map<String, Configuration>) (getServletContext().getAttribute("themeToConfigMap"));
|
||||
|
||||
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");
|
||||
if (themeToConfigMap.containsKey(themeDir)) {
|
||||
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.");
|
||||
return null; // RY should we throw an error here instead?
|
||||
} else if (themeToConfigMap.containsKey(themeDir)) {
|
||||
return themeToConfigMap.get(themeDir);
|
||||
} else {
|
||||
Configuration config = getNewConfig(themeDir);
|
||||
|
@ -191,6 +175,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
|
||||
// except theme-specific data, because multiple portals or apps might share the same theme. So instead
|
||||
|
@ -376,24 +459,26 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
protected String getTitle(String 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) {
|
||||
FreemarkerHelper helper = new FreemarkerHelper(config);
|
||||
return helper.mergeToTemplate(templateName, map);
|
||||
}
|
||||
|
||||
protected StringWriter mergeToTemplate(ResponseValues values, Configuration config) {
|
||||
return mergeToTemplate(values.getTemplateName(), values.getMap(), config);
|
||||
}
|
||||
|
||||
protected String mergeBodyToTemplate(String templateName, Map<String, Object> map, Configuration config) {
|
||||
protected String mergeMapToTemplate(String templateName, Map<String, Object> map, Configuration config) {
|
||||
return mergeToTemplate(templateName, map, config).toString();
|
||||
}
|
||||
|
||||
protected void writePage(Map<String, Object> root, Configuration config, HttpServletResponse response) {
|
||||
String templateName = getPageTemplateName();
|
||||
writeTemplate(templateName, root, config, response);
|
||||
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) {
|
||||
writeTemplate(getPageTemplateName(), root, config, 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);
|
||||
}
|
||||
|
||||
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);
|
||||
FreemarkerComponentGenerator.setServletContext(sc);
|
||||
UrlBuilder.contextPath = sc.getContextPath();
|
||||
|
||||
log.info("Freemarker templating system initialized.");
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
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.controller.Controllers;
|
||||
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.filestorage.backend.FileStorage;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
||||
|
@ -160,94 +163,31 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException, ServletException {
|
||||
|
||||
try {
|
||||
// Parse the multi-part request.
|
||||
request = FileUploadServletRequest.parseRequest(request,
|
||||
MAXIMUM_FILE_SIZE);
|
||||
if (log.isTraceEnabled()) {
|
||||
dumpRequestDetails(request);
|
||||
}
|
||||
|
||||
// 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 (!checkAuthorized(vreq)) {
|
||||
String loginPage = request.getContextPath() + Controllers.LOGIN;
|
||||
response.sendRedirect(loginPage);
|
||||
return;
|
||||
}
|
||||
|
||||
ResponseValues values = 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) {
|
||||
log.error("Could not produce response page", 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));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
try {
|
||||
// Parse the multi-part request.
|
||||
FileUploadServletRequest request = FileUploadServletRequest.parseRequest(vreq,
|
||||
MAXIMUM_FILE_SIZE);
|
||||
if (log.isTraceEnabled()) {
|
||||
dumpRequestDetails(vreq);
|
||||
}
|
||||
|
||||
// If they aren't authorized to do this, send them to login.
|
||||
if (!checkAuthorized(vreq)) {
|
||||
String loginPage = request.getContextPath() + Controllers.LOGIN;
|
||||
return new RedirectResponseValues(loginPage);
|
||||
}
|
||||
|
||||
return buildTheResponse(vreq);
|
||||
|
||||
} catch (Exception e) {
|
||||
//log.error("Could not produce response page", e);
|
||||
return new ExceptionResponseValues(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the different actions. If not specified, the default action is to
|
||||
* 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
|
||||
|
|
|
@ -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.controller.Controllers;
|
||||
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.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration;
|
||||
|
@ -74,7 +75,8 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
private ApplicationBean appBean;
|
||||
|
||||
|
||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
try {
|
||||
|
||||
HttpSession session = vreq.getSession();
|
||||
|
@ -92,13 +94,13 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") );
|
||||
if( redirectURL != null ){
|
||||
//doRedirect( vreq, res, redirectURL );
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
|
||||
if( rdfFormat != null ){
|
||||
//doRdf( vreq, res, rdfFormat );
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
Individual individual = null;
|
||||
|
@ -106,37 +108,34 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
individual = getEntityFromRequest( vreq);
|
||||
}catch(Throwable th){
|
||||
//doHelp(res);
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
|
||||
//doNotFound(vreq, res);
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
// If this is an uploaded file, redirect to its "alias URL".
|
||||
String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, individual);
|
||||
if (aliasUrl != null) {
|
||||
//res.sendRedirect(vreq.getContextPath() + aliasUrl);
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
int securityLevel = getSecurityLevel(session);
|
||||
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
|
||||
body.put("editStatus", getEditingData(vreq, securityLevel, individual, urlBuilder));
|
||||
body.putAll(getIndividualData(vreq, individual));
|
||||
body.put("title", individual.getName());
|
||||
|
||||
String bodyTemplate = "individual.ftl";
|
||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
||||
|
||||
return new TemplateResponseValues("individual.ftl", body);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error(e);
|
||||
//vreq.setAttribute("javax.servlet.jsp.jspException",e);
|
||||
// RequestDispatcher rd = vreq.getRequestDispatcher("/error.jsp");
|
||||
//rd.forward(vreq, res);
|
||||
return "";
|
||||
return new ExceptionResponseValues(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.VClassGroup;
|
||||
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.web.templatemodels.IndividualTemplateModel;
|
||||
import freemarker.template.Configuration;
|
||||
|
@ -28,9 +29,11 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
// private VClass vclass = 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 message = null;
|
||||
|
||||
|
@ -90,17 +93,17 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
} catch (HelpException help){
|
||||
errorMessage = "Request attribute 'vclass' or request parameter 'vclassId' must be set before calling. Its value must be a class uri.";
|
||||
} catch (Throwable e) {
|
||||
bodyTemplate = "error.ftl";
|
||||
return new ExceptionResponseValues(e);
|
||||
}
|
||||
|
||||
if (errorMessage != null) {
|
||||
bodyTemplate = "errorMessage.ftl";
|
||||
templateName = "errorMessage.ftl";
|
||||
body.put("errorMessage", errorMessage);
|
||||
} else if (message != null) {
|
||||
body.put("message", message);
|
||||
}
|
||||
|
||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
||||
return new TemplateResponseValues(templateName, body);
|
||||
}
|
||||
|
||||
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 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 freemarker.template.Configuration;
|
||||
|
||||
|
@ -46,8 +47,8 @@ public class NavigationController extends FreemarkerHttpServlet {
|
|||
displayOntModel.getBaseModel().register( urlPatterns );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
OntModel displayOntModel = (OntModel)getServletContext().getAttribute("displayOntModel");
|
||||
OntModel jenaOntModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||
|
||||
|
@ -56,7 +57,7 @@ public class NavigationController extends FreemarkerHttpServlet {
|
|||
Map<String,Object> values = getValues(ind, displayOntModel,jenaOntModel, getValuesFromRequest(/*?*/) );
|
||||
String template = getTemplate(ind, displayOntModel);
|
||||
|
||||
return mergeBodyToTemplate(template, values, config);
|
||||
return new TemplateResponseValues(template, values);
|
||||
}
|
||||
|
||||
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.vitro.webapp.beans.VClassGroup;
|
||||
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.Route;
|
||||
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 Log log = LogFactory.getLog(SiteAdminController.class);
|
||||
|
||||
@Override
|
||||
public String getTitle(String siteName) {
|
||||
return siteName + " Site Administration";
|
||||
}
|
||||
|
||||
public String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
String loginStatus = null;
|
||||
|
||||
|
@ -40,10 +43,14 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
|||
loginStatus = loginHandler.getLoginStatus();
|
||||
}
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
// NOT LOGGED IN: just show login form
|
||||
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
|
||||
} else {
|
||||
|
||||
|
@ -79,10 +86,24 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
|||
// }
|
||||
// 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) {
|
||||
|
||||
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.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 freemarker.template.Configuration;
|
||||
|
||||
public class TermsOfUseController extends FreemarkerHttpServlet {
|
||||
|
||||
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);
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
Portal portal = vreq.getPortal();
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
String rootBreadCrumbAnchor = portal.getRootBreadCrumbAnchor();
|
||||
String websiteName = StringUtils.isEmpty(rootBreadCrumbAnchor) ? portal.getAppName() : rootBreadCrumbAnchor;
|
||||
body.put("websiteName", websiteName);
|
||||
|
||||
body.put("copyrightAnchor", portal.getCopyrightAnchor());
|
||||
|
||||
return new TemplateResponseValues("termsOfUse.ftl", body);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle(String siteName) {
|
||||
return siteName + " Terms of Use";
|
||||
}
|
||||
|
||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||
|
||||
Portal portal = vreq.getPortal();
|
||||
|
||||
String rootBreadCrumbAnchor = portal.getRootBreadCrumbAnchor();
|
||||
String websiteName = StringUtils.isEmpty(rootBreadCrumbAnchor) ? portal.getAppName() : rootBreadCrumbAnchor;
|
||||
|
||||
body.put("websiteName", websiteName);
|
||||
body.put("copyrightAnchor", portal.getCopyrightAnchor());
|
||||
|
||||
String bodyTemplate = "termsOfUse.ftl";
|
||||
return mergeBodyToTemplate(bodyTemplate, body, config);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,10 @@ import java.util.Map;
|
|||
import org.apache.commons.logging.Log;
|
||||
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.freemarker.FreemarkerHttpServlet.ResponseValues;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues;
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
/**
|
||||
|
@ -25,12 +28,11 @@ public class TestController extends FreemarkerHttpServlet {
|
|||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(TestController.class);
|
||||
|
||||
protected String getTitle() {
|
||||
return "Test";
|
||||
}
|
||||
|
||||
protected String getBody(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
Portal portal = vreq.getPortal();
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
// Test of #list directive in template on undefined, null, and empty values.
|
||||
// Basic idea: empty list okay, null or undefined value not okay.
|
||||
List<String> apples = new ArrayList<String>(); // no error
|
||||
|
@ -85,10 +87,22 @@ public class TestController extends FreemarkerHttpServlet {
|
|||
body.put("bookTitle", "Persuasion");
|
||||
|
||||
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.
|
||||
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 */
|
||||
public String showLoginPage(VitroRequest vreq, Map<String, Object> body, Configuration config) {
|
||||
public TemplateResponseValues showLoginPanel(VitroRequest vreq) {
|
||||
try {
|
||||
|
||||
State state = getCurrentLoginState(vreq);
|
||||
log.debug("State on exit: " + state);
|
||||
|
||||
|
||||
switch (state) {
|
||||
// RY Why does this case exist? We don't call this method if a user is logged in.
|
||||
case LOGGED_IN:
|
||||
return "";
|
||||
return null;
|
||||
case FORCED_PASSWORD_CHANGE:
|
||||
return doTemplate(vreq, showPasswordChangeScreen(vreq), body, config);
|
||||
//return doTemplate(vreq, showPasswordChangeScreen(vreq), body, config);
|
||||
return showPasswordChangeScreen(vreq);
|
||||
default:
|
||||
return doTemplate(vreq, showLoginScreen(vreq), body, config);
|
||||
//return doTemplate(vreq, showLoginScreen(vreq), body, config);
|
||||
return showLoginScreen(vreq);
|
||||
}
|
||||
} catch (Exception 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()) {
|
||||
trv.put(BODY_ERROR_MESSAGE, errorMessage);
|
||||
}
|
||||
|
||||
return trv;
|
||||
}
|
||||
|
||||
|
@ -165,20 +169,10 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
|||
setUpRoot(vreq, root);
|
||||
|
||||
// Add the values that we got, and merge to the template.
|
||||
body.putAll(values.getBodyMap());
|
||||
return mergeBodyToTemplate(values.getTemplateName(), body, config);
|
||||
body.putAll(values.getMap());
|
||||
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?
|
||||
|
@ -240,29 +234,4 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
|||
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 {
|
||||
|
||||
Portal portal = vreq.getPortal();
|
||||
|
@ -116,7 +120,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
if( vreq.getWebappDaoFactory() == null
|
||||
|| vreq.getWebappDaoFactory().getIndividualDao() == null ){
|
||||
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();
|
||||
VClassGroupDao grpDao = vreq.getWebappDaoFactory().getVClassGroupDao();
|
||||
|
@ -153,7 +157,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
log.debug("query for '" + qtxt +"' is " + query.toString());
|
||||
|
||||
if (query == null ) {
|
||||
return doNoQuery(config, portal);
|
||||
return doNoQuery(portal);
|
||||
}
|
||||
|
||||
IndexSearcher searcherForRequest = getIndexSearcher(indexDir);
|
||||
|
@ -173,19 +177,19 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
if (msg == null) {
|
||||
msg = "The search request contained errors.";
|
||||
}
|
||||
return doFailedSearch(msg, qtxt, config);
|
||||
return doFailedSearch(msg, qtxt);
|
||||
}
|
||||
}
|
||||
|
||||
if( topDocs == null || topDocs.scoreDocs == null){
|
||||
log.error("topDocs for a search was null");
|
||||
String msg = "The search request contained errors.";
|
||||
return doFailedSearch(msg, qtxt, config);
|
||||
return doFailedSearch(msg, qtxt);
|
||||
}
|
||||
|
||||
int hitsLength = topDocs.scoreDocs.length;
|
||||
if ( hitsLength < 1 ){
|
||||
return doNoHits(qtxt, config);
|
||||
return doNoHits(qtxt);
|
||||
}
|
||||
log.debug("found "+hitsLength+" hits");
|
||||
|
||||
|
@ -286,12 +290,11 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
body.put("nextPage", getNextPageLink(startIndex, hitsPerPage, vreq.getServletPath(), pagingLinkParams));
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error(e, e);
|
||||
return doSearchError(e.getMessage(), config);
|
||||
} catch (Throwable e) {
|
||||
return doSearchError(e);
|
||||
}
|
||||
|
||||
return mergeBodyToTemplate("search-pagedResults.ftl", body, config);
|
||||
return new TemplateResponseValues("search-pagedResults.ftl", body);
|
||||
}
|
||||
|
||||
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>();
|
||||
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>();
|
||||
body.put("title", "Search " + portal.getAppName());
|
||||
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>();
|
||||
body.put("title", "Search for '" + querytext + "'");
|
||||
if ( StringUtils.isEmpty(message) ) {
|
||||
message = "Search failed.";
|
||||
}
|
||||
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>();
|
||||
body.put("title", "Search for '" + querytext + "'");
|
||||
body.put("message", "No matching results.");
|
||||
return mergeBodyToTemplate("search-error.ftl", body, config);
|
||||
return new TemplateResponseValues("search-error.ftl", body);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,102 +1,100 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.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.indexing.IndexBuilder;
|
||||
import freemarker.template.Configuration;
|
||||
|
||||
/**
|
||||
* Accepts requests to rebuild or update the search index. It uses
|
||||
* an IndexBuilder and finds that IndexBuilder from the servletContext using
|
||||
* the key "edu.cornel.mannlib.vitro.search.indexing.IndexBuilder"
|
||||
*
|
||||
* That IndexBuilder will be associated with a object that implements the IndexerIface.
|
||||
*
|
||||
* An example of the IndexerIface is LuceneIndexer.
|
||||
* An example of the IndexBuilder and LuceneIndexer getting setup is in LuceneSetup.
|
||||
*
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class IndexController extends FreemarkerHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(IndexController.class.getName());
|
||||
|
||||
// public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
// throws ServletException,IOException {
|
||||
// doGet(request, response);
|
||||
// }
|
||||
//
|
||||
// public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||
// throws IOException, ServletException {
|
||||
//
|
||||
// Object obj = request.getSession().getAttribute("loginHandler");
|
||||
// LoginFormBean loginHandler = null;
|
||||
// if( obj != null && obj instanceof LoginFormBean )
|
||||
// loginHandler = ((LoginFormBean)obj);
|
||||
// if( loginHandler == null ||
|
||||
// ! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
||||
// Integer.parseInt(loginHandler.getLoginRole()) <= 5 ){
|
||||
//
|
||||
// String redirectURL=request.getContextPath() + Controllers.SITE_ADMIN + "?login=block";
|
||||
// response.sendRedirect(redirectURL);
|
||||
// return;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Accepts requests to rebuild or update the search index. It uses
|
||||
* an IndexBuilder and finds that IndexBuilder from the servletContext using
|
||||
* the key "edu.cornel.mannlib.vitro.search.indexing.IndexBuilder"
|
||||
*
|
||||
* That IndexBuilder will be associated with a object that implements the IndexerIface.
|
||||
*
|
||||
* An example of the IndexerIface is LuceneIndexer.
|
||||
* An example of the IndexBuilder and LuceneIndexer getting setup is in LuceneSetup.
|
||||
*
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class IndexController extends FreemarkerHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(IndexController.class.getName());
|
||||
|
||||
// public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
// throws ServletException,IOException {
|
||||
// doGet(request, response);
|
||||
// }
|
||||
//
|
||||
// public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||
// throws IOException, ServletException {
|
||||
//
|
||||
// long start = System.currentTimeMillis();
|
||||
// try {
|
||||
// IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
||||
// if( request.getParameter("update") != null ){
|
||||
// builder.doUpdateIndex();
|
||||
// }else{
|
||||
// builder.doIndexRebuild();
|
||||
// }
|
||||
//
|
||||
// } catch (IndexingException e) {
|
||||
// log.error("IndexController -- Error building index: " + e);
|
||||
// Object obj = request.getSession().getAttribute("loginHandler");
|
||||
// LoginFormBean loginHandler = null;
|
||||
// if( obj != null && obj instanceof LoginFormBean )
|
||||
// loginHandler = ((LoginFormBean)obj);
|
||||
// if( loginHandler == null ||
|
||||
// ! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
|
||||
// Integer.parseInt(loginHandler.getLoginRole()) <= 5 ){
|
||||
//
|
||||
// String redirectURL=request.getContextPath() + Controllers.SITE_ADMIN + "?login=block";
|
||||
// response.sendRedirect(redirectURL);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// long start = System.currentTimeMillis();
|
||||
// try {
|
||||
// IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
||||
// if( request.getParameter("update") != null ){
|
||||
// builder.doUpdateIndex();
|
||||
// }else{
|
||||
// builder.doIndexRebuild();
|
||||
// }
|
||||
//
|
||||
// } catch (IndexingException e) {
|
||||
// log.error("IndexController -- Error building index: " + e);
|
||||
// }
|
||||
// long delta = System.currentTimeMillis() - start;
|
||||
// String msg = "Search index complete. Elapsed time " + delta + " msec.";
|
||||
// String msg = "Search index complete. Elapsed time " + delta + " msec.";
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
protected String getTitle(String siteName) {
|
||||
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;
|
||||
if( obj != null && obj instanceof LoginFormBean )
|
||||
loginHandler = ((LoginFormBean)obj);
|
||||
if( loginHandler == null ||
|
||||
! "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 mergeBodyToTemplate("message.ftl", body, config);
|
||||
return new RedirectResponseValues(UrlBuilder.getUrl(Route.LOGIN));
|
||||
}
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
// long start = System.currentTimeMillis();
|
||||
try {
|
||||
IndexBuilder builder = (IndexBuilder)getServletContext().getAttribute(IndexBuilder.class.getName());
|
||||
if( request.getParameter("update") != null ){
|
||||
if( vreq.getParameter("update") != null ){
|
||||
builder.doUpdateIndex();
|
||||
}else{
|
||||
builder.doIndexRebuild();
|
||||
|
@ -105,10 +103,10 @@ public class IndexController extends FreemarkerHttpServlet {
|
|||
} catch (IndexingException e) {
|
||||
log.error("Error rebuilding search index",e);
|
||||
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.");
|
||||
return mergeBodyToTemplate("message.ftl", body, config);
|
||||
}
|
||||
}
|
||||
return new TemplateResponseValues("message.ftl", body);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue