1 40 package org.dspace.app.webui.servlet; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 45 import javax.servlet.ServletException ; 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.servlet.http.HttpServletResponse ; 48 49 import org.apache.log4j.Logger; 50 import org.dspace.app.webui.util.JSPManager; 51 import org.dspace.app.webui.util.UIUtil; 52 import org.dspace.authorize.AuthorizeException; 53 import org.dspace.content.Collection; 54 import org.dspace.core.Context; 55 import org.dspace.eperson.EPerson; 56 import org.dspace.eperson.Subscribe; 57 58 64 public class SubscribeServlet extends DSpaceServlet 65 { 66 67 private static Logger log = Logger.getLogger(SubscribeServlet.class); 68 69 protected void doDSGet(Context context, HttpServletRequest request, 70 HttpServletResponse response) throws ServletException , IOException , 71 SQLException , AuthorizeException 72 { 73 showSubscriptions(context, request, response, false); 75 } 76 77 protected void doDSPost(Context context, HttpServletRequest request, 78 HttpServletResponse response) throws ServletException , IOException , 79 SQLException , AuthorizeException 80 { 81 86 String submit = UIUtil.getSubmitButton(request, "submit"); 87 EPerson e = context.getCurrentUser(); 88 89 if (submit.equals("submit_clear")) 90 { 91 Subscribe.unsubscribe(context, e, null); 93 94 showSubscriptions(context, request, response, true); 96 97 context.complete(); 98 } 99 else if (submit.equals("submit_unsubscribe")) 100 { 101 int collID = UIUtil.getIntParameter(request, "collection"); 102 Collection c = Collection.find(context, collID); 103 104 if (c != null) 106 { 107 Subscribe.unsubscribe(context, e, c); 108 } 109 110 showSubscriptions(context, request, response, true); 112 113 context.complete(); 114 } 115 else 116 { 117 response.sendRedirect(response.encodeRedirectURL(request 119 .getContextPath() 120 + "/mydspace")); 121 } 122 } 123 124 137 private void showSubscriptions(Context context, HttpServletRequest request, 138 HttpServletResponse response, boolean updated) 139 throws ServletException , IOException , SQLException 140 { 141 Collection[] subs = Subscribe.getSubscriptions(context, context 143 .getCurrentUser()); 144 145 request.setAttribute("subscriptions", subs); 146 request.setAttribute("updated", new Boolean (updated)); 147 148 JSPManager.showJSP(request, response, "/mydspace/subscriptions.jsp"); 149 } 150 } 151 | Popular Tags |