Clean up paths and names relating to contact form. Use freemarker template to generate email backup.

This commit is contained in:
rjy7 2010-05-25 20:49:50 +00:00
parent a16985ccaa
commit 8b0665a0d7
10 changed files with 61 additions and 64 deletions

View file

@ -804,6 +804,7 @@
<url-pattern>/listObjectPropertyStatements</url-pattern>
</servlet-mapping>
<!--
<servlet>
<servlet-name>EntityListController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.EntityListController</servlet-class>
@ -812,6 +813,7 @@
<servlet-name>EntityListController</servlet-name>
<url-pattern>/entitylist</url-pattern>
</servlet-mapping>
-->
<servlet>
<servlet-name>IndividualListController</servlet-name>
@ -863,29 +865,14 @@
</servlet-mapping>
<servlet>
<servlet-name>CommentFormController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.CommentFormController</servlet-class>
<servlet-name>ContactFormController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.freemarker.ContactFormController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CommentFormController</servlet-name>
<url-pattern>/comments</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CommentFormController</servlet-name>
<servlet-name>ContactFormController</servlet-name>
<url-pattern>/contact</url-pattern>
</servlet-mapping>
<!-- TEMPORARY - for comparison with new version -->
<servlet>
<servlet-name>CommentsController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.CommentsController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CommentsController</servlet-name>
<url-pattern>/comments-old</url-pattern>
</servlet-mapping>
<!-- end TEMPORARY -->
<servlet>
<servlet-name>JSON Service</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.JSONServlet</servlet-class>

View file

