1 40 41 package org.dspace.app.webui.servlet; 42 43 import java.io.IOException ; 44 import java.sql.SQLException ; 45 import java.util.Date ; 46 import javax.mail.MessagingException ; 47 import javax.servlet.ServletException ; 48 import javax.servlet.http.HttpServletRequest ; 49 import javax.servlet.http.HttpServletResponse ; 50 51 52 import org.apache.log4j.Logger; 53 54 import org.dspace.app.webui.util.JSPManager; 55 import org.dspace.authorize.AuthorizeException; 56 import org.dspace.core.ConfigurationManager; 57 import org.dspace.core.Context; 58 import org.dspace.core.Email; 59 import org.dspace.core.LogManager; 60 import org.dspace.eperson.EPerson; 61 import org.dspace.handle.HandleManager; 62 import org.dspace.content.Item; 63 import org.dspace.content.Collection; 64 import org.dspace.content.DCValue; 65 66 67 73 public class SuggestServlet extends DSpaceServlet 74 { 75 76 private static Logger log = Logger.getLogger(SuggestServlet.class); 77 78 protected void doDSGet(Context context, HttpServletRequest request, 79 HttpServletResponse response) 80 throws ServletException , IOException , SQLException , AuthorizeException 81 { 82 String handle = request.getParameter("handle"); 84 85 String title = null; 87 String collName = null; 88 if (handle != null && !handle.equals("")) 89 { 90 Item item = (Item) HandleManager.resolveToObject(context, handle); 91 if (item != null) 92 { 93 DCValue[] titleDC = item.getDC("title", null, Item.ANY); 94 if (titleDC != null || titleDC.length > 0) 95 { 96 title = titleDC[0].value; 97 } 98 Collection[] colls = item.getCollections(); 99 collName = colls[0].getMetadata("name"); 100 } 101 } 102 else 103 { 104 String path = request.getPathInfo(); 105 log.info(LogManager.getHeader(context, "invalid_id", "path=" + path)); 106 JSPManager.showInvalidIDError(request, response, path, -1); 107 return; 108 } 109 if (title == null) 110 { 111 title = ""; 112 } 113 if(collName == null) 114 { 115 collName = ""; 116 } 117 request.setAttribute("suggest.title", title); 118 119 EPerson currentUser = context.getCurrentUser(); 121 String authEmail = null; 122 String userName = null; 123 124 if (currentUser != null) 125 { 126 authEmail = currentUser.getEmail(); 127 userName = currentUser.getFullName(); 128 } 129 130 if (request.getParameter("submit") != null) 131 { 132 String recipAddr = request.getParameter("recip_email"); 133 if (recipAddr == null || recipAddr.equals("")) 135 { 136 log.info(LogManager.getHeader(context, "show_suggest_form", 137 "problem=true")); 138 request.setAttribute("suggest.problem", new Boolean (true)); 139 JSPManager.showJSP(request, response, "/suggest/suggest.jsp"); 140 return; 141 } 142 String recipName = request.getParameter("recip_name"); 143 if (recipName == null || "".equals(recipName)) 144 { 145 recipName = ConfigurationManager.getProperty("webui.suggest.recipient"); 146 } 147 String senderName = request.getParameter("sender_name"); 148 if (senderName == null || "".equals(senderName) ) 149 { 150 if (userName != null) 152 { 153 senderName = userName; 154 } 155 else 156 { 157 senderName = ConfigurationManager.getProperty("webui.suggest.sender"); 159 } 160 } 161 String senderAddr = request.getParameter("sender_email"); 162 if (senderAddr == null || "".equals(senderAddr) ) 163 { 164 if (authEmail != null) 166 { 167 senderAddr = authEmail; 168 } 169 } 170 String itemUri = HandleManager.getCanonicalForm(handle); 171 String itemUrl = HandleManager.resolveToURL(context,handle); 172 String message = request.getParameter("message"); 173 String siteName = ConfigurationManager.getProperty("dspace.name"); 174 175 try 177 { 178 Email email = ConfigurationManager.getEmail("suggest"); 179 180 email.addRecipient(recipAddr); 182 email.addArgument(recipName); email.addArgument(senderName); email.addArgument(siteName); email.addArgument(title); email.addArgument(itemUri); email.addArgument(itemUrl); email.addArgument(collName); email.addArgument(message); 191 if ( senderAddr != null && ! "".equals(senderAddr)) 193 { 194 email.setReplyTo(senderAddr); 195 } 196 197 email.send(); 198 199 log.info(LogManager.getHeader(context, "sent_suggest", 200 "from=" + senderAddr)); 201 202 JSPManager.showJSP(request, response, "/suggest/suggest_ok.jsp"); 203 } 204 catch (MessagingException me) 205 { 206 log.warn(LogManager.getHeader(context, "error_mailing_suggest", ""), me); 207 JSPManager.showInternalError(request, response); 208 } 209 } 210 else 211 { 212 log.info(LogManager.getHeader(context, "show_suggest_form", "problem=false")); 214 request.setAttribute("authenticated.email", authEmail); 215 request.setAttribute("eperson.name", userName); 216 JSPManager.showJSP(request, response, "/suggest/suggest.jsp"); } 218 } 219 220 protected void doDSPost(Context context, HttpServletRequest request, 221 HttpServletResponse response) 222 throws ServletException , IOException , SQLException , AuthorizeException 223 { 224 doDSGet(context, request, response); 226 } 227 } 228 | Popular Tags |