KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > struts > Util > AbstractWizardAction


1 package org.jahia.clipbuilder.html.struts.Util;
2
3 import java.util.*;
4
5 import javax.servlet.http.*;
6
7 import org.jahia.clipbuilder.html.*;
8 import org.jahia.clipbuilder.html.bean.*;
9 import org.jahia.clipbuilder.html.struts.*;
10 import org.jahia.clipbuilder.html.struts.webBrowser.*;
11 import org.apache.struts.action.*;
12 import org.apache.struts.actions.*;
13 import org.jahia.clipbuilder.html.database.hibernate.service.*;
14 import org.springframework.web.context.support.*;
15 import org.springframework.context.ApplicationContext;
16
17 /**
18  * Description of the Class
19  *
20  *@author Tlili Khaled
21  */

22 public abstract class AbstractWizardAction extends LookupDispatchAction {
23     private static org.apache.log4j.Logger logger =
24             org.apache.log4j.Logger.getLogger(AbstractWizardAction.class);
25
26
27     /**
28      * Gets the HeaderParams attribute of the BrowseAction object
29      *
30      *@param httpServletRequest Description of Parameter
31      *@return The HeaderParams value
32      */

33     public Hashtable getHeaderParams(HttpServletRequest httpServletRequest) {
34         Hashtable headerParamHash = new Hashtable();
35         Enumeration headerParamName = httpServletRequest.getHeaderNames();
36         while (headerParamName.hasMoreElements()) {
37             String JavaDoc name = (String JavaDoc) headerParamName.nextElement();
38             String JavaDoc value = httpServletRequest.getHeader(name);
39             // headerParamHash.put(name, value);
40
//logger.debug(name + "=" + value);
41
}
42         headerParamHash.put("User-Agent",httpServletRequest.getHeader("User-Agent"));
43         logger.debug("User-Agent=" + headerParamHash.get("User-Agent"));
44         return headerParamHash;
45     }
46
47
48     /**
49      * Gets the KeyMethodMap attribute of the AbstractWizardAction object
50      *
51      *@return The KeyMethodMap value
52      */

53     public Map getKeyMethodMap() {
54         Map map = new HashMap();
55         map.put("init", "init");
56         map.put("button.cancel", "quitWizard");
57         return map;
58     }
59
60     /**
61      * Gets the FormId attribute of the AbstractWizardAction object
62      *
63      *@return The FormId value
64      */

65     public abstract int getFormId();
66
67
68     /**
69      * Gets the DefaultConfigurationManager attribute of the
70      * AbstractWizardAction object
71      *
72      *@return The DefaultConfigurationManager value
73      */

74     public DefaultConfigurationManager getDefaultConfigurationManager() {
75         ApplicationContext cxt = org.jahia.clipbuilder.util.JahiaUtils.getSpringApplicationContext();
76         if (cxt == null) {
77             // clip builder is not part of jahia
78
cxt = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
79         }
80         return (DefaultConfigurationManager) cxt.getBean("htmlClipperDefaultConfigurationManager");
81     }
82
83
84     /**
85      * Gets the ClipperManager attribute of the AbstractWizardAction object
86      *
87      *@return The ClipperManager value
88      */

89     public ClipperManager getClipperManager() {
90         ApplicationContext cxt = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
91         return (ClipperManager) cxt.getBean("clipperManager");
92     }
93
94
95     /**
96      * Description of the Method
97      *
98      *@param request Description of Parameter
99      *@param formId Description of Parameter
100      */

101     public void updateSessionAttributes(HttpServletRequest request, int formId) {
102         ClipperBean cBean = SessionManager.getClipperBean(request);
103
104         HttpSession session = request.getSession();
105         switch (formId) {
106
107             case Constants.MANAGE:
108             {
109                 session.removeAttribute(Constants.TEST_FORM);
110                 session.removeAttribute(Constants.WEB_BROWSER_SIMULATOR);
111                 SessionManager.removeHTMLDocumentBuilder(request);
112
113             }
114             case Constants.DESCRIPTION:
115             {
116                 // init all session bean
117
logger.debug("[Init Session-Wizard]");
118
119                 logger.debug("[Init ClipperBean]");
120                 DescriptionClipperForm form = (DescriptionClipperForm)session.getAttribute(Constants.DESCRIPTION_FORM);
121                 cBean.buildFromDescriptionForm(form);
122                 SessionManager.setClipperBean(request, cBean);
123
124                 /*
125                  * logger.debug("[Init URLMap]");
126                  * URLMap map = new URLMap();
127                  * SessionManager.setURLMap(request, map);
128                  */

129                 logger.debug("[Init RecordingBean]");
130                 RecordingBean rc = new RecordingBean(RecordingBean.STOP);
131
132                 logger.debug("[Set Session Attributes]");
133                                 SessionManager.setRecorderBean(request,rc);
134                 session.removeAttribute(Constants.WEB_BROWSER_FORM);
135
136                 logger.debug("[ Finish init session attributes... ]");
137
138             }
139             case Constants.BROWSE:
140             {
141
142                 // Clean the url parameters config
143
logger.debug("[ clear url param config ]");
144                 cBean = SessionManager.getClipperBean(request);
145
146                 logger.debug("[ init webBrowserForm]");
147                 WebBrowserForm w = new WebBrowserForm();
148                 w.setShow(Constants.WEB_BROWSER_SHOW_BROWSE);
149                 SessionManager.setWebBrowserForm(request, w);
150
151                 logger.debug("[ HTMLDocuementBuilder Web Client ]");
152                 SessionManager.removeHTMLDocumentBuilder(request);
153
154             }
155             case Constants.SELECTPART:
156             {
157                 // do nothink...
158
}
159             case Constants.EDITPARAM:
160             {
161                 // do nothink...
162
}
163             case Constants.PREVIEW:
164             {
165                 // do nothink...
166
}
167         }
168
169     }
170
171
172     /**
173      * Description of the Method
174      *
175      *@param request Description of Parameter
176      *@param formId Description of Parameter
177      */

178     public void removeBeanForm(HttpServletRequest request, int formId) {
179         HttpSession session = request.getSession();
180         String JavaDoc formName = getFormName(formId);
181         //Remove the form bean from session
182
session.removeAttribute(formName);
183         logger.debug("[ Form ( id = " + formId + " ) " + formName +" removed ]");
184     }
185
186
187     /**
188      * Remove all form bean from session comming the current Action
189      *
190      *@param request HttpServletRequest attribute
191      *@param formId Description of Parameter
192      */

193     public void removeAllBeanForm(HttpServletRequest request, int formId) {
194         // remove test
195

196         //init the formId
197
for (int i = formId; i <= Constants.PREVIEW; i++) {
198             // Remove the form bean
199
removeBeanForm(request, i);
200         }
201     }
202
203
204     /**
205      * Remove all the strust form-bean comming after the current form
206      *
207      *@param actionMapping Description of Parameter
208      *@param actionForm Description of Parameter
209      *@param httpServletRequest Description of Parameter
210      *@param httpServletResponse Description of Parameter
211      *@return Description of the Returned Value
212      */

213     public ActionForward init(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) {
214         logger.debug("[ Init Action ]");
215         AbstractWizardForm form = (AbstractWizardForm) actionForm;
216         // update the wizard
217
removeAllBeanForm(httpServletRequest, form.getNextFormId());
218
219         return actionMapping.getInputForward();
220     }
221
222
223     /**
224      * Description of the Method
225      *
226      *@param actionMapping Description of Parameter
227      *@param actionForm Description of Parameter
228      *@param httpServletRequest Description of Parameter
229      *@param httpServletResponse Description of Parameter
230      *@return Description of the Returned Value
231      */

232     public ActionForward quitWizard(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) {
233         return actionMapping.findForward("manage");
234     }
235
236
237     /**
238      * Description of the Method
239      *
240      *@param actionMapping Description of Parameter
241      *@param actionForm Description of Parameter
242      *@param httpServletRequest Description of Parameter
243      *@param httpServletResponse Description of Parameter
244      *@return Description of the Returned Value
245      */

246     public ActionForward view(ActionMapping actionMapping,
247             ActionForm actionForm,
248             HttpServletRequest httpServletRequest,
249             HttpServletResponse httpServletResponse) {
250         logger.debug("[ View ]");
251         return actionMapping.getInputForward();
252     }
253
254
255     /**
256      * Gets the Param attribute of the AbstractWizardAction class
257      *
258      *@param request Description of Parameter
259      *@return The Param value
260      */

261     public static Map getParam(HttpServletRequest request) {
262         return org.jahia.clipbuilder.html.struts.webBrowser.WebBrowserAction.getParam(request);
263     }
264
265
266     /**
267      * Gets the FormName attribute of the ClipperAction object
268      *
269      *@param formId Description of Parameter
270      *@return The FormName value
271      */

272     public static String JavaDoc getFormName(int formId) {
273         switch (formId) {
274
275             case Constants.TEST:
276             {
277                 return Constants.TEST_FORM;
278             }
279             case Constants.MANAGE:
280             {
281                 return Constants.MANAGE_FORM;
282             }
283
284             case Constants.BROWSE:
285             {
286                 return Constants.BROWSE_FORM;
287             }
288             case Constants.EDITPARAM:
289             {
290                 return Constants.EDITPARAM_FORM;
291             }
292
293             case Constants.DESCRIPTION:
294             {
295                 return Constants.DESCRIPTION_FORM;
296             }
297
298             case Constants.PREVIEW:
299             {
300                 return Constants.PREVIEW_FORM;
301             }
302
303             case Constants.SELECTPART:
304             {
305                 return Constants.SELECTPART_FORM;
306             }
307
308         }
309         return null;
310     }
311 }
312
Popular Tags