Changed class Router to Routes to clarify its purpose. Decode the referrer url in the contact form email.
This commit is contained in:
parent
947c6841c9
commit
4f77fa419e
9 changed files with 61 additions and 59 deletions
|
@ -980,7 +980,7 @@
|
|||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>sendMail</servlet-name>
|
||||
<url-pattern>/sendMail</url-pattern>
|
||||
<url-pattern>/submitFeedback</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
|
|
|
@ -20,14 +20,10 @@ 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);
|
||||
|
@ -239,45 +235,20 @@ public class ContactMailController extends FreeMarkerHttpServlet {
|
|||
private String composeEmail(String webusername, String webuseremail,
|
||||
String comments, String deliveryfrom,
|
||||
String originalReferer, String ipAddr) {
|
||||
|
||||
Map<String, Object> email = new HashMap<String, Object>();
|
||||
String template = "commentForm/email.ftl";
|
||||
|
||||
email.put("subject", deliveryfrom);
|
||||
email.put("name", webusername);
|
||||
email.put("emailAddress", webuseremail);
|
||||
email.put("comments", comments);
|
||||
email.put("ip", ipAddr);
|
||||
if ( !(originalReferer == null || originalReferer.equals("none")) ) {
|
||||
email.put("referrer", urlDecode(originalReferer));
|
||||
}
|
||||
|
||||
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("<html>" + lineSeparator );
|
||||
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 );
|
||||
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();
|
||||
|
||||
return mergeBodyToTemplate(template, email);
|
||||
}
|
||||
|
||||
private void writeBackupCopy(PrintWriter outFile, String msgText,
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -250,15 +251,15 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
|
|||
Map<String, String> portalParam = new HashMap<String, String>();
|
||||
portalParam.put("home", "" + portalId);
|
||||
|
||||
urls.put("about", getUrl(Router.ABOUT, portalParam));
|
||||
urls.put("about", getUrl(Routes.ABOUT, portalParam));
|
||||
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("termsOfUse", getUrl(Router.TERMS_OF_USE, portalParam));
|
||||
urls.put("login", getUrl(Router.LOGIN));
|
||||
urls.put("logout", getUrl(Router.LOGOUT));
|
||||
urls.put("siteAdmin", getUrl(Router.SITE_ADMIN));
|
||||
urls.put("search", getUrl(Routes.SEARCH));
|
||||
urls.put("termsOfUse", getUrl(Routes.TERMS_OF_USE, portalParam));
|
||||
urls.put("login", getUrl(Routes.LOGIN));
|
||||
urls.put("logout", getUrl(Routes.LOGOUT));
|
||||
urls.put("siteAdmin", getUrl(Routes.SITE_ADMIN));
|
||||
|
||||
setSharedVariable("urls", urls);
|
||||
}
|
||||
|
@ -392,5 +393,15 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -59,7 +59,7 @@ public class IndividualListController extends FreeMarkerHttpServlet {
|
|||
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
|
||||
if (vclass == null) {
|
||||
log.error("Couldn't retrieve vclass "+vitroClassIdStr);
|
||||
response.sendRedirect(Router.BROWSE + "?"+vreq.getQueryString());
|
||||
response.sendRedirect(Routes.BROWSE + "?"+vreq.getQueryString());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new HelpException("EntityListControllerFM: request parameter 'vclassId' must be a URI string");
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
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,
|
||||
// if we go that route.
|
||||
public class Router {
|
||||
// if we go that route. Separating from Controllers to keep track of which ones are being used with FreeMarker
|
||||
// Controllers; can recombine later if desired.
|
||||
public class Routes {
|
||||
|
||||
public static final String ABOUT = "/about";
|
||||
public static final String BROWSE = "/browse";
|
|
@ -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.Portal;
|
||||
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 {
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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 {
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,3 +1,22 @@
|
|||
<#-- $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>
|
|
@ -27,7 +27,7 @@
|
|||
</p>
|
||||
</#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="RequiredFields" value="webusername,webuseremail,s34gfd88p9x1"/>
|
||||
<input type="hidden" name="RequiredFieldsNames" value="Name,Email address,Comments"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue