1 19 20 package com.sslexplorer.core.actions; 21 22 import java.util.List ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.action.ActionMapping; 31 32 import com.sslexplorer.core.CoreUtil; 33 import com.sslexplorer.core.LicenseAgreement; 34 import com.sslexplorer.core.forms.LicenseAgreementForm; 35 import com.sslexplorer.security.Constants; 36 import com.sslexplorer.security.SessionInfo; 37 38 public class LicenseAgreementDispatchAction extends DefaultDispatchAction { 39 40 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 41 throws Exception { 42 List l = (List )request.getSession().getAttribute(Constants.LICENSE_AGREEMENTS); 43 if(l == null || l.size() == 0) { 44 throw new Exception ("No license agreements to show."); 45 } 46 LicenseAgreement agreement = (LicenseAgreement)l.get(0); 47 ((LicenseAgreementForm)form).setAgreement(agreement); 48 return mapping.findForward("display"); 49 } 50 51 public ActionForward accept(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 52 throws Exception { 53 List l = (List )request.getSession().getAttribute(Constants.LICENSE_AGREEMENTS); 54 if(l == null || l.size() == 0) { 55 throw new Exception ("No license agreements to agree to."); 56 } 57 LicenseAgreement agreement = (LicenseAgreement)l.get(0); 58 agreement.getCallback().licenseAccepted(request); 59 removeAgreement(request.getSession(), l); 60 ActionForward fwd = agreement.getReturnTo(); 61 return fwd; 62 } 63 64 public ActionForward reject(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 65 throws Exception { 66 List l = (List )request.getSession().getAttribute(Constants.LICENSE_AGREEMENTS); 67 if(l == null || l.size() == 0) { 68 throw new Exception ("No license agreements to reject."); 69 } 70 LicenseAgreement agreement = (LicenseAgreement)l.get(0); 71 agreement.getCallback().licenseRejected(request); 72 removeAgreement(request.getSession(), l); 73 return agreement.getReturnTo(); 74 } 75 76 private void removeAgreement(HttpSession session, List l) { 77 l.remove(0); 78 if(l.size() == 0) { 79 session.removeAttribute(Constants.LICENSE_AGREEMENTS); 80 CoreUtil.removePageInterceptListener(session, CoreUtil.getPageInterceptListenerById(session, "licenseAgreement")); 81 } 82 } 83 84 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 85 return SessionInfo.ALL_CONTEXTS; 86 } 87 88 } | Popular Tags |