KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > sample > samplewizard > actions > SampleFinishAction


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.sample.samplewizard.actions;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.ActionForm;
31 import org.apache.struts.action.ActionForward;
32 import org.apache.struts.action.ActionMapping;
33
34 import com.sslexplorer.core.CoreEvent;
35 import com.sslexplorer.core.CoreServlet;
36 import com.sslexplorer.policyframework.ResourceChangeEvent;
37 import com.sslexplorer.sample.Sample;
38 import com.sslexplorer.sample.SamplePlugin;
39 import com.sslexplorer.sample.samplewizard.forms.SampleDefaultDetailsForm;
40 import com.sslexplorer.security.SessionInfo;
41 import com.sslexplorer.wizard.AbstractWizardSequence;
42 import com.sslexplorer.wizard.WizardActionStatus;
43 import com.sslexplorer.wizard.actions.AbstractWizardAction;
44 import com.sslexplorer.wizard.forms.AbstractWizardFinishForm;
45
46 /**
47  * <p>
48  * The final action in which the resource is created.
49  *
50  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
51  *
52  */

53 public class SampleFinishAction extends AbstractWizardAction {
54     final static Log log = LogFactory.getLog(SampleFinishAction.class);
55
56     /**
57      * Constructor.
58      */

59     public SampleFinishAction() {
60         super();
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
67      * org.apache.struts.action.ActionForm,
68      * javax.servlet.http.HttpServletRequest,
69      * javax.servlet.http.HttpServletResponse)
70      */

71     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
72         return SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
73     }
74
75     /*
76      * (non-Javadoc)
77      *
78      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
79      * org.apache.struts.action.ActionForm,
80      * javax.servlet.http.HttpServletRequest,
81      * javax.servlet.http.HttpServletResponse)
82      */

83     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
84                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
85         List JavaDoc actionStatus = new ArrayList JavaDoc();
86         AbstractWizardSequence seq = getWizardSequence(request);
87         String JavaDoc name = (String JavaDoc) seq.getAttribute(SampleDefaultDetailsForm.ATTR_RESOURCE_NAME, null);
88         String JavaDoc description = (String JavaDoc) seq.getAttribute(SampleDefaultDetailsForm.ATTR_RESOURCE_DESCRIPTION, null);
89         boolean favorite = ((Boolean JavaDoc) seq.getAttribute(SampleDefaultDetailsForm.ATTR_FAVORITE, Boolean.FALSE)).booleanValue();
90         int parentResourcePermission = ((Integer JavaDoc) seq.getAttribute(SampleDefaultDetailsForm.ATTR_PARENT_RESOURCE_PERMISSION,
91                         new Integer JavaDoc(0))).intValue();
92         Sample sample = null;
93         try {
94             try {
95                 sample = SamplePlugin.getDatabase().addSample(name, description, parentResourcePermission);
96                 // #ifdef XTRA
97
CoreServlet.getServlet().fireCoreEvent(new ResourceChangeEvent(this,
98                     SamplePlugin.EVT_SAMPLE_CREATED, sample, getSessionInfo(request), CoreEvent.STATE_SUCCESSFUL));
99                 // #endif
100
}
101             catch(Exception JavaDoc e) {
102                 // #ifdef XTRA
103
CoreServlet.getServlet().fireCoreEvent(new ResourceChangeEvent(this,
104                     SamplePlugin.EVT_SAMPLE_CREATED, sample, getSessionInfo(request), CoreEvent.STATE_UNSUCCESSFUL));
105                 // #endif
106
throw e;
107             }
108             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
109                             "samplewizard.sampleFinish.status.profileCreated"));
110         } catch (Exception JavaDoc e) {
111             log.error("Failed to create profile.", e);
112             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
113                             "samplewizard.sampleFinish.status.failedToCreateProfile", e.getMessage()));
114         }
115         // TODO do the attaching.
116
if (sample != null) {
117             actionStatus.add(attachToPoliciesAndAddToFavorites("samplewizard.sampleFinish", seq, sample, favorite, request));
118         }
119         ((AbstractWizardFinishForm) form).setActionStatus(actionStatus);
120         return super.unspecified(mapping, form, request, response);
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see com.sslexplorer.wizard.actions.AbstractFinishWizardAction#exit(org.apache.struts.action.ActionMapping,
127      * org.apache.struts.action.ActionForm,
128      * javax.servlet.http.HttpServletRequest,
129      * javax.servlet.http.HttpServletResponse)
130      */

131     public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
132                     throws Exception JavaDoc {
133         return cancel(mapping, form, request, response);
134     }
135
136 }
137
Popular Tags