1 package org.jahia.clipbuilder.html.struts; 2 3 import java.util.*; 4 5 import javax.servlet.http.*; 6 7 import org.apache.struts.action.*; 8 import org.jahia.clipbuilder.html.*; 9 import org.jahia.clipbuilder.html.bean.*; 10 import org.jahia.clipbuilder.html.struts.Util.*; 11 import org.jahia.clipbuilder.html.struts.Util.Constants; 12 import org.jahia.clipbuilder.html.struts.webBrowser.WebBrowserForm; 13 import org.jahia.clipbuilder.html.util.*; 14 import org.jahia.clipbuilder.html.web.Constant.*; 15 import org.jahia.clipbuilder.html.web.Url.*; 16 import org.jahia.clipbuilder.html.web.http.*; 17 18 19 24 public class BrowseAction extends AbstractWizardAction { 25 private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(BrowseAction.class); 26 27 28 33 public Map getKeyMethodMap() { 34 Map map = super.getKeyMethodMap(); 35 map.put("wizard.browse", "view"); 36 map.put("browse.browse", "browse"); 37 map.put("button.next", "goToNextStep"); 38 map.put("browse.startRecord", "startRecord"); 39 map.put("browse.resetRecord", "init"); 40 map.put("browse.stopRecord", "stopRecord"); 41 map.put("browse.removeLast", "removeLastRecordedUrl"); 42 map.put("browse.button.addUrl", "addManuallyUrl"); 44 45 return map; 47 } 48 49 50 51 56 public int getFormId() { 57 return Constants.BROWSE; 58 } 59 60 61 70 public ActionForward view(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { 71 logger.debug("[ View ]"); 72 AbstractWizardForm form = (AbstractWizardForm) actionForm; 73 SessionManager.getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT); 74 75 return actionMapping.getInputForward(); 76 } 77 78 79 88 public ActionForward addManuallyUrl(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { 89 logger.debug("[ Add Manually Url ]"); 90 BrowseForm form = (BrowseForm) actionForm; 91 String newUrl = form.getSourceUrl(); 92 WebBrowserForm webForm = SessionManager.getWebBrowserForm(request); 93 94 String hash = HashUtilities.buildManulUrlHash(newUrl); 96 String from = WebConstants.FROM_MANUAL; 97 URLWrapper wrapper = new URLWrapper(newUrl, from, "GET", null, hash); 98 URLMap map = SessionManager.getHTMLDocumentBuilder(request).getUrlMap(); 99 map.addSourceUrl(wrapper, hash); 100 101 webForm.setFrom(from); 103 webForm.setLinkHash(hash); 104 webForm.setShow(Constants.WEB_BROWSER_SHOW_BROWSE); 105 106 return actionMapping.getInputForward(); 107 } 108 109 110 111 121 public ActionForward goToNextStep(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { 122 BrowseForm browseForm = (BrowseForm) actionForm; 123 124 updateSessionAttributes(request, Constants.BROWSE); 126 HttpSession session = request.getSession(); 128 129 RecordingBean rb = SessionManager.getRecorderBean(request); 130 rb.setStatut(RecordingBean.STOP); 131 SessionManager.setRecorderBean(request, rb); 132 133 session.setAttribute(Constants.SELECTPART_FORM, new SelectPartForm()); 135 136 ClipperBean bean = SessionManager.getClipperBean(request); 138 if (bean.isEmpty()) { 139 logger.warn("[ No url has been recorded]"); 140 return browse(actionMapping, actionForm, request, response); 141 } 142 logger.debug("[go to select part]"); 143 144 return actionMapping.findForward("selectPart"); 145 } 146 147 148 157 public ActionForward startRecord(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { 158 BrowseForm browseForm = (BrowseForm) actionForm; 159 logger.debug("[Start record]"); 160 161 HttpSession session = httpServletRequest.getSession(); 163 RecordingBean rb = (RecordingBean) session.getAttribute(WebConstants.RECORDING); 164 165 SessionManager.getClipperBean(httpServletRequest).addUrlBean(rb.getCurrentUrlBean()); 167 rb.setStatut(RecordingBean.START); 168 session.setAttribute(WebConstants.RECORDING, rb); 169 170 SessionManager.getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT); 172 173 return actionMapping.getInputForward(); 174 } 175 176 177 186 public ActionForward stopRecord(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { 187 BrowseForm browseForm = (BrowseForm) actionForm; 188 logger.debug("[Start record]"); 189 190 HttpSession session = httpServletRequest.getSession(); 192 RecordingBean rb = (RecordingBean) session.getAttribute(WebConstants.RECORDING); 193 rb.setStatut(RecordingBean.STOP); 194 195 SessionManager.getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT); 197 session.setAttribute(WebConstants.RECORDING, rb); 198 199 return actionMapping.getInputForward(); 200 } 201 202 203 204 214 public ActionForward resetRecord(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { 215 logger.debug("[Reset record]"); 216 BrowseForm browseForm = (BrowseForm) actionForm; 217 218 init(actionMapping, actionForm, httpServletRequest, httpServletResponse, browseForm); 220 221 updateSessionAttributes(httpServletRequest, Constants.DESCRIPTION); 223 224 return actionMapping.getInputForward(); 225 } 226 227 228 238 public ActionForward browse(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { 239 BrowseForm browseForm = (BrowseForm) actionForm; 240 241 Object o = httpServletRequest.getSession().getAttribute(Constants.SELECTPART_FORM); 243 if (o != null) { 244 return actionMapping.findForward("selectPart"); 245 } 246 WebBrowserForm wForm = SessionManager.getWebBrowserForm(httpServletRequest); 248 wForm.setShow(Constants.WEB_BROWSER_SHOW_BROWSE); 249 250 logger.debug("[ Browse ]"); 252 253 ClipperBean bean = SessionManager.getClipperBean(httpServletRequest); 255 256 if (bean == null) { 258 return actionMapping.findForward("description"); 259 } 260 return actionMapping.getInputForward(); 261 } 262 263 264 267 288 297 public ActionForward init(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { 298 BrowseForm browseForm = (BrowseForm) actionForm; 299 ActionErrors errors = new ActionErrors(); 300 try { 301 302 browseForm.setAllPropertiesToNull(); 304 init(actionMapping, actionForm, httpServletRequest, httpServletResponse, browseForm); 306 307 super.updateSessionAttributes(httpServletRequest, Constants.BROWSE); 308 309 logger.debug("[ Browse ]"); 311 312 ClipperBean bean = SessionManager.getClipperBean(httpServletRequest); 314 bean.clearRecordedUrl(); 315 316 if (bean == null) { 318 return actionMapping.findForward("description"); 319 } 320 321 } 322 323 catch (Exception ex) { 324 ActionError e = new ActionError("errors.exception", ex.getStackTrace()[0].toString()); 325 e = new ActionError("errors.exception", ex.toString()); 326 errors.add("errors.exception", e); 327 ex.printStackTrace(); 328 } 329 330 finally { 331 saveMessages(httpServletRequest, errors); 332 return actionMapping.getInputForward(); 333 } 334 335 } 336 337 338 347 public ActionForward removeLastRecordedUrl(ActionMapping actionMapping, 348 ActionForm actionForm, 349 HttpServletRequest 350 httpServletRequest, 351 HttpServletResponse 352 httpServletResponse) { 353 BrowseForm browseForm = (BrowseForm) actionForm; 354 355 logger.debug("[ Remove last recorded url ]"); 357 358 ClipperBean bean = SessionManager.getClipperBean(httpServletRequest); 360 361 if (bean == null) { 363 return actionMapping.findForward("description"); 364 } 365 366 369 removeLastUrlandSetHTMLContent(httpServletRequest, httpServletResponse, browseForm); 371 372 SessionManager.getWebBrowserForm(httpServletRequest).setShow(Constants.WEB_BROWSER_SHOW_LAST_DOCUMENT); 373 return actionMapping.getInputForward(); 375 } 376 377 378 381 411 413 424 426 428 432 488 495 private void removeLastUrlandSetHTMLContent(HttpServletRequest 496 httpServletRequest, 497 HttpServletResponse 498 httpServletResponse, 499 BrowseForm browseForm) { 500 ClipperBean cBean = SessionManager.getClipperBean(httpServletRequest); 502 cBean.removeLastRecordedUrl(); 503 504 logger.debug("[Last url removed]"); 506 507 if (cBean.isEmpty()) { 509 RecordingBean rBean = SessionManager.getRecorderBean(httpServletRequest); 510 rBean.setStatut(RecordingBean.STOP); 511 } 512 513 HttpSession session = httpServletRequest.getSession(); 515 HTMLClient client = (HTMLClient) session.getAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.ADVANCED_WEBCLIENT); 516 if (client != null) { 517 client.removeLastUrl(); 518 } 519 520 } 521 522 523 532 private void init(ActionMapping actionMapping, ActionForm actionForm, 533 HttpServletRequest httpServletRequest, 534 HttpServletResponse httpServletResponse, 535 BrowseForm browseForm) { 536 super.init(actionMapping, actionForm, httpServletRequest, httpServletResponse); 537 String sourceUrl = SessionManager.getClipperBean(httpServletRequest).getTargetUrl(); 538 logger.debug("[Init sourceUrl property " + sourceUrl + " ]"); 539 browseForm.setSourceUrl(sourceUrl); 541 browseForm.setLinkHash(Constants.FIRST_URL_HASH); 542 browseForm.setFrom(Constants.FIRST_URL_FROM); 543 } 544 545 } 546 | Popular Tags |