Move template names to enum in FreeMarkerHttpServlet and constants in subclasses.

This commit is contained in:
rjy7 2010-09-20 15:40:35 +00:00
parent 89391fbc96
commit c0a8d603ed
19 changed files with 243 additions and 113 deletions

View file

@ -16,6 +16,7 @@ public class AboutController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(AboutController.class); private static final Log log = LogFactory.getLog(AboutController.class);
private static final String TEMPLATE_DEFAULT = "about.ftl";
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
@ -25,7 +26,7 @@ public class AboutController extends FreemarkerHttpServlet {
body.put("aboutText", portal.getAboutText()); body.put("aboutText", portal.getAboutText());
body.put("acknowledgeText", portal.getAcknowledgeText()); body.put("acknowledgeText", portal.getAcknowledgeText());
return new TemplateResponseValues("about.ftl", body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} }
@Override @Override

View file

@ -46,7 +46,9 @@ public class BrowseController extends FreemarkerHttpServlet {
= new ConcurrentLinkedQueue<String>(); = new ConcurrentLinkedQueue<String>();
private RebuildGroupCacheThread _cacheRebuildThread; 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) public void init(javax.servlet.ServletConfig servletConfig)
throws javax.servlet.ServletException { throws javax.servlet.ServletException {
@ -107,7 +109,7 @@ public class BrowseController extends FreemarkerHttpServlet {
body.put("message", message); body.put("message", message);
} }
return new TemplateResponseValues("classGroups.ftl", body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} }
public void destroy(){ public void destroy(){

View file

@ -33,6 +33,9 @@ public class ContactFormController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(ContactFormController.class.getName()); private static final Log log = LogFactory.getLog(ContactFormController.class.getName());
private static final String TEMPLATE_DEFAULT = "contactForm-form.ftl";
private static final String TEMPLATE_ERROR = "contactForm-error.ftl";
@Override @Override
protected String getTitle(String siteName) { protected String getTitle(String siteName) {
return siteName + " Feedback Form"; return siteName + " Feedback Form";
@ -49,14 +52,14 @@ public class ContactFormController extends FreemarkerHttpServlet {
body.put("errorMessage", body.put("errorMessage",
"This application has not yet been configured to send mail. " + "This application has not yet been configured to send mail. " +
"An smtp host has not been specified in the configuration properties file."); "An smtp host has not been specified in the configuration properties file.");
templateName = "contactForm-error.ftl"; templateName = TEMPLATE_ERROR;
} }
else if (StringUtils.isEmpty(portal.getContactMail())) { else if (StringUtils.isEmpty(portal.getContactMail())) {
body.put("errorMessage", body.put("errorMessage",
"The feedback form is currently disabled. In order to activate the form, a site administrator must provide a contact email address in the <a href='editForm?home=1&amp;controller=Portal&amp;id=1'>Site Configuration</a>"); "The feedback form is currently disabled. In order to activate the form, a site administrator must provide a contact email address in the <a href='editForm?home=1&amp;controller=Portal&amp;id=1'>Site Configuration</a>");
templateName = "contactForm-error.ftl"; templateName = TEMPLATE_ERROR;
} }
else { else {
@ -89,7 +92,7 @@ public class ContactFormController extends FreemarkerHttpServlet {
vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer")); vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer"));
} }
templateName = "contactForm-form.ftl"; templateName = TEMPLATE_DEFAULT;
} }
return new TemplateResponseValues(templateName, body); return new TemplateResponseValues(templateName, body);

View file

