Move template names to enum in FreeMarkerHttpServlet and constants in subclasses.
This commit is contained in:
parent
89391fbc96
commit
c0a8d603ed
19 changed files with 243 additions and 113 deletions
|
@ -16,6 +16,7 @@ public class AboutController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(AboutController.class);
|
||||
private static final String TEMPLATE_DEFAULT = "about.ftl";
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
@ -25,7 +26,7 @@ public class AboutController extends FreemarkerHttpServlet {
|
|||
body.put("aboutText", portal.getAboutText());
|
||||
body.put("acknowledgeText", portal.getAcknowledgeText());
|
||||
|
||||
return new TemplateResponseValues("about.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,9 @@ public class BrowseController extends FreemarkerHttpServlet {
|
|||
= new ConcurrentLinkedQueue<String>();
|
||||
private RebuildGroupCacheThread _cacheRebuildThread;
|
||||
|
||||
private static final Log log = LogFactory.getLog(BrowseController.class.getName());
|
||||
private static final Log log = LogFactory.getLog(BrowseController.class);
|
||||
|
||||
private static final String TEMPLATE_DEFAULT = "classGroups.ftl";
|
||||
|
||||
public void init(javax.servlet.ServletConfig servletConfig)
|
||||
throws javax.servlet.ServletException {
|
||||
|
@ -107,7 +109,7 @@ public class BrowseController extends FreemarkerHttpServlet {
|
|||
body.put("message", message);
|
||||
}
|
||||
|
||||
return new TemplateResponseValues("classGroups.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
|
|
|
@ -33,6 +33,9 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
|||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(ContactFormController.class.getName());
|
||||
|
||||
private static final String TEMPLATE_DEFAULT = "contactForm-form.ftl";
|
||||
private static final String TEMPLATE_ERROR = "contactForm-error.ftl";
|
||||
|
||||
@Override
|
||||
protected String getTitle(String siteName) {
|
||||
return siteName + " Feedback Form";
|
||||
|
@ -49,14 +52,14 @@ public class ContactFormController 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.");
|
||||
templateName = "contactForm-error.ftl";
|
||||
templateName = TEMPLATE_ERROR;
|
||||
}
|
||||
|
||||
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>");
|
||||
|
||||
templateName = "contactForm-error.ftl";
|
||||
templateName = TEMPLATE_ERROR;
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -89,7 +92,7 @@ public class ContactFormController extends FreemarkerHttpServlet {
|
|||
vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer"));
|
||||
}
|
||||
|
||||
templateName = "contactForm-form.ftl";
|
||||
templateName = TEMPLATE_DEFAULT;
|
||||
}
|
||||
|
||||
return new TemplateResponseValues(templateName, body);
|
||||
|
|
|
@ -43,6 +43,11 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
private final static String WEB_USEREMAIL_PARAM = "webuseremail";
|
||||
private final static String COMMENTS_PARAM = "s34gfd88p9x1";
|
||||
|
||||
private final static String TEMPLATE_CONFIRMATION = "contactForm-confirmation.ftl";
|
||||
private final static String TEMPLATE_EMAIL = "contactForm-email.ftl";
|
||||
private final static String TEMPLATE_BACKUP = "contactForm-backup.ftl";
|
||||
private final static String TEMPLATE_ERROR = "contactForm-error.ftl";
|
||||
|
||||
private static String smtpHost = null;
|
||||
|
||||
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
|
||||
|
@ -86,7 +91,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.");
|
||||
templateName = "contactForm-error.ftl";
|
||||
templateName = TEMPLATE_ERROR;
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -102,7 +107,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
// rjy7 We should reload the form, not go to the error page!
|
||||
body.put("errorMessage",
|
||||
"Invalid submission");
|
||||
templateName = "contactForm-error.ftl";
|
||||
templateName = TEMPLATE_ERROR;
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -210,10 +215,10 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
|
||||
// Message was sent successfully
|
||||
if (statusMsg == null && spamReason == null) {
|
||||
templateName = "contactForm-confirmation.ftl";
|
||||
templateName = TEMPLATE_CONFIRMATION;
|
||||
} else {
|
||||
body.put("errorMessage", statusMsg);
|
||||
templateName = "contactForm-error.ftl";
|
||||
templateName = TEMPLATE_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -236,7 +241,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
String originalReferer, String ipAddr, Configuration config) {
|
||||
|
||||
Map<String, Object> email = new HashMap<String, Object>();
|
||||
String template = "contactForm-email.ftl";
|
||||
String template = TEMPLATE_EMAIL;
|
||||
|
||||
email.put("subject", deliveryfrom);
|
||||
email.put("name", webusername);
|
||||
|
@ -254,7 +259,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
|||
String spamReason, Configuration config) {
|
||||
|
||||
Map<String, Object> backup = new HashMap<String, Object>();
|
||||
String template = "contactForm-backup.ftl";
|
||||
String template = TEMPLATE_BACKUP;
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
backup.put("datetime", cal.getTime().toString());
|
||||
|
|
|
@ -20,6 +20,8 @@ import javax.servlet.http.HttpSession;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
|
@ -30,6 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts;
|
||||
|
@ -52,6 +55,24 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
private static final Log log = LogFactory.getLog(FreemarkerHttpServlet.class);
|
||||
private static final int FILTER_SECURITY_LEVEL = LoginFormBean.EDITOR;
|
||||
|
||||
protected enum Template {
|
||||
STANDARD_ERROR("error-standard.ftl"),
|
||||
ERROR_MESSAGE("error-message.ftl"),
|
||||
TITLED_ERROR_MESSAGE("error-titledMessage.ftl"),
|
||||
MESSAGE("message.ftl"),
|
||||
PAGE_DEFAULT("page.ftl");
|
||||
|
||||
private final String filename;
|
||||
|
||||
Template(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
||||
public void doGet( HttpServletRequest request, HttpServletResponse response )
|
||||
throws IOException, ServletException {
|
||||
|
||||
|
@ -219,6 +240,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
doRedirect(vreq, response, values);
|
||||
} else if (values instanceof ForwardResponseValues) {
|
||||
doForward(vreq, response, values);
|
||||
} else if (values instanceof RdfResponseValues) {
|
||||
doRdf(vreq, response, values);
|
||||
}
|
||||
} catch (ServletException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
@ -273,6 +296,24 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
protected void doRdf(HttpServletRequest request, HttpServletResponse response, ResponseValues values)
|
||||
throws IOException {
|
||||
|
||||
String mediaType = values.getContentType().getMediaType();
|
||||
response.setContentType(mediaType);
|
||||
|
||||
String format = "";
|
||||
if ( RDFXML_MIMETYPE.equals(mediaType)) {
|
||||
format = "RDF/XML";
|
||||
} else if( N3_MIMETYPE.equals(mediaType)) {
|
||||
format = "N3";
|
||||
} else if ( TTL_MIMETYPE.equals(mediaType)) {
|
||||
format ="TTL";
|
||||
}
|
||||
|
||||
values.getModel().write( response.getOutputStream(), format );
|
||||
}
|
||||
|
||||
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());
|
||||
|
@ -521,7 +562,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
|
||||
// Can be overridden by individual controllers to use a different basic page layout.
|
||||
protected String getPageTemplateName() {
|
||||
return "page.ftl";
|
||||
return Template.PAGE_DEFAULT.toString();
|
||||
}
|
||||
|
||||
// TEMPORARY method for transition from JSP to Freemarker.
|
||||
|
@ -552,10 +593,15 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
String getForwardUrl();
|
||||
|
||||
Throwable getException();
|
||||
|
||||
ContentType getContentType();
|
||||
|
||||
Model getModel();
|
||||
}
|
||||
|
||||
protected static abstract class BaseResponseValues implements ResponseValues {
|
||||
private int statusCode = 0;
|
||||
private ContentType contentType = null;
|
||||
|
||||
BaseResponseValues() { }
|
||||
|
||||
|
@ -563,6 +609,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
BaseResponseValues(ContentType contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
@ -570,6 +620,14 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public ContentType getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(ContentType contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class TemplateResponseValues extends BaseResponseValues {
|
||||
|
@ -636,6 +694,12 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
"This is not an exception response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model getModel() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not an RDF response.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class RedirectResponseValues extends BaseResponseValues {
|
||||
|
@ -684,6 +748,11 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
"This is not an exception response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model getModel() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not an RDF response.");
|
||||
}
|
||||
}
|
||||
|
||||
protected static class ForwardResponseValues extends BaseResponseValues {
|
||||
|
@ -732,10 +801,15 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
"This is not an exception response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model getModel() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not an RDF response.");
|
||||
}
|
||||
}
|
||||
|
||||
protected static class ExceptionResponseValues extends TemplateResponseValues {
|
||||
private final static String DEFAULT_TEMPLATE_NAME = "error.ftl";
|
||||
private final static String DEFAULT_TEMPLATE_NAME = "error-standard.ftl";
|
||||
private final Throwable cause;
|
||||
|
||||
public ExceptionResponseValues(Throwable cause) {
|
||||
|
@ -801,5 +875,66 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
"This is not a forwarding response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model getModel() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not an RDF response.");
|
||||
}
|
||||
}
|
||||
|
||||
protected static class RdfResponseValues extends BaseResponseValues {
|
||||
private final Model model;
|
||||
|
||||
RdfResponseValues(ContentType contentType, Model model) {
|
||||
super(contentType);
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not a template response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusCode() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not a BaseResponseValues response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatusCode(int statusCode) {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not a BaseResponseValues 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 String getForwardUrl() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not a forwarding response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable getException() {
|
||||
throw new UnsupportedOperationException(
|
||||
"This is not an exception response.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model getModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -110,7 +110,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
public static final String TEMPLATE_NEW = "imageUpload-newImage.ftl";
|
||||
public static final String TEMPLATE_REPLACE = "imageUpload-replaceImage.ftl";
|
||||
public static final String TEMPLATE_CROP = "imageUpload-cropImage.ftl";
|
||||
public static final String TEMPLATE_ERROR = "error.ftl";
|
||||
public static final String TEMPLATE_ERROR = "error-standard.ftl";
|
||||
|
||||
private static final String URL_HERE = UrlBuilder.getUrl("/uploadImages");
|
||||
|
||||
|
|
|
@ -74,6 +74,8 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
private String default_body_jsp = Controllers.ENTITY_JSP;
|
||||
private ApplicationBean appBean;
|
||||
|
||||
private static final String TEMPLATE_INDIVIDUAL = "individual.ftl";
|
||||
private static final String TEMPLATE_HELP = "individual-help.ftl";
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
@ -83,44 +85,35 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
|
||||
cleanUpSession(session);
|
||||
|
||||
|
||||
|
||||
// get URL without hostname or servlet context
|
||||
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
||||
|
||||
// Title = individual label
|
||||
|
||||
//Check to see if the request is for a non-information resource, redirect if it is.
|
||||
// Check to see if the request is for a non-information resource, redirect if it is.
|
||||
String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") );
|
||||
if( redirectURL != null ){
|
||||
//doRedirect( vreq, res, redirectURL );
|
||||
return null;
|
||||
return new RedirectResponseValues(redirectURL);
|
||||
}
|
||||
|
||||
Individual individual = null;
|
||||
try {
|
||||
individual = getEntityFromRequest(vreq);
|
||||
} catch (Throwable th) {
|
||||
return doHelp();
|
||||
}
|
||||
|
||||
if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
|
||||
return doNotFound(vreq);
|
||||
}
|
||||
|
||||
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
|
||||
if( rdfFormat != null ){
|
||||
//doRdf( vreq, res, rdfFormat );
|
||||
return null;
|
||||
}
|
||||
|
||||
Individual individual = null;
|
||||
try{
|
||||
individual = getEntityFromRequest( vreq);
|
||||
}catch(Throwable th){
|
||||
//doHelp(res);
|
||||
return null;
|
||||
}
|
||||
|
||||
if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
|
||||
//doNotFound(vreq, res);
|
||||
return null;
|
||||
return doRdf(vreq, individual, rdfFormat);
|
||||
}
|
||||
|
||||
// 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 null;
|
||||
return new RedirectResponseValues(UrlBuilder.getUrl(vreq.getContextPath() + aliasUrl));
|
||||
}
|
||||
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
@ -128,10 +121,10 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
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());
|
||||
body.putAll(getIndividualData(vreq, individual));
|
||||
|
||||
return new TemplateResponseValues("individual.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_INDIVIDUAL, body);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error(e);
|
||||
|
@ -308,15 +301,9 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
return map;
|
||||
}
|
||||
|
||||
private void doRdf(VitroRequest vreq, HttpServletResponse res,
|
||||
private ResponseValues doRdf(VitroRequest vreq, Individual individual,
|
||||
ContentType rdfFormat) throws IOException, ServletException {
|
||||
|
||||
Individual indiv = getEntityFromRequest(vreq);
|
||||
if( indiv == null ){
|
||||
doNotFound(vreq, res);
|
||||
return;
|
||||
}
|
||||
|
||||
OntModel ontModel = null;
|
||||
HttpSession session = vreq.getSession(false);
|
||||
if( session != null )
|
||||
|
@ -324,19 +311,9 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
if( ontModel == null)
|
||||
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||
|
||||
Model newModel;
|
||||
newModel = getRDF(indiv, ontModel, ModelFactory.createDefaultModel(), 0);
|
||||
Model newModel = getRDF(individual, ontModel, ModelFactory.createDefaultModel(), 0);
|
||||
|
||||
res.setContentType(rdfFormat.getMediaType());
|
||||
String format = "";
|
||||
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format = "RDF/XML";
|
||||
else if( N3_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format = "N3";
|
||||
else if ( TTL_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||
format ="TTL";
|
||||
|
||||
newModel.write( res.getOutputStream(), format );
|
||||
return new RdfResponseValues(rdfFormat, newModel);
|
||||
}
|
||||
|
||||
private void doRedirect(HttpServletRequest req, HttpServletResponse res,
|
||||
|
@ -660,18 +637,11 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
doGet(request, response);
|
||||
}
|
||||
|
||||
private void doHelp(HttpServletResponse res)
|
||||
throws IOException, ServletException {
|
||||
ServletOutputStream out = res.getOutputStream();
|
||||
res.setContentType("text/html; charset=UTF-8");
|
||||
out.println("<html><body><h2>Quick Notes on using entity:</h2>");
|
||||
out.println("<p>id is the id of the entity to query for. netid also works.</p>");
|
||||
out.println("</body></html>");
|
||||
private ResponseValues doHelp() throws IOException, ServletException {
|
||||
return new TemplateResponseValues(TEMPLATE_HELP);
|
||||
}
|
||||
|
||||
private void doNotFound(HttpServletRequest req, HttpServletResponse res)
|
||||
throws IOException, ServletException {
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
private ResponseValues doNotFound(VitroRequest vreq) throws IOException, ServletException {
|
||||
Portal portal = vreq.getPortal();
|
||||
ApplicationBean appBean = ApplicationBean.getAppBean(getServletContext());
|
||||
int allPortalId = appBean.getAllPortalFlagNumeric();
|
||||
|
@ -697,7 +667,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
else
|
||||
portalParam = "home=" + allPortalId;
|
||||
|
||||
String queryStr = req.getQueryString();
|
||||
String queryStr = vreq.getQueryString();
|
||||
if( queryStr == null && portalParam != null && !"".equals(portalParam)){
|
||||
queryStr = portalParam;
|
||||
} else {
|
||||
|
@ -708,14 +678,14 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
queryStr = "?" + queryStr;
|
||||
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append( req.getContextPath() );
|
||||
if( req.getContextPath() != null && !req.getContextPath().endsWith("/"))
|
||||
url.append( vreq.getContextPath() );
|
||||
if( vreq.getContextPath() != null && !vreq.getContextPath().endsWith("/"))
|
||||
url.append('/');
|
||||
|
||||
if( portalPrefix != null && !"".equals(portalPrefix))
|
||||
url.append( portalPrefix ).append('/');
|
||||
|
||||
String servletPath = req.getServletPath();
|
||||
String servletPath = vreq.getServletPath();
|
||||
String spath = "";
|
||||
if( servletPath != null ){
|
||||
if( servletPath.startsWith("/") )
|
||||
|
@ -727,32 +697,24 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
if( spath != null && !"".equals(spath))
|
||||
url.append( spath );
|
||||
|
||||
if( req.getPathInfo() != null )
|
||||
url.append( req.getPathInfo() );
|
||||
if( vreq.getPathInfo() != null )
|
||||
url.append( vreq.getPathInfo() );
|
||||
|
||||
if( queryStr != null && !"".equals(queryStr ))
|
||||
url.append( queryStr );
|
||||
|
||||
res.sendRedirect(url.toString());
|
||||
return;
|
||||
return new RedirectResponseValues(url.toString());
|
||||
}
|
||||
}catch(Throwable th){
|
||||
log.error("could not do a redirect", th);
|
||||
}
|
||||
|
||||
//set title before we do the highlighting so we don't get markup in it.
|
||||
req.setAttribute("title","not found");
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body.put("title","Individual Not Found");
|
||||
body.put("errorMessage", "The individual was not found in the system.");
|
||||
|
||||
String css = "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\""
|
||||
+ portal.getThemeDir() + "css/entity.css\"/>"
|
||||
+ "<script language='JavaScript' type='text/javascript' src='js/toggle.js'></script>";
|
||||
req.setAttribute("css",css);
|
||||
|
||||
req.setAttribute("bodyJsp","/"+Controllers.ENTITY_NOT_FOUND_JSP);
|
||||
|
||||
RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP);
|
||||
rd.forward(req,res);
|
||||
return new TemplateResponseValues(Template.TITLED_ERROR_MESSAGE.toString(), body, HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
|
||||
private String forURL(String frag) {
|
||||
|
|
|
@ -26,13 +26,13 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(IndividualListController.class.getName());
|
||||
// private VClass vclass = null;
|
||||
// private String title = null;
|
||||
|
||||
private static final String TEMPLATE_DEFAULT = "individualList.ftl";
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
||||
String templateName = "individualList.ftl";
|
||||
String templateName = TEMPLATE_DEFAULT;
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
String errorMessage = null;
|
||||
String message = null;
|
||||
|
@ -97,7 +97,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
|
|||
}
|
||||
|
||||
if (errorMessage != null) {
|
||||
templateName = "errorMessage.ftl";
|
||||
templateName = Template.ERROR_MESSAGE.toString();
|
||||
body.put("errorMessage", errorMessage);
|
||||
} else if (message != null) {
|
||||
body.put("message", message);
|
||||
|
|
|
@ -28,6 +28,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
|||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(SiteAdminController.class);
|
||||
|
||||
private static final String TEMPLATE_DEFAULT = "siteAdmin-main.ftl";
|
||||
@Override
|
||||
public String getTitle(String siteName) {
|
||||
return siteName + " Site Administration";
|
||||
|
@ -86,7 +87,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
|
|||
// }
|
||||
// body.put("languageModeStr", languageMode);
|
||||
|
||||
return new TemplateResponseValues("siteAdmin-main.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public class TermsOfUseController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(TermsOfUseController.class);
|
||||
private static final String TEMPLATE_DEFAULT = "termsOfUse.ftl";
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
@ -32,7 +33,7 @@ public class TermsOfUseController extends FreemarkerHttpServlet {
|
|||
|
||||
body.put("copyrightAnchor", portal.getCopyrightAnchor());
|
||||
|
||||
return new TemplateResponseValues("termsOfUse.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ public class TestController extends FreemarkerHttpServlet {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(TestController.class);
|
||||
private static final String TEMPLATE_DEFAULT = "test.ftl";
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
|
@ -88,7 +89,7 @@ public class TestController extends FreemarkerHttpServlet {
|
|||
|
||||
body.put("title", "VIVO Test");
|
||||
|
||||
return new TemplateResponseValues("test.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,7 +29,7 @@ public class UrlBuilder {
|
|||
BROWSE("/browse"),
|
||||
CONTACT("/contact"),
|
||||
INDIVIDUAL("/individual"),
|
||||
INDIVIDUAL_LIST("/individuallist"), // entitylist individuallist
|
||||
INDIVIDUAL_LIST("/individuallist"),
|
||||
SEARCH("/search"),
|
||||
TERMS_OF_USE("/termsOfUse"),
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
|
|||
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl";
|
||||
|
||||
/** Show error message */
|
||||
public static final String TEMPLATE_SERVER_ERROR = "errorMessage.ftl";
|
||||
public static final String TEMPLATE_SERVER_ERROR = Template.ERROR_MESSAGE.toString();
|
||||
|
||||
public static final String BODY_LOGIN_NAME = "loginName";
|
||||
public static final String BODY_FORM_ACTION = "formAction";
|
||||
|
|
|
@ -86,9 +86,14 @@ import freemarker.template.Configuration;
|
|||
public class FreemarkerPagedSearchController extends FreemarkerHttpServlet implements Searcher {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private IndexSearcher searcher = null;
|
||||
private static final Log log = LogFactory.getLog(FreemarkerPagedSearchController.class.getName());
|
||||
|
||||
private static final String TEMPLATE_SEARCH_RESULTS = "search-pagedResults.ftl";
|
||||
private static final String TEMPLATE_ERROR = "search-error.ftl";
|
||||
|
||||
String NORESULT_MSG = "The search returned no results.";
|
||||
|
||||
private IndexSearcher searcher = null;
|
||||
private int defaultHitsPerPage = 25;
|
||||
private int defaultMaxSearchSize= 1000;
|
||||
|
||||
|
@ -294,7 +299,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
return doSearchError(e);
|
||||
}
|
||||
|
||||
return new TemplateResponseValues("search-pagedResults.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_SEARCH_RESULTS, body);
|
||||
}
|
||||
|
||||
private void alphaSortIndividuals(List<Individual> beans) {
|
||||
|
@ -755,20 +760,20 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
private TemplateResponseValues doSearchError(String message) {
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
body.put("message", "Search failed: " + message);
|
||||
return new TemplateResponseValues("search-error.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_ERROR, body);
|
||||
}
|
||||
|
||||
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);
|
||||
return new ExceptionResponseValues(TEMPLATE_ERROR, 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 new TemplateResponseValues("search-error.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_ERROR, body);
|
||||
}
|
||||
|
||||
private TemplateResponseValues doFailedSearch(String message, String querytext) {
|
||||
|
@ -778,14 +783,14 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
|||
message = "Search failed.";
|
||||
}
|
||||
body.put("message", message);
|
||||
return new TemplateResponseValues("search-error.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_ERROR, body);
|
||||
}
|
||||
|
||||
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 new TemplateResponseValues("search-error.ftl", body);
|
||||
return new TemplateResponseValues(TEMPLATE_ERROR, body);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
|
|||
*/
|
||||
public class IndexController extends FreemarkerHttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(IndexController.class.getName());
|
||||
private static final Log log = LogFactory.getLog(IndexController.class);
|
||||
|
||||
// public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
// throws ServletException,IOException {
|
||||
|
@ -103,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 new ExceptionResponseValues("errorMessage.ftl", body, e);
|
||||
return new ExceptionResponseValues(Template.ERROR_MESSAGE.toString(), body, e);
|
||||
}
|
||||
|
||||
body.put("message","Rebuilding of index started.");
|
||||
return new TemplateResponseValues("message.ftl", body);
|
||||
return new TemplateResponseValues(Template.MESSAGE.toString(), body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Standard template to display an error message generated from any controller. Keeps this out of individual templates. -->
|
||||
|
||||
<h2>${title}</h2>
|
||||
|
||||
<#include "errorMessage.ftl">
|
7
webapp/web/templates/freemarker/body/individual-help.ftl
Normal file
7
webapp/web/templates/freemarker/body/individual-help.ftl
Normal file
|
@ -0,0 +1,7 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Template for help on individual page -->
|
||||
|
||||
<h2>Quick Notes on Using Individual:</h2>
|
||||
|
||||
<p>id is the id of the entity to query for. netid also works.</p>
|
Loading…
Add table
Reference in a new issue