Changed class Router to Routes to clarify its purpose. Decode the referrer url in the contact form email.

This commit is contained in:
rjy7 2010-05-19 21:08:48 +00:00
parent 947c6841c9
commit 4f77fa419e
9 changed files with 61 additions and 59 deletions

View file

@ -980,7 +980,7 @@
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>sendMail</servlet-name> <servlet-name>sendMail</servlet-name>
<url-pattern>/sendMail</url-pattern> <url-pattern>/submitFeedback</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet> <servlet>

View file

@ -20,14 +20,10 @@ import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
public class ContactMailController extends FreeMarkerHttpServlet { public class ContactMailController extends FreeMarkerHttpServlet {
private static final Logger LOG = Logger.getLogger(ContactMailController.class); private static final Logger LOG = Logger.getLogger(ContactMailController.class);
@ -240,44 +236,19 @@ public class ContactMailController extends FreeMarkerHttpServlet {
String comments, String deliveryfrom, String comments, String deliveryfrom,
String originalReferer, String ipAddr) { String originalReferer, String ipAddr) {
StringBuffer msgBuf = new StringBuffer(); Map<String, Object> email = new HashMap<String, Object>();
// contains the intro copy for the body of the email message String template = "commentForm/email.ftl";
String lineSeparator = System.getProperty("line.separator"); email.put("subject", deliveryfrom);
// \r\n on windows, \n on unix email.put("name", webusername);
email.put("emailAddress", webuseremail);
// from MyLibrary email.put("comments", comments);
msgBuf.setLength(0); email.put("ip", ipAddr);
msgBuf.append("Content-Type: text/html; charset='us-ascii'" + lineSeparator); if ( !(originalReferer == null || originalReferer.equals("none")) ) {
msgBuf.append("<html>" + lineSeparator ); email.put("referrer", urlDecode(originalReferer));
msgBuf.append("<head>" + lineSeparator );
msgBuf.append("<style>a {text-decoration: none}</style>" + lineSeparator );
msgBuf.append("<title>" + deliveryfrom + "</title>" + lineSeparator );
msgBuf.append("</head>" + lineSeparator );
msgBuf.append("<body>" + lineSeparator );
msgBuf.append("<h4>" + deliveryfrom + "</h4>" + lineSeparator );
msgBuf.append("<h4>From: "+webusername +" (" + webuseremail + ")" +
" at IP address " + ipAddr + "</h4>"+lineSeparator);
if (!(originalReferer == null || originalReferer.equals("none"))){
//The spam filter that is being used by the listsrv is rejecting <a href="...
//so try with out the markup, if that sill doesn't work,
//uncomment the following line to strip the http://
//msgBuf.append("<p><i>likely viewing page " + stripProtocol(originalReferer) );
msgBuf.append("<p><i>likely viewing page " + originalReferer );
} }
msgBuf.append(lineSeparator + "</i></p><h3>Comments:</h3>" + lineSeparator ); return mergeBodyToTemplate(template, email);
if (comments==null || comments.equals("")) {
msgBuf.append("<p>BLANK MESSAGE</p>");
} else {
msgBuf.append("<p>"+comments+"</p>");
}
msgBuf.append("</body>" + lineSeparator );
msgBuf.append("</html>" + lineSeparator );
return msgBuf.toString();
} }
private void writeBackupCopy(PrintWriter outFile, String msgText, private void writeBackupCopy(PrintWriter outFile, String msgText,

View file

@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -250,15 +251,15 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
Map<String, String> portalParam = new HashMap<String, String>(); Map<String, String> portalParam = new HashMap<String, String>();
portalParam.put("home", "" + portalId); portalParam.put("home", "" + portalId);
urls.put("about", getUrl(Router.ABOUT, portalParam)); urls.put("about", getUrl(Routes.ABOUT, portalParam));
if (ContactMailServlet.getSmtpHostFromProperties() != null) { if (ContactMailServlet.getSmtpHostFromProperties() != null) {
urls.put("contact", getUrl(Router.COMMENT_FORM, portalParam)); urls.put("contact", getUrl(Routes.COMMENT_FORM, portalParam));
} }
urls.put("search", getUrl(Router.SEARCH)); urls.put("search", getUrl(Routes.SEARCH));
urls.put("termsOfUse", getUrl(Router.TERMS_OF_USE, portalParam)); urls.put("termsOfUse", getUrl(Routes.TERMS_OF_USE, portalParam));
urls.put("login", getUrl(Router.LOGIN)); urls.put("login", getUrl(Routes.LOGIN));
urls.put("logout", getUrl(Router.LOGOUT)); urls.put("logout", getUrl(Routes.LOGOUT));
urls.put("siteAdmin", getUrl(Router.SITE_ADMIN)); urls.put("siteAdmin", getUrl(Routes.SITE_ADMIN));
setSharedVariable("urls", urls); setSharedVariable("urls", urls);
} }
@ -392,5 +393,15 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
return encodedUrl; return encodedUrl;
} }
public static String urlDecode(String url) {
String encoding = "ISO-8859-1";
String decodedUrl = null;
try {
decodedUrl = URLDecoder.decode(url, encoding);
} catch (UnsupportedEncodingException e) {
log.error("Error decoding url " + url + " with encoding " + encoding + ": Unsupported encoding.");
}
return decodedUrl;
}
} }

