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 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 33 public Hashtable getHeaderParams(HttpServletRequest httpServletRequest) { 34 Hashtable headerParamHash = new Hashtable(); 35 Enumeration headerParamName = httpServletRequest.getHeaderNames(); 36 while (headerParamName.hasMoreElements()) { 37 String name = (String ) headerParamName.nextElement(); 38 String value = httpServletRequest.getHeader(name); 39 } 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 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 65 public abstract int getFormId(); 66 67 68 74 public DefaultConfigurationManager getDefaultConfigurationManager() { 75 ApplicationContext cxt = org.jahia.clipbuilder.util.JahiaUtils.getSpringApplicationContext(); 76 if (cxt == null) { 77 cxt = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); 79 } 80 return (DefaultConfigurationManager) cxt.getBean("htmlClipperDefaultConfigurationManager"); 81 } 82 83 84 89 public ClipperManager getClipperManager() { 90 ApplicationContext cxt = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); 91 return (ClipperManager) cxt.getBean("clipperManager"); 92 } 93 94 95 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 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 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 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 } 159 case Constants.EDITPARAM: 160 { 161 } 163 case Constants.PREVIEW: 164 { 165 } 167 } 168 169 } 170 171 172 178 public void removeBeanForm(HttpServletRequest request, int formId) { 179 HttpSession session = request.getSession(); 180 String formName = getFormName(formId); 181 session.removeAttribute(formName); 183 logger.debug("[ Form ( id = " + formId + " ) " + formName +" removed ]"); 184 } 185 186 187 193 public void removeAllBeanForm(HttpServletRequest request, int formId) { 194 196 for (int i = formId; i <= Constants.PREVIEW; i++) { 198 removeBeanForm(request, i); 200 } 201 } 202 203 204 213 public ActionForward init(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) { 214 logger.debug("[ Init Action ]"); 215 AbstractWizardForm form = (AbstractWizardForm) actionForm; 216 removeAllBeanForm(httpServletRequest, form.getNextFormId()); 218 219 return actionMapping.getInputForward(); 220 } 221 222 223 232 public ActionForward quitWizard(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) { 233 return actionMapping.findForward("manage"); 234 } 235 236 237 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 261 public static Map getParam(HttpServletRequest request) { 262 return org.jahia.clipbuilder.html.struts.webBrowser.WebBrowserAction.getParam(request); 263 } 264 265 266 272 public static String 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 |