KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > actions > LicenseAgreementDispatchAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core.actions;
21
22 import java.util.List JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import javax.servlet.http.HttpSession JavaDoc;
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 JavaDoc request, HttpServletResponse JavaDoc response)
41                     throws Exception JavaDoc {
42         List JavaDoc l = (List JavaDoc)request.getSession().getAttribute(Constants.LICENSE_AGREEMENTS);
43         if(l == null || l.size() == 0) {
44             throw new Exception JavaDoc("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 JavaDoc request, HttpServletResponse JavaDoc response)
52                     throws Exception JavaDoc {
53         List JavaDoc l = (List JavaDoc)request.getSession().getAttribute(Constants.LICENSE_AGREEMENTS);
54         if(l == null || l.size() == 0) {
55             throw new Exception JavaDoc("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 JavaDoc request, HttpServletResponse JavaDoc response)
65                     throws Exception JavaDoc {
66         List JavaDoc l = (List JavaDoc)request.getSession().getAttribute(Constants.LICENSE_AGREEMENTS);
67         if(l == null || l.size() == 0) {
68             throw new Exception JavaDoc("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 JavaDoc session, List JavaDoc 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 JavaDoc request, HttpServletResponse JavaDoc response) {
85         return SessionInfo.ALL_CONTEXTS;
86     }
87
88 }
Popular Tags