@ -25,10 +25,10 @@ import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
* Controller for comments ("contact us") page
* * @author bjl23
*/
public class CommentFormController extends FreeMarkerHttpServlet {
public class ContactFormController extends FreeMarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(CommentFormController.class.getName());
private static final Log log = LogFactory.getLog(ContactFormController.class.getName());
protected String getTitle() {
return appName + " Feedback Form";
@ -43,13 +43,13 @@ public class CommentFormController extends FreeMarkerHttpServlet {
body.put("errorMessage",
"This application has not yet been configured to send mail. " +
"An smtp host has not been specified in the configuration properties file.");
bodyTemplate = "commentForm/error.ftl";
bodyTemplate = "contactForm/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";
bodyTemplate = "contactForm/error.ftl";
}
else {
@ -75,12 +75,12 @@ public class CommentFormController extends FreeMarkerHttpServlet {
// Not used in template. Is it used in processing the form?
if (vreq.getHeader("Referer") == null) {
vreq.getSession().setAttribute("commentsFormReferer","none");
vreq.getSession().setAttribute("contactFormReferer","none");
} else {
vreq.getSession().setAttribute("commentsFormReferer",vreq.getHeader("Referer"));
vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer"));
}
bodyTemplate = "commentForm/form.ftl";
bodyTemplate = "contactForm/form.ftl";
}
return mergeBodyToTemplate(bodyTemplate, body);

View file

@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.Date;
@ -77,7 +78,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
body.put("errorMessage",
"This application has not yet been configured to send mail. " +
"An smtp host has not been specified in the configuration properties file.");
bodyTemplate = "commentForm/error.ftl";
bodyTemplate = "contactForm/error.ftl";
}
else {
@ -93,7 +94,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
// rjy7 We should reload the form, not go to the error page!
body.put("errorMessage",
"Invalid submission");
bodyTemplate = "commentForm/error.ftl";
bodyTemplate = "contactForm/error.ftl";
}
else {
@ -103,9 +104,9 @@ public class ContactMailController extends FreeMarkerHttpServlet {
String spamReason = null;
String originalReferer = (String) vreq.getSession().getAttribute("commentsFormReferer");
String originalReferer = (String) vreq.getSession().getAttribute("contactFormReferer");
if (originalReferer != null) {
vreq.getSession().removeAttribute("commentsFormReferer");
vreq.getSession().removeAttribute("contactFormReferer");
/* does not support legitimate clients that don't send the Referer header
String referer = request.getHeader("Referer");
if (referer == null ||
@ -132,7 +133,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
int recipientCount = 0;
String deliveryfrom = null;
if ("comment".equals(formType)) {
if ("contact".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(
@ -142,18 +143,6 @@ public class ContactMailController extends FreeMarkerHttpServlet {
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 ;
@ -212,10 +201,10 @@ public class ContactMailController extends FreeMarkerHttpServlet {
// Message was sent successfully
if (statusMsg == null && spamReason == null) {
bodyTemplate = "commentForm/confirmation.ftl";
bodyTemplate = "contactForm/confirmation.ftl";
} else {
body.put("errorMessage", statusMsg);
bodyTemplate = "commentForm/error.ftl";
bodyTemplate = "contactForm/error.ftl";
}
}
}
@ -238,7 +227,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
String originalReferer, String ipAddr) {
Map<String, Object> email = new HashMap<String, Object>();
String template = "commentForm/email.ftl";
String template = "contactForm/email.ftl";
email.put("subject", deliveryfrom);
email.put("name", webusername);
@ -254,19 +243,21 @@ public class ContactMailController extends FreeMarkerHttpServlet {
private void writeBackupCopy(PrintWriter outFile, String msgText,
String spamReason) {
Map<String, Object> backup = new HashMap<String, Object>();
String template = "contactForm/backup.ftl";
Calendar cal = Calendar.getInstance();
outFile.println("<hr/>");
outFile.println();
outFile.println("<p>"+cal.getTime()+"</p>");
outFile.println();
backup.put("datetime", cal.getTime().toString());
if (spamReason != null) {
outFile.println("<p>REJECTED - SPAM</p>");
outFile.println("<p>"+spamReason+"</p>");
outFile.println();
backup.put("spamReason", spamReason);
}
outFile.print( msgText );
outFile.println();
outFile.println();
backup.put("msgText", msgText);
String backupText = mergeBodyToTemplate(template, backup);
outFile.print(backupText);
outFile.flush();
//outFile.close();
}

View file

@ -193,7 +193,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
urls.put("about", getUrl(Routes.ABOUT, portalParam));
if (ContactMailServlet.getSmtpHostFromProperties() != null) {
urls.put("contact", getUrl(Routes.COMMENT_FORM, portalParam));
urls.put("contact", getUrl(Routes.CONTACT, portalParam));
}
urls.put("search", getUrl(Routes.SEARCH));
urls.put("termsOfUse", getUrl(Routes.TERMS_OF_USE, portalParam));

View file

@ -9,9 +9,9 @@ public class Routes {
public static final String ABOUT = "/about";
public static final String BROWSE = "/browse";
public static final String COMMENT_FORM = "/comments";
public static final String CONTACT = "/contact";
public static final String INDIVIDUAL = "/individual";
public static final String INDIVIDUAL_LIST = "/individuallist"; // "/entitylist"; "/individuallist";
public static final String INDIVIDUAL_LIST = "/individuallist";
public static final String SEARCH = "/search";
public static final String TERMS_OF_USE = "/termsOfUse";

View file

@ -0,0 +1,16 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Backup of contact mail email -->
<p>${datetime}</p>
<#if spamReason??>
<div style="color:red;">
<p>REJECTED - SPAM</p>
<p>${spamReason}</p>
</div>
</#if>
${msgText}
<hr />

View file

@ -1,6 +1,6 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Confirmation page for comment form -->
<#-- Contact form submission confirmation page -->
<h2>Thank you for your feedback</h2>
<img src="${siteIconPath}/mail.gif" alt="mailbox"/><br/>

View file

@ -1,6 +1,6 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Comment form email response -->
<#-- Contact form email response -->
<#-- Only inline styles seem to work in email. Can't get styles for margin to work, though. -->

View file

@ -1,7 +1,10 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<img src="${siteIconPath}/bomb.gif" alt="email error"/>
<#-- Contact form processing errors -->
<h2>${title}</h2>
<img src="${siteIconPath}/bomb.gif" alt="email error"/>
<p class="normal">An error occurred during the processing of your request.<br />
<#if errorMessage?has_content>

View file

@ -33,7 +33,7 @@
<input type="hidden" name="RequiredFieldsNames" value="Name,Email address,Comments"/>
<input type="hidden" name="EmailFields" value="webuseremail"/>
<input type="hidden" name="EmailFieldsNames" value="emailaddress"/>
<input type="hidden" name="DeliveryType" value="comment"/>
<input type="hidden" name="DeliveryType" value="contact"/>
<label for="webusername">Full name</label>
<p><input style="width:33%;" type="text" name="webusername" maxlength="255"/></p>