View file

@ -59,7 +59,7 @@ public class IndividualListController extends FreeMarkerHttpServlet {
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr); vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
if (vclass == null) { if (vclass == null) {
log.error("Couldn't retrieve vclass "+vitroClassIdStr); log.error("Couldn't retrieve vclass "+vitroClassIdStr);
response.sendRedirect(Router.BROWSE + "?"+vreq.getQueryString()); response.sendRedirect(Routes.BROWSE + "?"+vreq.getQueryString());
} }
} catch (Exception ex) { } catch (Exception ex) {
throw new HelpException("EntityListControllerFM: request parameter 'vclassId' must be a URI string"); throw new HelpException("EntityListControllerFM: request parameter 'vclassId' must be a URI string");

View file

@ -3,8 +3,9 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker; package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
// For now this class just holds constants for creating links. Could later be used to implement custom routing, // For now this class just holds constants for creating links. Could later be used to implement custom routing,
// if we go that route. // if we go that route. Separating from Controllers to keep track of which ones are being used with FreeMarker
public class Router { // Controllers; can recombine later if desired.
public class Routes {
public static final String ABOUT = "/about"; public static final String ABOUT = "/about";
public static final String BROWSE = "/browse"; public static final String BROWSE = "/browse";

View file

@ -8,13 +8,13 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.Router; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.Routes;
public class IndividualView extends ViewObject { public class IndividualView extends ViewObject {
private static final Log log = LogFactory.getLog(IndividualView.class.getName()); private static final Log log = LogFactory.getLog(IndividualView.class.getName());
private static final String URL = Router.INDIVIDUAL; private static final String URL = Routes.INDIVIDUAL;
private Individual individual; private Individual individual;

View file

@ -9,12 +9,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.Router; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.Routes;
public class VClassView extends ViewObject { public class VClassView extends ViewObject {
private static final Log log = LogFactory.getLog(VClassView.class.getName()); private static final Log log = LogFactory.getLog(VClassView.class.getName());
private static final String URL = Router.INDIVIDUAL_LIST; private static final String URL = Routes.INDIVIDUAL_LIST;
private VClass vclass; private VClass vclass;

View file

@ -1,3 +1,22 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#-- Comment form email response --> <#-- Comment form email response -->
<#-- Only inline styles seem to work in email. Can't get styles for margin to work, though. -->
<html>
<head>
<title>${subject}</title>
</head>
<body>
<h3>${subject}</h3>
<p>
<strong>From:</strong> ${name}<br />
<strong>Email address:</strong> ${emailAddress}<br />
<strong>IP address:</strong> ${ip}<br />
<#if referrer??>
<em>Likely viewing page: ${referrer}</em><br />
</#if>
<strong>Comments:</strong> ${comments}
</body>
</html>

View file

@ -27,7 +27,7 @@
</p> </p>
</#if> </#if>
<form name="contact_form" action="sendMail" method="post" onsubmit="return ValidateForm('contact_form');"> <form name="contact_form" action="submitFeedback" method="post" onsubmit="return ValidateForm('contact_form');">
<input type="hidden" name="home" value="${portalId}"/> <input type="hidden" name="home" value="${portalId}"/>
<input type="hidden" name="RequiredFields" value="webusername,webuseremail,s34gfd88p9x1"/> <input type="hidden" name="RequiredFields" value="webusername,webuseremail,s34gfd88p9x1"/>
<input type="hidden" name="RequiredFieldsNames" value="Name,Email address,Comments"/> <input type="hidden" name="RequiredFieldsNames" value="Name,Email address,Comments"/>