From f88a77d307eb26053af8668107b86a1a04b4c4f6 Mon Sep 17 00:00:00 2001
From: rjy7
Date: Wed, 19 May 2010 19:50:54 +0000
Subject: [PATCH] Rewrote comment form controllers and templates in FreeMarker.
---
webapp/config/web.xml | 31 +-
.../webapp/controller/CommentsController.java | 2 +-
.../freemarker/AboutController.java | 4 +-
.../freemarker/BrowseController.java | 7 +-
.../freemarker/CommentFormController.java | 128 +++---
.../freemarker/ContactMailController.java | 378 ++++++++++++++++++
.../freemarker/FreeMarkerHttpServlet.java | 56 +--
.../webapp/controller/freemarker/Router.java | 1 -
.../freemarker/TermsOfUseController.java | 10 +-
webapp/web/commentsForm.jsp | 2 +-
webapp/web/js/commentForm.js | 75 ++++
webapp/web/js/commentsForm.js | 79 ----
webapp/web/js/commentsForm.jsp | 7 +
.../templates/freemarker/body/classGroups.ftl | 20 +-
.../body/commentForm/confirmation.ftl | 9 +
.../freemarker/body/commentForm/email.ftl | 3 +
.../freemarker/body/commentForm/error.ftl | 13 +
.../freemarker/body/commentForm/form.ftl | 59 +++
.../templates/freemarker/body/termsOfUse.ftl | 4 +-
.../freemarker/components/footer.ftl | 2 -
.../freemarker/components/googleAnalytics.ftl | 21 +
.../freemarker/components/scripts.ftl | 6 +-
.../freemarker/components/stylesheets.ftl | 8 +-
.../web/templates/freemarker/page/default.ftl | 6 +-
24 files changed, 723 insertions(+), 208 deletions(-)
create mode 100644 webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java
create mode 100644 webapp/web/js/commentForm.js
delete mode 100644 webapp/web/js/commentsForm.js
create mode 100644 webapp/web/js/commentsForm.jsp
create mode 100644 webapp/web/templates/freemarker/body/commentForm/confirmation.ftl
create mode 100644 webapp/web/templates/freemarker/body/commentForm/email.ftl
create mode 100644 webapp/web/templates/freemarker/body/commentForm/error.ftl
create mode 100644 webapp/web/templates/freemarker/body/commentForm/form.ftl
create mode 100644 webapp/web/templates/freemarker/components/googleAnalytics.ftl
diff --git a/webapp/config/web.xml b/webapp/config/web.xml
index a56b95a50..0845fb8d2 100644
--- a/webapp/config/web.xml
+++ b/webapp/config/web.xml
@@ -849,6 +849,17 @@
/contact
+
+
+ CommentsController
+ edu.cornell.mannlib.vitro.webapp.controller.CommentsController
+
+
+ CommentsController
+ /comments-old
+
+
+
JSON Service
edu.cornell.mannlib.vitro.webapp.controller.JSONServlet
@@ -924,11 +935,27 @@
/dwr/*
+
sendmail
edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet
5
+
+ sendmail
+ /sendmail
+
+
+
+
+ sendMail
+ edu.cornell.mannlib.vitro.webapp.controller.freemarker.ContactMailController
+ 5
+
+
+ sendMail
+ /sendMail
+
mailusers
@@ -1046,10 +1073,6 @@
fetch
/fetch
-
-
- sendmail
- /sendmail
mailusers
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java
index 586c67d56..a1757ab01 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/CommentsController.java
@@ -57,7 +57,7 @@ public class CommentsController extends VitroHttpServlet{
}
request.setAttribute("siteName",portalBean.getAppName());
- request.setAttribute("scripts","/js/commentsForm.js");
+ request.setAttribute("scripts","/js/commentsForm.jsp");
if (request.getHeader("Referer") == null)
request.getSession().setAttribute("commentsFormReferer","none");
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/AboutController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/AboutController.java
index a4ce76efd..dda4c7b55 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/AboutController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/AboutController.java
@@ -24,8 +24,8 @@ public class AboutController extends FreeMarkerHttpServlet {
body.put("aboutText", portal.getAboutText());
body.put("acknowledgeText", portal.getAcknowledgeText());
- String templateName = "body/about.ftl";
- return mergeBodyToTemplate(templateName, body);
+ String bodyTemplate = "about.ftl";
+ return mergeBodyToTemplate(bodyTemplate, body);
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java
index 6106cb297..25e5ff016 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java
@@ -72,7 +72,8 @@ public class BrowseController extends FreeMarkerHttpServlet {
Map body = new HashMap();
// Set main page template attributes specific to this page
- root.put("contentClass", "siteMap");
+ // But the template should control this! Try putting in a div inside the content.
+ //root.put("contentClass", "siteMap");
if( vreq.getParameter("clearcache") != null ) //mainly for debugging
clearGroupCache();
@@ -99,8 +100,8 @@ public class BrowseController extends FreeMarkerHttpServlet {
body.put("classGroups", vcgroups);
}
- String templateName = "body/classGroups.ftl";
- return mergeBodyToTemplate(templateName, body);
+ String bodyTemplate = "classGroups.ftl";
+ return mergeBodyToTemplate(bodyTemplate, body);
}
public void destroy(){
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java
index 7846dda90..8c1c52508 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java
@@ -3,87 +3,85 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
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.utils.StringUtils;
/**
* Controller for comments ("contact us") page
* * @author bjl23
*/
public class CommentFormController extends FreeMarkerHttpServlet {
-
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request, response);
- }
-
- public void doGet( HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException {
- super.doGet(request,response);
- VitroRequest vreq = new VitroRequest(request);
- try {
- //this try block passes any errors to error.jsp
- if (!ContactMailServlet.isSmtpHostConfigured()) {
- request.setAttribute("title", "Comments and Feedback Form");
- request.setAttribute("bodyJsp", "/contact_err.jsp");// <<< this is where the body gets set
- request.setAttribute("ERR","This application has not yet been configured to send mail -- " +
- "smtp host has not been specified in the configuration properties file.");
- RequestDispatcher errd = request.getRequestDispatcher(Controllers.BASIC_JSP);
- errd.forward(request, response);
- }
- ApplicationBean appBean=vreq.getAppBean();
- Portal portalBean=vreq.getPortal();
-
- if ( (appBean.getMaxSharedPortalId()-appBean.getMinSharedPortalId()) > 1
- && ( (portalBean.getPortalId() >= appBean.getMinSharedPortalId()
- && portalBean.getPortalId() <= appBean.getMaxSharedPortalId() )
- || portalBean.getPortalId() == appBean.getSharedPortalFlagNumeric() )
- ) {
- request.setAttribute("portalType","CALSResearch");
- } else
- if (portalBean.getAppName().equalsIgnoreCase("CALS Impact")){
- request.setAttribute("portalType", "CALSImpact");
- } else if (portalBean.getAppName().equalsIgnoreCase("VIVO")) {
- request.setAttribute("portalType", "VIVO");
- } else {
- request.setAttribute("portalType", "clone");
- }
-
- request.setAttribute("siteName",portalBean.getAppName());
- request.setAttribute("scripts","/js/commentsForm.js");
-
- if (request.getHeader("Referer") == null)
- request.getSession().setAttribute("commentsFormReferer","none");
- else
- request.getSession().setAttribute("commentsFormReferer",request.getHeader("Referer"));
-
-
- request.setAttribute("portalId",Integer.valueOf(portalBean.getPortalId()));
-
- request.setAttribute("title", portalBean.getAppName()+" Comments and Feedback Form");
- request.setAttribute("bodyJsp", "/commentsForm.jsp");// <<< this is where the body gets set
- request.setAttribute("portalBean",portalBean);
-
- RequestDispatcher rd =
- request.getRequestDispatcher(Controllers.BASIC_JSP);
- rd.forward(request, response);
-
- } catch (Throwable e) {
- // This is how we use an error.jsp
- //it expects javax.servlet.jsp.jspException to be set to the
- //exception so that it can display the info out of that.
- request.setAttribute("javax.servlet.jsp.jspException", e);
- RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
- rd.include(request, response);
- }
+
+ private static final long serialVersionUID = 1L;
+ private static final Log log = LogFactory.getLog(CommentFormController.class.getName());
+
+ protected String getTitle() {
+ return appName + " Feedback Form";
+ }
+
+ protected String getBody() {
+
+ Map body = new HashMap();
+ String bodyTemplate;
+
+ 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 = "commentForm/error.ftl";
+ }
+
+ else if (StringUtils.isEmpty(portal.getContactMail())) {
+ body.put("errorMessage",
+ "The site administrator has not configured an email address to receive the form submission.");
+ bodyTemplate = "commentForm/error.ftl";
+ }
+
+ else {
+
+ ApplicationBean appBean = vreq.getAppBean();
+ int portalId = portal.getPortalId();
+
+ String portalType = null;
+ if ( (appBean.getMaxSharedPortalId()-appBean.getMinSharedPortalId()) > 1
+ && ( (portalId >= appBean.getMinSharedPortalId()
+ && portalId <= appBean.getMaxSharedPortalId() )
+ || portalId == appBean.getSharedPortalFlagNumeric() ) ) {
+ portalType = "CALSResearch";
+ } else if (appName.equalsIgnoreCase("CALS Impact")) {
+ portalType = "CALSImpact";
+ } else if (appName.equalsIgnoreCase("VIVO")){
+ portalType = "VIVO";
+ } else {
+ portalType = "clone";
+ }
+ body.put("portalType", portalType);
+
+ // Not used in template. Is it used in processing the form?
+ if (vreq.getHeader("Referer") == null) {
+ vreq.getSession().setAttribute("commentsFormReferer","none");
+ } else {
+ vreq.getSession().setAttribute("commentsFormReferer",vreq.getHeader("Referer"));
+ }
+
+ bodyTemplate = "commentForm/form.ftl";
+ }
+
+ return mergeBodyToTemplate(bodyTemplate, body);
}
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java
new file mode 100644
index 000000000..f35632baf
--- /dev/null
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ContactMailController.java
@@ -0,0 +1,378 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.SendFailedException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
+import edu.cornell.mannlib.vitro.webapp.beans.Portal;
+
+public class ContactMailController extends FreeMarkerHttpServlet {
+ private static final Logger LOG = Logger.getLogger(ContactMailController.class);
+
+ private final static String CONFIRM_PAGE = "/thankyou.jsp";
+ private final static String ERR_PAGE = "/contact_err.jsp";
+ private final static String SPAM_MESSAGE = "Your message was flagged as spam.";
+ private final static String EMAIL_BACKUP_FILE_PATH = "/WEB-INF/LatestMessage.html";
+
+ private final static String WEB_USERNAME_PARAM = "webusername";
+ private final static String WEB_USEREMAIL_PARAM = "webuseremail";
+ private final static String COMMENTS_PARAM = "s34gfd88p9x1";
+
+ private static String smtpHost = null;
+
+ public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
+ super.init(servletConfig);
+ smtpHost = getSmtpHostFromProperties();
+ }
+
+ public static boolean isSmtpHostConfigured() {
+ if( smtpHost==null || smtpHost.equals("")) {
+ return false;
+ }
+ return true;
+ }
+
+ public static String getSmtpHostFromProperties() {
+ String host = ConfigurationProperties.getProperty("Vitro.smtpHost");
+ if (host != null && !host.equals("")) {
+ LOG.debug("Found Vitro.smtpHost value of " + host);
+ } else {
+ LOG.debug("No Vitro.smtpHost specified");
+ }
+ return (host != null && host.length() > 0) ? host : null;
+ }
+
+ protected String getTitle() {
+ return appName + " Feedback Form";
+ }
+
+ protected String getBody() {
+
+ Map body = new HashMap();
+ String bodyTemplate = null;
+
+ String statusMsg = null; // holds the error status
+
+ if (!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 = "commentForm/error.ftl";
+ }
+
+ else {
+
+ String webusername = vreq.getParameter(WEB_USERNAME_PARAM);
+ String webuseremail = vreq.getParameter(WEB_USEREMAIL_PARAM);
+ String comments = vreq.getParameter(COMMENTS_PARAM);
+
+ String validationMessage = validateInput(webusername, webuseremail,
+ comments);
+ if (validationMessage != null) {
+ // rjy7 We should reload the form, not go to the error page!
+ body.put("errorMessage",
+ "Invalid submission");
+ bodyTemplate = "commentForm/error.ftl";
+ }
+
+ else {
+ webusername = webusername.trim();
+ webuseremail = webuseremail.trim();
+ comments = comments.trim();
+
+ String spamReason = null;
+
+ String originalReferer = (String) vreq.getSession().getAttribute("commentsFormReferer");
+ if (originalReferer != null) {
+ vreq.getSession().removeAttribute("commentsFormReferer");
+ /* does not support legitimate clients that don't send the Referer header
+ String referer = request.getHeader("Referer");
+ if (referer == null ||
+ (referer.indexOf("comments") <0
+ && referer.indexOf("correction") <0) ) {
+ spamReason = "The form was not submitted from the " +
+ "Contact Us or Corrections page.";
+ statusMsg = SPAM_MESSAGE;
+ }
+ */
+ } else {
+ originalReferer = "none";
+ }
+
+ if (spamReason == null) {
+ spamReason = checkForSpam(comments);
+ if (spamReason != null) {
+ statusMsg = SPAM_MESSAGE;
+ }
+ }
+
+ String formType = vreq.getParameter("DeliveryType");
+ String[] deliverToArray = null;
+ int recipientCount = 0;
+ String deliveryfrom = null;
+
+ if ("comment".equals(formType)) {
+ if (portal.getContactMail() == null || portal.getContactMail().trim().length()==0) {
+ LOG.error("No contact mail address defined in current portal "+portal.getPortalId());
+ throw new Error(
+ "To establish the Contact Us mail capability the system administrators must "
+ + "specify an email address in the current portal.");
+ } else {
+ deliverToArray = portal.getContactMail().split(",");
+ }
+ deliveryfrom = "Message from the "+portal.getAppName()+" Contact Form";
+ } else if ("correction".equals(formType)) {
+ if (portal.getCorrectionMail() == null || portal.getCorrectionMail().trim().length()==0) {
+ LOG.error("Expecting one or more correction email addresses to be specified in current portal "+portal.getPortalId()+"; will attempt to use contact mail address");
+ if (portal.getContactMail() == null || portal.getContactMail().trim().length()==0) {
+ LOG.error("No contact mail address or correction mail address defined in current portal "+portal.getPortalId());
+ } else {
+ deliverToArray = portal.getContactMail().split(",");
+ }
+ } else {
+ deliverToArray = portal.getCorrectionMail().split(",");
+ }
+ deliveryfrom = "Message from the "+portal.getAppName()+" Correction Form (ARMANN-nospam)";
+ } else {
+ deliverToArray = portal.getContactMail().split(",");
+ statusMsg = SPAM_MESSAGE ;
+ spamReason = "The form specifies no delivery type.";
+ }
+ recipientCount=(deliverToArray == null) ? 0 : deliverToArray.length;
+ if (recipientCount == 0) {
+ LOG.error("recipientCount is 0 when DeliveryType specified as \""+formType+"\"");
+ throw new Error(
+ "To establish the Contact Us mail capability the system administrators must "
+ + "specify at least one email address in the current portal.");
+ }
+
+ String msgText = composeEmail(webusername, webuseremail, comments,
+ deliveryfrom, originalReferer, vreq.getRemoteAddr());
+
+ // debugging
+ FileWriter fw = null;
+ try {
+ fw = new FileWriter(context.getRealPath(EMAIL_BACKUP_FILE_PATH),true);
+ }
+ catch (IOException e){
+ LOG.error("Can't open file to write email backup");
+ }
+ PrintWriter outFile = new PrintWriter(fw);
+ writeBackupCopy(outFile, msgText, spamReason);
+
+ // Set the smtp host
+ Properties props = System.getProperties();
+ props.put("mail.smtp.host", smtpHost);
+ Session s = Session.getDefaultInstance(props,null); // was Session.getInstance(props,null);
+ //s.setDebug(true);
+ try {
+
+ if (spamReason == null) {
+ sendMessage(s, webuseremail, deliverToArray, deliveryfrom,
+ recipientCount, msgText);
+ }
+
+ } catch (AddressException e) {
+ statusMsg = "Please supply a valid email address.";
+ outFile.println( statusMsg );
+ outFile.println( e.getMessage() );
+ } catch (SendFailedException e) {
+ statusMsg = "The system was unable to deliver your mail. Please try again later. [SEND FAILED]";
+ outFile.println( statusMsg );
+ outFile.println( e.getMessage() );
+ } catch (MessagingException e) {
+ statusMsg = "The system was unable to deliver your mail. Please try again later. [MESSAGING]";
+ outFile.println( statusMsg );
+ outFile.println( e.getMessage() );
+ e.printStackTrace();
+ }
+
+ outFile.flush();
+ outFile.close();
+
+ // Message was sent successfully
+ if (statusMsg == null && spamReason == null) {
+ bodyTemplate = "commentForm/confirmation.ftl";
+ } else {
+ body.put("errorMessage", statusMsg);
+ bodyTemplate = "commentForm/error.ftl";
+ }
+ }
+ }
+
+ return mergeBodyToTemplate(bodyTemplate, body);
+
+ }
+
+ /** Intended to mangle url so it can get through spam filtering
+ * http://host/dir/servlet?param=value -> host: dir/servlet?param=value */
+ public String stripProtocol( String in ){
+ if( in == null )
+ return "";
+ else
+ return in.replaceAll("http://", "host: " );
+ }
+
+ private String composeEmail(String webusername, String webuseremail,
+ String comments, String deliveryfrom,
+ String originalReferer, String ipAddr) {
+
+ StringBuffer msgBuf = new StringBuffer();
+ // contains the intro copy for the body of the email message
+
+ String lineSeparator = System.getProperty("line.separator");
+ // \r\n on windows, \n on unix
+
+ // from MyLibrary
+ msgBuf.setLength(0);
+ msgBuf.append("Content-Type: text/html; charset='us-ascii'" + lineSeparator);
+ msgBuf.append("" + lineSeparator );
+ msgBuf.append("" + lineSeparator );
+ msgBuf.append("" + lineSeparator );
+ msgBuf.append("" + deliveryfrom + " " + lineSeparator );
+ msgBuf.append("" + lineSeparator );
+ msgBuf.append("" + lineSeparator );
+ msgBuf.append("" + deliveryfrom + " " + lineSeparator );
+ msgBuf.append("From: "+webusername +" (" + webuseremail + ")" +
+ " at IP address " + ipAddr + " "+lineSeparator);
+
+ if (!(originalReferer == null || originalReferer.equals("none"))){
+ //The spam filter that is being used by the listsrv is rejecting likely viewing page " + stripProtocol(originalReferer) );
+ msgBuf.append(" likely viewing page " + originalReferer );
+ }
+
+ msgBuf.append(lineSeparator + "
Comments: " + lineSeparator );
+ if (comments==null || comments.equals("")) {
+ msgBuf.append("BLANK MESSAGE
");
+ } else {
+ msgBuf.append(""+comments+"
");
+ }
+ msgBuf.append("" + lineSeparator );
+ msgBuf.append("" + lineSeparator );
+
+ return msgBuf.toString();
+
+ }
+
+ private void writeBackupCopy(PrintWriter outFile, String msgText,
+ String spamReason) {
+ Calendar cal = Calendar.getInstance();
+ outFile.println(" ");
+ outFile.println();
+ outFile.println(""+cal.getTime()+"
");
+ outFile.println();
+ if (spamReason != null) {
+ outFile.println("REJECTED - SPAM
");
+ outFile.println(""+spamReason+"
");
+ outFile.println();
+ }
+ outFile.print( msgText );
+ outFile.println();
+ outFile.println();
+ outFile.flush();
+ // outFile.close();
+ }
+
+ private void sendMessage(Session s, String webuseremail,
+ String[] deliverToArray, String deliveryfrom, int recipientCount,
+ String msgText)
+ throws AddressException, SendFailedException, MessagingException {
+ // Construct the message
+ MimeMessage msg = new MimeMessage( s );
+ //System.out.println("trying to send message from servlet");
+
+ // Set the from address
+ msg.setFrom( new InternetAddress( webuseremail ));
+
+ // Set the recipient address
+
+ if (recipientCount>0){
+ InternetAddress[] address=new InternetAddress[recipientCount];
+ for (int i=0; i -1
+ || comments.indexOf("[/URL]") > -1
+ || comments.indexOf("[url=") > -1
+ || comments.indexOf("[URL=") > -1)) {
+ return "The message contained blog link markup.";
+ }
+
+ /* if message is absurdly short, treat as blog spam */
+ if (comments.length()<15) {
+ return "The message was too short.";
+ }
+
+ return null;
+
+ }
+}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java
index 277cd04ea..6f9dbca0d 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java
@@ -90,7 +90,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
root.put("body", getBody());
}
- protected void setSharedVariable(String key, String value) {
+ protected void setSharedVariable(String key, Object value) {
try {
config.setSharedVariable(key, value);
} catch (TemplateModelException e) {
@@ -134,6 +134,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
}
protected String mergeBodyToTemplate(String templateName, Map map) {
+ templateName = "body/" + templateName;
String body = mergeToTemplate(templateName, map).toString();
extractLinkTagsFromBody(body);
return body;
@@ -199,18 +200,10 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
// RY Can this be removed? Do templates need it? Ideally, they should not.
// Only needed for some weird stuff in search box that I think is only used in old default theme.
int portalId = portal.getPortalId();
- try {
- config.setSharedVariable("portalId", portalId);
- } catch (TemplateModelException e) {
- log.error("Can't set shared variable 'portalId'.");
- }
+ setSharedVariable("portalId", portalId);
appName = portal.getAppName();
- try {
- config.setSharedVariable("appName", appName);
- } catch (TemplateModelException e) {
- log.error("Can't set shared variable 'appName'.");
- }
+ setSharedVariable("siteName", appName);
setTemplateLoader();
@@ -221,23 +214,20 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
PortalWebUtil.populateSearchOptions(portal, appBean, vreq.getWebappDaoFactory().getPortalDao());
PortalWebUtil.populateNavigationChoices(portal, vreq, appBean, vreq.getWebappDaoFactory().getPortalDao());
- // We'll need to separate theme-general and theme-specific stylesheet
- // dirs, so we need either two attributes or a list.
- String themeDir = portal.getThemeDir();
- String stylesheetDir = getUrl(themeDir + "css/");
- try {
- config.setSharedVariable("stylesheetDir", stylesheetDir);
- } catch (TemplateModelException e) {
- log.error("Can't set shared variable 'stylesheetDir'.");
- }
-
- root.put("siteName", portal.getAppName());
root.put("tagline", portal.getShortHand());
- root.put("breadcrumbs", BreadCrumbsUtil.getBreadCrumbsDiv(request));
+ root.put("breadcrumbs", BreadCrumbsUtil.getBreadCrumbsDiv(vreq));
+
+ String themeDir = portal.getThemeDir();
setUrls(portalId, themeDir);
setLoginInfo();
setCopyrightInfo();
+ setThemeInfo(themeDir);
+
+ // *** TEMPORARY. The templates shouldn't need to know this. Doing temporarily for script files
+ // till we put the script/css loading strategy in place. (Templates make a call to add files
+ // to a view object. These get iterated through in scripts.ftl and stylesheets.ftl.)
+ setSharedVariable("contextPath", contextPath);
}
// Define the URLs that are accessible to the templates. Note that we do not create menus here,
@@ -248,8 +238,8 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
// view to control which links go where, and the link text and title.
Map urls = new HashMap();
- String homeUrl = (portal.getRootBreadCrumbURL()!=null && portal.getRootBreadCrumbURL().length()>0) ?
- portal.getRootBreadCrumbURL() : vreq.getContextPath()+"/";
+ String rootBreadCrumbUrl = portal.getRootBreadCrumbURL();
+ String homeUrl = StringUtils.isEmpty(rootBreadCrumbUrl) ? contextPath : rootBreadCrumbUrl;
urls.put("home", homeUrl);
String bannerImage = portal.getBannerImage();
@@ -262,7 +252,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
urls.put("about", getUrl(Router.ABOUT, portalParam));
if (ContactMailServlet.getSmtpHostFromProperties() != null) {
- urls.put("contact", getUrl(Router.CONTACT, portalParam));
+ urls.put("contact", getUrl(Router.COMMENT_FORM, portalParam));
}
urls.put("search", getUrl(Router.SEARCH));
urls.put("termsOfUse", getUrl(Router.TERMS_OF_USE, portalParam));
@@ -270,7 +260,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
urls.put("logout", getUrl(Router.LOGOUT));
urls.put("siteAdmin", getUrl(Router.SITE_ADMIN));
- root.put("urls", urls);
+ setSharedVariable("urls", urls);
}
private final void setLoginInfo() {
@@ -311,6 +301,18 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
root.put("copyright", copyright);
}
}
+
+ private final void setThemeInfo(String themeDir) {
+
+ setSharedVariable("themeDir", getUrl(themeDir));
+
+ // We'll need to separate theme-general and theme-specific stylesheet
+ // dirs, so we need either two attributes or a list.
+ setSharedVariable("stylesheetDir", getUrl(themeDir + "css/"));
+
+ setSharedVariable("siteIconDir", getUrl(themeDir + "site_icons/"));
+
+ }
// Define template locations. Template loader will look first in the theme-specific
// location, then in the vitro location.
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Router.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Router.java
index 5e1e4658d..15bb2a31b 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Router.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Router.java
@@ -8,7 +8,6 @@ public class Router {
public static final String ABOUT = "/about";
public static final String BROWSE = "/browse";
- public static final String CONTACT= "/comments"; // temporary - FreeMarkerHttpServlet in svn is looking for it
public static final String COMMENT_FORM = "/comments";
public static final String INDIVIDUAL = "/individual";
public static final String INDIVIDUAL_LIST = "/entitylist"; // change
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TermsOfUseController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TermsOfUseController.java
index 5b0eddb1f..129fe3866 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TermsOfUseController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/TermsOfUseController.java
@@ -23,15 +23,13 @@ public class TermsOfUseController extends FreeMarkerHttpServlet {
Map body = new HashMap();
- String websiteName = portal.getRootBreadCrumbAnchor();
- if (StringUtils.isEmpty(websiteName)) {
- websiteName = appName;
- }
+ String rootBreadCrumbAnchor = portal.getRootBreadCrumbAnchor();
+ String websiteName = StringUtils.isEmpty(rootBreadCrumbAnchor) ? appName : rootBreadCrumbAnchor;
body.put("websiteName", websiteName);
body.put("copyrightAnchor", portal.getCopyrightAnchor());
- String templateName = "body/termsOfUse.ftl";
- return mergeBodyToTemplate(templateName, body);
+ String bodyTemplate = "termsOfUse.ftl";
+ return mergeBodyToTemplate(bodyTemplate, body);
}
}
\ No newline at end of file
diff --git a/webapp/web/commentsForm.jsp b/webapp/web/commentsForm.jsp
index 98bd561e3..b3497d8fb 100644
--- a/webapp/web/commentsForm.jsp
+++ b/webapp/web/commentsForm.jsp
@@ -46,7 +46,7 @@
Disclaimer of Endorsement
Reference herein to any specific commercial product, process, or service by trade name,
diff --git a/webapp/web/templates/freemarker/components/footer.ftl b/webapp/web/templates/freemarker/components/footer.ftl
index 368a97848..918342435 100644
--- a/webapp/web/templates/freemarker/components/footer.ftl
+++ b/webapp/web/templates/freemarker/components/footer.ftl
@@ -24,5 +24,3 @@
All Rights Reserved. Terms of Use
-
-<#-- SCRIPT TAGS SHOULD GO HERE -->
\ No newline at end of file
diff --git a/webapp/web/templates/freemarker/components/googleAnalytics.ftl b/webapp/web/templates/freemarker/components/googleAnalytics.ftl
new file mode 100644
index 000000000..cbcdad571
--- /dev/null
+++ b/webapp/web/templates/freemarker/components/googleAnalytics.ftl
@@ -0,0 +1,21 @@
+<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
+
+<#-- NOTICE: This is SAMPLE Google Analytics code. You must replace it with your institution's code. -->
+
+<#--
+
+
+-->
diff --git a/webapp/web/templates/freemarker/components/scripts.ftl b/webapp/web/templates/freemarker/components/scripts.ftl
index 841b7965f..a38c12498 100644
--- a/webapp/web/templates/freemarker/components/scripts.ftl
+++ b/webapp/web/templates/freemarker/components/scripts.ftl
@@ -1 +1,5 @@
-<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
\ No newline at end of file
+<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
+
+<#include "googleAnalytics.ftl">
+
+<#-- OTHER SCRIPT TAGS HERE -->
\ No newline at end of file
diff --git a/webapp/web/templates/freemarker/components/stylesheets.ftl b/webapp/web/templates/freemarker/components/stylesheets.ftl
index 23321b49d..d44a8c9c1 100644
--- a/webapp/web/templates/freemarker/components/stylesheets.ftl
+++ b/webapp/web/templates/freemarker/components/stylesheets.ftl
@@ -3,6 +3,8 @@
-<#list stylesheets as stylesheet>
- ${stylesheet}
-#list>
+<#if stylesheeets??>
+ <#list stylesheets as stylesheet>
+ ${stylesheet}
+ #list>
+#if>
\ No newline at end of file
diff --git a/webapp/web/templates/freemarker/page/default.ftl b/webapp/web/templates/freemarker/page/default.ftl
index ab3f06026..70da460f2 100644
--- a/webapp/web/templates/freemarker/page/default.ftl
+++ b/webapp/web/templates/freemarker/page/default.ftl
@@ -22,7 +22,7 @@
-
class="${contentClass}" #if>>
+
<#-- We don't do title here because some pages don't get a title, or it may not be the same as the
text.
${title} -->
${body}
@@ -31,6 +31,8 @@
<#include "/components/footer.ftl">
-
+
+
+ <#include "/components/scripts.ftl">