@ -43,6 +43,11 @@ public class ContactMailController extends FreemarkerHttpServlet {
private final static String WEB_USEREMAIL_PARAM = "webuseremail"; private final static String WEB_USEREMAIL_PARAM = "webuseremail";
private final static String COMMENTS_PARAM = "s34gfd88p9x1"; 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; private static String smtpHost = null;
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException { public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
@ -86,7 +91,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
body.put("errorMessage", body.put("errorMessage",
"This application has not yet been configured to send mail. " + "This application has not yet been configured to send mail. " +
"An smtp host has not been specified in the configuration properties file."); "An smtp host has not been specified in the configuration properties file.");
templateName = "contactForm-error.ftl"; templateName = TEMPLATE_ERROR;
} }
else { else {
@ -102,7 +107,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
// rjy7 We should reload the form, not go to the error page! // rjy7 We should reload the form, not go to the error page!
body.put("errorMessage", body.put("errorMessage",
"Invalid submission"); "Invalid submission");
templateName = "contactForm-error.ftl"; templateName = TEMPLATE_ERROR;
} }
else { else {
@ -210,10 +215,10 @@ public class ContactMailController extends FreemarkerHttpServlet {
// Message was sent successfully // Message was sent successfully
if (statusMsg == null && spamReason == null) { if (statusMsg == null && spamReason == null) {
templateName = "contactForm-confirmation.ftl"; templateName = TEMPLATE_CONFIRMATION;
} else { } else {
body.put("errorMessage", statusMsg); 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) { String originalReferer, String ipAddr, Configuration config) {
Map<String, Object> email = new HashMap<String, Object>(); Map<String, Object> email = new HashMap<String, Object>();
String template = "contactForm-email.ftl"; String template = TEMPLATE_EMAIL;
email.put("subject", deliveryfrom); email.put("subject", deliveryfrom);
email.put("name", webusername); email.put("name", webusername);
@ -254,7 +259,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
String spamReason, Configuration config) { String spamReason, Configuration config) {
Map<String, Object> backup = new HashMap<String, Object>(); Map<String, Object> backup = new HashMap<String, Object>();
String template = "contactForm-backup.ftl"; String template = TEMPLATE_BACKUP;
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
backup.put("datetime", cal.getTime().toString()); backup.put("datetime", cal.getTime().toString());

View file

@ -20,6 +20,8 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vedit.beans.LoginFormBean; import edu.cornell.mannlib.vedit.beans.LoginFormBean;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; 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.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil; 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.PortalWebUtil;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel; import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.files.Scripts; 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 Log log = LogFactory.getLog(FreemarkerHttpServlet.class);
private static final int FILTER_SECURITY_LEVEL = LoginFormBean.EDITOR; 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 ) public void doGet( HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException { throws IOException, ServletException {
@ -219,6 +240,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
doRedirect(vreq, response, values); doRedirect(vreq, response, values);
} else if (values instanceof ForwardResponseValues) { } else if (values instanceof ForwardResponseValues) {
doForward(vreq, response, values); doForward(vreq, response, values);
} else if (values instanceof RdfResponseValues) {
doRdf(vreq, response, values);
} }
} catch (ServletException e) { } catch (ServletException e) {
// TODO Auto-generated catch block // 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) { protected void doException(VitroRequest vreq, HttpServletResponse response, ResponseValues values) {
// Log the error, and display an error message on the page. // Log the error, and display an error message on the page.
log.error(values.getException(), values.getException()); 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. // Can be overridden by individual controllers to use a different basic page layout.
protected String getPageTemplateName() { protected String getPageTemplateName() {
return "page.ftl"; return Template.PAGE_DEFAULT.toString();
} }
// TEMPORARY method for transition from JSP to Freemarker. // TEMPORARY method for transition from JSP to Freemarker.
@ -552,10 +593,15 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
String getForwardUrl(); String getForwardUrl();
Throwable getException(); Throwable getException();
ContentType getContentType();
Model getModel();
} }
protected static abstract class BaseResponseValues implements ResponseValues { protected static abstract class BaseResponseValues implements ResponseValues {
private int statusCode = 0; private int statusCode = 0;
private ContentType contentType = null;
BaseResponseValues() { } BaseResponseValues() { }
@ -563,6 +609,10 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
this.statusCode = statusCode; this.statusCode = statusCode;
} }
BaseResponseValues(ContentType contentType) {
this.contentType = contentType;
}
public int getStatusCode() { public int getStatusCode() {
return statusCode; return statusCode;
} }
@ -570,6 +620,14 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
public void setStatusCode(int statusCode) { public void setStatusCode(int statusCode) {
this.statusCode = statusCode; this.statusCode = statusCode;
} }
public ContentType getContentType() {
return contentType;
}
public void setContentType(ContentType contentType) {
this.contentType = contentType;
}
} }
protected static class TemplateResponseValues extends BaseResponseValues { protected static class TemplateResponseValues extends BaseResponseValues {
@ -636,6 +694,12 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
"This is not an exception response."); "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 { protected static class RedirectResponseValues extends BaseResponseValues {
@ -684,6 +748,11 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
"This is not an exception response."); "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 { protected static class ForwardResponseValues extends BaseResponseValues {
@ -732,10 +801,15 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
"This is not an exception response."); "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 { 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; private final Throwable cause;
public ExceptionResponseValues(Throwable cause) { public ExceptionResponseValues(Throwable cause) {
@ -801,5 +875,66 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
"This is not a forwarding response."); "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;
}
} }
} }

View file

@ -110,7 +110,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
public static final String TEMPLATE_NEW = "imageUpload-newImage.ftl"; public static final String TEMPLATE_NEW = "imageUpload-newImage.ftl";
public static final String TEMPLATE_REPLACE = "imageUpload-replaceImage.ftl"; public static final String TEMPLATE_REPLACE = "imageUpload-replaceImage.ftl";
public static final String TEMPLATE_CROP = "imageUpload-cropImage.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"); private static final String URL_HERE = UrlBuilder.getUrl("/uploadImages");

View file

@ -74,6 +74,8 @@ public class IndividualController extends FreemarkerHttpServlet {
private String default_body_jsp = Controllers.ENTITY_JSP; private String default_body_jsp = Controllers.ENTITY_JSP;
private ApplicationBean appBean; private ApplicationBean appBean;
private static final String TEMPLATE_INDIVIDUAL = "individual.ftl";
private static final String TEMPLATE_HELP = "individual-help.ftl";
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
@ -83,44 +85,35 @@ public class IndividualController extends FreemarkerHttpServlet {
cleanUpSession(session); cleanUpSession(session);
// get URL without hostname or servlet context // get URL without hostname or servlet context
String url = vreq.getRequestURI().substring(vreq.getContextPath().length()); 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") ); String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") );
if( redirectURL != null ){ if( redirectURL != null ){
//doRedirect( vreq, res, redirectURL ); return new RedirectResponseValues(redirectURL);
return null;
}
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
if( rdfFormat != null ){
//doRdf( vreq, res, rdfFormat );
return null;
} }
Individual individual = null; Individual individual = null;
try { try {
individual = getEntityFromRequest(vreq); individual = getEntityFromRequest(vreq);
} catch (Throwable th) { } catch (Throwable th) {
//doHelp(res); return doHelp();
return null;
} }
if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){ if( individual == null || checkForHidden(vreq, individual) || checkForSunset(vreq, individual)){
//doNotFound(vreq, res); return doNotFound(vreq);
return null; }
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
if( rdfFormat != null ){
return doRdf(vreq, individual, rdfFormat);
} }
// If this is an uploaded file, redirect to its "alias URL". // If this is an uploaded file, redirect to its "alias URL".
String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, individual); String aliasUrl = getAliasUrlForBytestreamIndividual(vreq, individual);
if (aliasUrl != null) { if (aliasUrl != null) {
//res.sendRedirect(vreq.getContextPath() + aliasUrl); return new RedirectResponseValues(UrlBuilder.getUrl(vreq.getContextPath() + aliasUrl));
return null;
} }
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
@ -128,10 +121,10 @@ public class IndividualController extends FreemarkerHttpServlet {
int securityLevel = getSecurityLevel(session); int securityLevel = getSecurityLevel(session);
UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal()); UrlBuilder urlBuilder = new UrlBuilder(vreq.getPortal());
body.put("editStatus", getEditingData(vreq, securityLevel, individual, urlBuilder)); body.put("editStatus", getEditingData(vreq, securityLevel, individual, urlBuilder));
body.putAll(getIndividualData(vreq, individual));
body.put("title", individual.getName()); 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) { } catch (Throwable e) {
log.error(e); log.error(e);
@ -308,15 +301,9 @@ public class IndividualController extends FreemarkerHttpServlet {
return map; return map;
} }
private void doRdf(VitroRequest vreq, HttpServletResponse res, private ResponseValues doRdf(VitroRequest vreq, Individual individual,
ContentType rdfFormat) throws IOException, ServletException { ContentType rdfFormat) throws IOException, ServletException {
Individual indiv = getEntityFromRequest(vreq);
if( indiv == null ){
doNotFound(vreq, res);
return;
}
OntModel ontModel = null; OntModel ontModel = null;
HttpSession session = vreq.getSession(false); HttpSession session = vreq.getSession(false);
if( session != null ) if( session != null )
@ -324,19 +311,9 @@ public class IndividualController extends FreemarkerHttpServlet {
if( ontModel == null) if( ontModel == null)
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel"); ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
Model newModel; Model newModel = getRDF(individual, ontModel, ModelFactory.createDefaultModel(), 0);
newModel = getRDF(indiv, ontModel, ModelFactory.createDefaultModel(), 0);
res.setContentType(rdfFormat.getMediaType()); return new RdfResponseValues(rdfFormat, newModel);
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 );
} }
private void doRedirect(HttpServletRequest req, HttpServletResponse res, private void doRedirect(HttpServletRequest req, HttpServletResponse res,
@ -660,18 +637,11 @@ public class IndividualController extends FreemarkerHttpServlet {
doGet(request, response); doGet(request, response);
} }
private void doHelp(HttpServletResponse res) private ResponseValues doHelp() throws IOException, ServletException {
throws IOException, ServletException { return new TemplateResponseValues(TEMPLATE_HELP);
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 void doNotFound(HttpServletRequest req, HttpServletResponse res) private ResponseValues doNotFound(VitroRequest vreq) throws IOException, ServletException {
throws IOException, ServletException {
VitroRequest vreq = new VitroRequest(req);
Portal portal = vreq.getPortal(); Portal portal = vreq.getPortal();
ApplicationBean appBean = ApplicationBean.getAppBean(getServletContext()); ApplicationBean appBean = ApplicationBean.getAppBean(getServletContext());
int allPortalId = appBean.getAllPortalFlagNumeric(); int allPortalId = appBean.getAllPortalFlagNumeric();
@ -697,7 +667,7 @@ public class IndividualController extends FreemarkerHttpServlet {
else else
portalParam = "home=" + allPortalId; portalParam = "home=" + allPortalId;
String queryStr = req.getQueryString(); String queryStr = vreq.getQueryString();
if( queryStr == null && portalParam != null && !"".equals(portalParam)){ if( queryStr == null && portalParam != null && !"".equals(portalParam)){
queryStr = portalParam; queryStr = portalParam;
} else { } else {
@ -708,14 +678,14 @@ public class IndividualController extends FreemarkerHttpServlet {
queryStr = "?" + queryStr; queryStr = "?" + queryStr;
StringBuilder url = new StringBuilder(); StringBuilder url = new StringBuilder();
url.append( req.getContextPath() ); url.append( vreq.getContextPath() );
if( req.getContextPath() != null && !req.getContextPath().endsWith("/")) if( vreq.getContextPath() != null && !vreq.getContextPath().endsWith("/"))
url.append('/'); url.append('/');
if( portalPrefix != null && !"".equals(portalPrefix)) if( portalPrefix != null && !"".equals(portalPrefix))
url.append( portalPrefix ).append('/'); url.append( portalPrefix ).append('/');
String servletPath = req.getServletPath(); String servletPath = vreq.getServletPath();
String spath = ""; String spath = "";
if( servletPath != null ){ if( servletPath != null ){
if( servletPath.startsWith("/") ) if( servletPath.startsWith("/") )
@ -727,32 +697,24 @@ public class IndividualController extends FreemarkerHttpServlet {
if( spath != null && !"".equals(spath)) if( spath != null && !"".equals(spath))
url.append( spath ); url.append( spath );
if( req.getPathInfo() != null ) if( vreq.getPathInfo() != null )
url.append( req.getPathInfo() ); url.append( vreq.getPathInfo() );
if( queryStr != null && !"".equals(queryStr )) if( queryStr != null && !"".equals(queryStr ))
url.append( queryStr ); url.append( queryStr );
res.sendRedirect(url.toString()); return new RedirectResponseValues(url.toString());
return;
} }
}catch(Throwable th){ }catch(Throwable th){
log.error("could not do a redirect", th); log.error("could not do a redirect", th);
} }
//set title before we do the highlighting so we don't get markup in it. //set title before we do the highlighting so we don't get markup in it.
req.setAttribute("title","not found"); Map<String, Object> body = new HashMap<String, Object>();
res.setStatus(HttpServletResponse.SC_NOT_FOUND); 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=\"" return new TemplateResponseValues(Template.TITLED_ERROR_MESSAGE.toString(), body, HttpServletResponse.SC_NOT_FOUND);
+ 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);
} }
private String forURL(String frag) { private String forURL(String frag) {

View file

@ -26,13 +26,13 @@ public class IndividualListController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(IndividualListController.class.getName()); 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 @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
String templateName = "individualList.ftl"; String templateName = TEMPLATE_DEFAULT;
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
String errorMessage = null; String errorMessage = null;
String message = null; String message = null;
@ -97,7 +97,7 @@ public class IndividualListController extends FreemarkerHttpServlet {
} }
if (errorMessage != null) { if (errorMessage != null) {
templateName = "errorMessage.ftl"; templateName = Template.ERROR_MESSAGE.toString();
body.put("errorMessage", errorMessage); body.put("errorMessage", errorMessage);
} else if (message != null) { } else if (message != null) {
body.put("message", message); body.put("message", message);

View file

@ -28,6 +28,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(SiteAdminController.class); private static final Log log = LogFactory.getLog(SiteAdminController.class);
private static final String TEMPLATE_DEFAULT = "siteAdmin-main.ftl";
@Override @Override
public String getTitle(String siteName) { public String getTitle(String siteName) {
return siteName + " Site Administration"; return siteName + " Site Administration";
@ -86,7 +87,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
// } // }
// body.put("languageModeStr", languageMode); // body.put("languageModeStr", languageMode);
return new TemplateResponseValues("siteAdmin-main.ftl", body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} }

View file

@ -19,6 +19,7 @@ public class TermsOfUseController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(TermsOfUseController.class); private static final Log log = LogFactory.getLog(TermsOfUseController.class);
private static final String TEMPLATE_DEFAULT = "termsOfUse.ftl";
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
@ -32,7 +33,7 @@ public class TermsOfUseController extends FreemarkerHttpServlet {
body.put("copyrightAnchor", portal.getCopyrightAnchor()); body.put("copyrightAnchor", portal.getCopyrightAnchor());
return new TemplateResponseValues("termsOfUse.ftl", body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} }
@Override @Override

View file

@ -27,6 +27,7 @@ public class TestController extends FreemarkerHttpServlet {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(TestController.class); private static final Log log = LogFactory.getLog(TestController.class);
private static final String TEMPLATE_DEFAULT = "test.ftl";
@Override @Override
protected ResponseValues processRequest(VitroRequest vreq) { protected ResponseValues processRequest(VitroRequest vreq) {
@ -88,7 +89,7 @@ public class TestController extends FreemarkerHttpServlet {
body.put("title", "VIVO Test"); body.put("title", "VIVO Test");
return new TemplateResponseValues("test.ftl", body); return new TemplateResponseValues(TEMPLATE_DEFAULT, body);
} }
@Override @Override

View file

@ -29,7 +29,7 @@ public class UrlBuilder {
BROWSE("/browse"), BROWSE("/browse"),
CONTACT("/contact"), CONTACT("/contact"),
INDIVIDUAL("/individual"), INDIVIDUAL("/individual"),
INDIVIDUAL_LIST("/individuallist"), // entitylist individuallist INDIVIDUAL_LIST("/individuallist"),
SEARCH("/search"), SEARCH("/search"),
TERMS_OF_USE("/termsOfUse"), TERMS_OF_USE("/termsOfUse"),

View file

@ -39,7 +39,7 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl"; public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl";
/** Show error message */ /** 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_LOGIN_NAME = "loginName";
public static final String BODY_FORM_ACTION = "formAction"; public static final String BODY_FORM_ACTION = "formAction";

View file

@ -86,9 +86,14 @@ import freemarker.template.Configuration;
public class FreemarkerPagedSearchController extends FreemarkerHttpServlet implements Searcher { public class FreemarkerPagedSearchController extends FreemarkerHttpServlet implements Searcher {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private IndexSearcher searcher = null;
private static final Log log = LogFactory.getLog(FreemarkerPagedSearchController.class.getName()); 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."; String NORESULT_MSG = "The search returned no results.";
private IndexSearcher searcher = null;
private int defaultHitsPerPage = 25; private int defaultHitsPerPage = 25;
private int defaultMaxSearchSize= 1000; private int defaultMaxSearchSize= 1000;
@ -294,7 +299,7 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
return doSearchError(e); return doSearchError(e);
} }
return new TemplateResponseValues("search-pagedResults.ftl", body); return new TemplateResponseValues(TEMPLATE_SEARCH_RESULTS, body);
} }
private void alphaSortIndividuals(List<Individual> beans) { private void alphaSortIndividuals(List<Individual> beans) {
@ -755,20 +760,20 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
private TemplateResponseValues doSearchError(String message) { private TemplateResponseValues doSearchError(String message) {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("message", "Search failed: " + message); body.put("message", "Search failed: " + message);
return new TemplateResponseValues("search-error.ftl", body); return new TemplateResponseValues(TEMPLATE_ERROR, body);
} }
private ExceptionResponseValues doSearchError(Throwable e) { private ExceptionResponseValues doSearchError(Throwable e) {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("message", "Search failed: " + e.getMessage()); 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) { private TemplateResponseValues doNoQuery(Portal portal) {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("title", "Search " + portal.getAppName()); body.put("title", "Search " + portal.getAppName());
body.put("message", "No query entered."); body.put("message", "No query entered.");
return new TemplateResponseValues("search-error.ftl", body); return new TemplateResponseValues(TEMPLATE_ERROR, body);
} }
private TemplateResponseValues doFailedSearch(String message, String querytext) { private TemplateResponseValues doFailedSearch(String message, String querytext) {
@ -778,14 +783,14 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
message = "Search failed."; message = "Search failed.";
} }
body.put("message", message); body.put("message", message);
return new TemplateResponseValues("search-error.ftl", body); return new TemplateResponseValues(TEMPLATE_ERROR, body);
} }
private TemplateResponseValues doNoHits(String querytext) { private TemplateResponseValues doNoHits(String querytext) {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
body.put("title", "Search for '" + querytext + "'"); body.put("title", "Search for '" + querytext + "'");
body.put("message", "No matching results."); body.put("message", "No matching results.");
return new TemplateResponseValues("search-error.ftl", body); return new TemplateResponseValues(TEMPLATE_ERROR, body);
} }
/** /**

View file

@ -31,7 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
*/ */
public class IndexController extends FreemarkerHttpServlet { 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) // public void doPost(HttpServletRequest request, HttpServletResponse response)
// throws ServletException,IOException { // throws ServletException,IOException {
@ -103,10 +103,10 @@ public class IndexController extends FreemarkerHttpServlet {
} catch (IndexingException e) { } catch (IndexingException e) {
log.error("Error rebuilding search index",e); log.error("Error rebuilding search index",e);
body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage()); body.put("errorMessage", "There was an error while rebuilding the search index. " + e.getMessage());
return new ExceptionResponseValues("errorMessage.ftl", body, e); return new ExceptionResponseValues(Template.ERROR_MESSAGE.toString(), body, e);
} }
body.put("message","Rebuilding of index started."); body.put("message","Rebuilding of index started.");
return new TemplateResponseValues("message.ftl", body); return new TemplateResponseValues(Template.MESSAGE.toString(), body);
} }
} }

View file

@ -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">

View 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>