1 40 package org.dspace.app.webui.servlet; 41 42 import java.io.IOException ; 43 import java.net.InetAddress ; 44 import java.sql.SQLException ; 45 import java.util.Date ; 46 47 import javax.mail.MessagingException ; 48 import javax.servlet.ServletException ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 52 import org.apache.log4j.Logger; 53 import org.dspace.app.webui.util.JSPManager; 54 import org.dspace.authorize.AuthorizeException; 55 import org.dspace.core.ConfigurationManager; 56 import org.dspace.core.Context; 57 import org.dspace.core.Email; 58 import org.dspace.core.LogManager; 59 import org.dspace.eperson.EPerson; 60 61 68 public class FeedbackServlet extends DSpaceServlet 69 { 70 71 private static Logger log = Logger.getLogger(FeedbackServlet.class); 72 73 protected void doDSGet(Context context, HttpServletRequest request, 74 HttpServletResponse response) throws ServletException , IOException , 75 SQLException , AuthorizeException 76 { 77 String fromPage = request.getHeader("Referer"); 80 81 String host = ConfigurationManager.getProperty("dspace.hostname"); 83 84 String basicHost = ""; 85 if (host.equals("localhost") || host.equals("127.0.0.1") 86 || host.equals(InetAddress.getLocalHost().getHostAddress())) 87 basicHost = host; 88 else 89 { 90 int lastDot = host.lastIndexOf("."); 93 basicHost = host.substring(host.substring(0, lastDot).lastIndexOf(".")); 94 } 95 96 if (fromPage == null || fromPage.indexOf(basicHost) == -1) 97 { 98 throw new AuthorizeException(); 99 } 100 101 String formEmail = request.getParameter("email"); 103 104 String userAgent = request.getHeader("User-Agent"); 106 107 String sessionID = request.getSession().getId(); 109 110 EPerson currentUser = context.getCurrentUser(); 112 String authEmail = null; 113 114 if (currentUser != null) 115 { 116 authEmail = currentUser.getEmail(); 117 } 118 119 if (request.getParameter("submit") != null) 121 { 122 String feedback = request.getParameter("feedback"); 123 124 if ((formEmail == null) || formEmail.equals("") 126 || (feedback == null) || feedback.equals("")) 127 { 128 log.info(LogManager.getHeader(context, "show_feedback_form", 129 "problem=true")); 130 request.setAttribute("feedback.problem", new Boolean (true)); 131 JSPManager.showJSP(request, response, "/feedback/form.jsp"); 132 133 return; 134 } 135 136 try 138 { 139 Email email = ConfigurationManager.getEmail("feedback"); 140 email.addRecipient(ConfigurationManager 141 .getProperty("feedback.recipient")); 142 143 email.addArgument(new Date ()); email.addArgument(formEmail); email.addArgument(authEmail); email.addArgument(fromPage); email.addArgument(userAgent); email.addArgument(sessionID); email.addArgument(feedback); 151 email.setReplyTo(formEmail); 153 154 email.send(); 155 156 log.info(LogManager.getHeader(context, "sent_feedback", "from=" 157 + formEmail)); 158 159 JSPManager.showJSP(request, response, 160 "/feedback/acknowledge.jsp"); 161 } 162 catch (MessagingException me) 163 { 164 log.warn(LogManager.getHeader(context, 165 "error_mailing_feedback", ""), me); 166 167 JSPManager.showInternalError(request, response); 168 } 169 } 170 else 171 { 172 log.info(LogManager.getHeader(context, "show_feedback_form", 174 "problem=false")); 175 request.setAttribute("authenticated.email", authEmail); 176 JSPManager.showJSP(request, response, "/feedback/form.jsp"); 177 } 178 } 179 180 protected void doDSPost(Context context, HttpServletRequest request, 181 HttpServletResponse response) throws ServletException , IOException , 182 SQLException , AuthorizeException 183 { 184 doDSGet(context, request, response); 186 } 187 } 188 | Popular Tags |