KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > wizard > forms > AbstractWizardForm


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.wizard.forms;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.struts.action.ActionMapping;
25
26 import com.sslexplorer.core.forms.CoreForm;
27 import com.sslexplorer.security.Constants;
28 import com.sslexplorer.wizard.AbstractWizardSequence;
29
30 /**
31  * Abstract superclass class for all <i>Wizard Pages</i>. Every page within
32  * the wizard framework must provide a concrete implementation of this class.
33  *
34  *
35  * @author Brett Smith <brett@3sp.com>
36  */

37 public abstract class AbstractWizardForm extends CoreForm {
38     
39     private int gotoStep;
40     
41     public AbstractWizardForm() {
42         super();
43     }
44     
45     /**
46      * Initialise the wizard form whenever it is visited
47      *
48      * @param sequence sequence
49      * @param request TODO
50      * @throws Exception on any error
51      */

52     public abstract void init(AbstractWizardSequence sequence, HttpServletRequest JavaDoc request) throws Exception JavaDoc;
53
54     /* (non-Javadoc)
55      * @see com.sslexplorer.core.forms.CoreForm#isCommiting()
56      */

57     public boolean isCommiting() {
58         return super.isCommiting() || "next".equals(getActionTarget()) || "gotoStep".equals(getActionTarget()) ||
59             "finish".equals(getActionTarget());
60     }
61
62     /**
63      * Apply the current state to the sequence object whenever the user
64      * changes pages.
65      *
66      * @param sequence sequence
67      * @throws Exception on any error
68      */

69     public abstract void apply(AbstractWizardSequence sequence) throws Exception JavaDoc;
70     
71     /* (non-Javadoc)
72      * @see com.sslexplorer.core.forms.CoreForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
73      */

74     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
75         super.reset(mapping, request);
76         setActionTarget("unspecified");
77     }
78
79     /**
80      * Return if the user may move onto the next page
81      *
82      * @return next available
83      */

84     public abstract boolean getNextAvailable();
85
86     /**
87      * Return if the user may move back to the previous page
88      *
89      * @return previous available
90      */

91     public abstract boolean getPreviousAvailable();
92
93     /**
94      * Return if the user may move back to the finish page
95      *
96      * @return previous available
97      */

98     public abstract boolean getFinishAvailable();
99     
100     /**
101      * Return the path of the JSP fragment that provides the
102      * body of the page. This should be a fully qualified path starting at
103      * <strong>/WEB-INF</strong>. For example
104      * <strong>/WEB-INF/jsp/content/install/selectCertificateSource.jspf</strong>
105      *
106      * @return path of JSP fragement providing wizard page body
107      */

108     public abstract String JavaDoc getPage();
109     
110     /**
111      * Return the resource prefix used for localisation of
112      * common elements of a wizard page. Currently this only includes
113      * the <i>description</i>. For example, <i>installation.selectCertificateSource</i>.
114      *
115      * @return resource prefix
116      */

117     public abstract String JavaDoc getResourcePrefix();
118
119     /**
120      * Return the name of the resource bundle used for localisation of
121      * common elements of a wizard page. Currently this only includes
122      * the <i>description</i>. For example, <i>install</i>.
123      *
124      * @return resource bundle
125      */

126     public abstract String JavaDoc getResourceBundle();
127
128     /**
129      * Get the step index for this action.
130      *
131      * @return resource bundle
132      */

133     public abstract int getStepIndex();
134     
135     /**
136      * Return the page name of this wizard page. This is used for building
137      * the struts action page amongst other things. For example, <i>selectCertificateSource</i>
138      *
139      * @return page name.
140      */

141     public abstract String JavaDoc getPageName();
142     
143     /**
144      * Return the initially focused field name
145      *
146      * @return initially focused field name
147      */

148     public abstract String JavaDoc getFocussedField();
149     
150     /**
151      * Get if this form should support autocomplete
152      *
153      * @return autocomplete
154      */

155     public abstract boolean getAutocomplete();
156     
157     /**
158      * Return the value the should be placed in the onclick attribute
159      * of the <b>Next</b> button. Subclasses should overide this
160      * method if they wish to target a different action.
161      *
162      * @return javascript
163      */

164     public String JavaDoc getNextOnClick() {
165         return "setActionTarget('next'); document.forms[0].submit(); return false";
166     }
167     
168     /**
169      * Return the value the should be placed in the onclick attribute
170      * of the <b>Previous</b> button. Subclasses should overide this
171      * method if they wish to target a different action.
172      *
173      * @return javascript
174      */

175     public String JavaDoc getPreviousOnClick() {
176         return "setActionTarget('previous'); document.forms[0].submit(); return false";
177     }
178     
179     /**
180      * Return the value the should be placed in the onclick attribute
181      * of the <b>Finish</b> button. Subclasses should overide this
182      * method if they wish to target a different action.
183      *
184      * @return javascript
185      */

186     public String JavaDoc getFinishOnClick() {
187         return "setActionTarget('finish'); document.forms[0].submit()";
188     }
189     
190     /**
191      * Return the encoding to use for the &lt;form/&gt; tag for this
192      * form.
193      *
194      * @return encoding
195      */

196     public String JavaDoc getFormEncoding() {
197         return "application/x-www-form-urlencoded";
198     }
199     
200     /**
201      * Return the action to use for the &lt;form/&gt; tag for this
202      * form.
203      *
204      * @return action
205      */

206     public String JavaDoc getFormAction() {
207         return "/" + getPageName() + ".do";
208     }
209     
210     /**
211      * Convenience method to get the current {@link com.sslexplorer.wizard.AbstractWizardSequence}
212      * for the session
213      *
214      * @param request request from which to get session
215      * @return current wizard sequence object or null if none
216      */

217     public AbstractWizardSequence getWizardSequence(HttpServletRequest JavaDoc request) {
218         return (AbstractWizardSequence)request.getSession().getAttribute(Constants.WIZARD_SEQUENCE);
219     }
220
221     public int getGotoStep() {
222         return gotoStep;
223     }
224
225     public void setGotoStep(int gotoStep) {
226         this.gotoStep = gotoStep;
227     }
228 }
229
Popular Tags