1 package org.jahia.views.engines.versioning.pages.actions; 2 3 import java.io.*; 4 import java.text.*; 5 import java.util.*; 6 import javax.servlet.*; 7 import javax.servlet.http.*; 8 9 import javax.swing.*; 10 11 import org.apache.log4j.Logger; 12 import org.apache.struts.action.*; 13 import org.jahia.bin.*; 14 import org.jahia.content.*; 15 import org.jahia.exceptions.*; 16 import org.jahia.params.*; 17 import org.jahia.registries.*; 18 import org.jahia.services.pages.*; 19 import org.jahia.services.usermanager.*; 20 import org.jahia.services.version.*; 21 import org.jahia.views.engines.*; 22 import org.jahia.views.engines.datepicker.*; 23 import org.jahia.views.engines.datepicker.actions.*; 24 import org.jahia.views.engines.versioning.pages.*; 25 import org.jahia.views.engines.versioning.revisionsdetail.actions.*; 26 import org.jahia.services.cache.HtmlCache; 27 import org.jahia.services.cache.CacheFactory; 28 import org.jahia.services.sitemap.JahiaSiteMapService; 29 import org.jahia.data.viewhelper.sitemap.SiteMapViewHelper; 30 import org.jahia.services.lock.LockService; 31 import org.jahia.services.lock.LockKey; 32 33 34 43 public class PagesVersioningAction extends org.apache.struts.actions.DispatchAction { 44 45 private static Logger logger = Logger.getLogger(PagesVersioningAction.class); 46 47 private static final String ENGINE_TITLE = "Pages Versioning"; 48 49 public static final String SESSION_VERSIONING_LOCK_LIST = "org.jahia.views.engines.versioning.pages.Locks"; 50 51 57 private void init(ActionMapping mapping, HttpServletRequest request) 58 throws JahiaException { 59 60 try { 61 62 String engineView = request.getParameter ("engineview"); 64 String reloaded = request.getParameter("reloaded"); 65 66 PagesVersioningViewHelper engineViewHelper = null; 68 if ( engineView != null && !"yes".equals(reloaded) ){ 69 engineViewHelper = 71 (PagesVersioningViewHelper)request.getSession() 72 .getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 73 } 74 JahiaEngineCommonData engineCommonData = 76 new JahiaEngineCommonData(request); 77 engineCommonData.setEngineTitle(PagesVersioningAction.ENGINE_TITLE); 78 79 JahiaEngineButtonsHelper jahiaEngineButtonsHelper = 81 new JahiaEngineButtonsHelper(); 82 jahiaEngineButtonsHelper.addCloseButton(); 83 84 jahiaEngineButtonsHelper.addAuthoringButton(); 85 if ( engineCommonData.getParamBean().getPage() 86 .checkAdminAccess(engineCommonData.getParamBean().getUser()) ){ 87 jahiaEngineButtonsHelper.addRightsButton(); 88 } 89 if ( engineCommonData.getParamBean().getPage() 90 .checkAdminAccess(engineCommonData.getParamBean().getUser()) || 91 engineCommonData.getParamBean().getPage() 92 .checkWriteAccess(engineCommonData.getParamBean().getUser()) ){ 93 jahiaEngineButtonsHelper.addVersioningButton(); 94 } 95 if ( engineCommonData.getParamBean().getPage() 96 .checkAdminAccess(engineCommonData.getParamBean().getUser()) ){ 97 jahiaEngineButtonsHelper.addLogsButton(); 98 } 99 if ( engineCommonData.getParamBean().getPage() 100 .checkAdminAccess(engineCommonData.getParamBean().getUser()) || 101 engineCommonData.getParamBean().getPage() 102 .checkWriteAccess(engineCommonData.getParamBean().getUser()) ){ 103 jahiaEngineButtonsHelper.addCategoriesButton(); 104 } 105 106 request.setAttribute(JahiaEngineButtonsHelper.JAHIA_ENGINE_BUTTONS_HELPER, 107 jahiaEngineButtonsHelper); 108 109 if ( engineViewHelper == null ){ 110 String pid = null; 112 EntryLoadRequest loadRequest = EntryLoadRequest.VERSIONED; 113 pid = request.getParameter("pageid"); 114 ContentPage page = ServicesRegistry.getInstance() 115 .getJahiaPageService() 116 .lookupContentPage(Integer.parseInt(pid),loadRequest,false); 117 engineViewHelper = 118 new PagesVersioningViewHelper(page); 119 120 request.getSession().setAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER, 122 engineViewHelper); 123 } 124 125 ContentPage page = engineViewHelper.getPage(); 127 if ( !page.checkWriteAccess(engineCommonData.getParamBean().getUser()) 128 && !page.checkAdminAccess(engineCommonData.getParamBean().getUser()) ){ 129 throw new JahiaForbiddenAccessException(); 130 } 131 132 request.setAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA, 133 engineCommonData); 134 135 request.setAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER, 136 engineViewHelper); 137 138 String pageTitle = engineViewHelper.getPage() 140 .getTitle(engineCommonData.getParamBean() 141 .getEntryLoadRequest()); 142 if ( pageTitle == null ){ 143 pageTitle = "No title for page [" + engineViewHelper.getPage().getID() + "] in lang : " + engineCommonData.getParamBean() 144 .getEntryLoadRequest().getFirstLocale(true).getDisplayName(); 145 } 146 request.setAttribute("pageproperties.pagetitle", 147 pageTitle); 148 request.setAttribute("pageproperties.pageid", 149 String.valueOf(engineViewHelper.getPage().getID())); 150 151 String actionURL = composeActionURL(engineViewHelper.getPage(), 153 engineCommonData.getParamBean(),mapping.getPath(),null,null); 154 request.setAttribute("PagesVersioning.ActionURL",actionURL); 155 156 HashMap engineMap = (HashMap)request 159 .getSession().getAttribute("jahia_session_engineMap"); 160 if ( engineMap != null ){ 161 engineMap.put("screen","versioning"); 162 request.setAttribute("jahia_session_engineMap", engineMap); 163 engineCommonData.setEngineURL((String )engineMap.get("engineUrl")); 165 } 166 167 } catch ( Throwable t ){ 168 logger.debug("Error occurred",t); 169 throw new JahiaException("Exception occured initializing engine's objects", 170 "Exception occured initializing engine's objects", 171 JahiaException.ENGINE_ERROR, 172 JahiaException.ENGINE_ERROR, t); 173 } 174 } 175 176 187 public ActionForward showOperationChoices(ActionMapping mapping, 188 ActionForm form, 189 HttpServletRequest request, 190 HttpServletResponse response) 191 throws IOException, ServletException { 192 193 ActionForward forward = mapping.findForward("operationChoices"); 194 ActionMessages errors = new ActionMessages(); 195 JahiaEngineCommonData engineCommonData = null; 196 try { 197 init(mapping,request); 198 getRevisionsListFormData(mapping,form,request,response); 199 getSiteMapFormData(mapping,form,request,response); 200 engineCommonData = (JahiaEngineCommonData) 201 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 202 203 ActionMessages localMessages = new ActionMessages(); 206 boolean lockingSuccessful = acquireTreeLocks(engineCommonData.getParamBean(), localMessages); 207 if (!lockingSuccessful) { 208 forward = mapping.findForward("pageTreeLocked"); 209 saveMessages(request, localMessages); 210 } 211 212 } catch ( Throwable t ){ 213 JahiaErrorDisplay.DisplayException(request, response, 214 super.getServlet().getServletContext(), t); 215 errors.add(ActionMessages.GLOBAL_MESSAGE, 216 new ActionMessage("Error preparing Operation Choices view")); 217 } 218 request.setAttribute("engineView","operationChoices"); 220 return continueForward(mapping,request,errors,forward); 221 } 222 223 234 public ActionForward showRevisionsList(ActionMapping mapping, 235 ActionForm form, 236 HttpServletRequest request, 237 HttpServletResponse response) 238 throws IOException, ServletException { 239 240 ActionForward forward = mapping.getInputForward(); 241 ActionMessages errors = new ActionMessages(); 242 PagesVersioningViewHelper pagesVersViewHelper = null; 243 JahiaEngineCommonData engineCommonData = null; 244 try { 245 init(mapping,request); 246 getRevisionsListFormData(mapping,form,request,response); 247 pagesVersViewHelper = (PagesVersioningViewHelper) 248 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 249 engineCommonData = (JahiaEngineCommonData) 250 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 251 252 initRevisionsDateListener(pagesVersViewHelper,request); 253 254 Calendar calendar = Calendar.getInstance(); 256 calendar.setTime(new Date(pagesVersViewHelper.getToRevisionDate().longValue())); 257 calendar.set(Calendar.HOUR,23); 258 calendar.set(Calendar.MINUTE,59); 259 calendar.set(Calendar.SECOND,0); 260 long toDate = calendar.getTime().getTime(); 261 EntryLoadRequest loadRequest = 262 new EntryLoadRequest(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 263 (int)(toDate/1000), 264 engineCommonData.getParamBean().getEntryLoadRequest().getLocales()); 265 266 int pageLevel = pagesVersViewHelper.getPageLevel().intValue(); 268 if ( pageLevel>0 ){ 269 pageLevel -=1; 270 } 271 ContentTreeRevisionsVisitor revisionsVisitor = 272 pagesVersViewHelper.getContentTreeRevisionsVisitor( 273 engineCommonData.getParamBean().getUser(), 274 loadRequest,ParamBean.EDIT); 275 276 revisionsVisitor.setWithDeletedContent(true); 277 revisionsVisitor.setDescendingPageLevel(pageLevel); 278 279 long fromDate = pagesVersViewHelper.getFromRevisionDate().longValue(); 280 calendar.setTime(new Date(fromDate)); 281 calendar.set(Calendar.HOUR,0); 282 calendar.set(Calendar.MINUTE,0); 283 calendar.set(Calendar.SECOND,1); 284 revisionsVisitor.setFromRevisionDate(calendar.getTime().getTime()); 285 revisionsVisitor.setToRevisionDate( 286 toDate); 287 288 revisionsVisitor.loadRevisions(false); 289 revisionsVisitor.sortRevisions( 290 engineCommonData.getParamBean().getLocale().toString(), 291 pagesVersViewHelper.getSortAttribute(), 292 pagesVersViewHelper.getSortOrder(),false); 293 294 ArrayList revisions = revisionsVisitor.getRevisions(); 295 ArrayList filteredRevisions = new ArrayList(); 296 int size = revisions.size(); 297 RevisionEntrySet revEntrySet = null; 299 for ( int i=0; i<size; i++ ){ 300 revEntrySet = (RevisionEntrySet)revisions.get(i); 301 if ( (revEntrySet.getWorkflowState() != 302 EntryLoadRequest.DELETED_WORKFLOW_STATE) ){ 303 filteredRevisions.add(revEntrySet); 304 } 305 } 306 request.setAttribute("revisions",filteredRevisions); 307 308 } catch ( Throwable t ){ 309 JahiaErrorDisplay.DisplayException(request, response, 310 super.getServlet().getServletContext(), t); 311 errors.add(ActionMessages.GLOBAL_MESSAGE, 312 new ActionMessage("Exception occured when processing page pid[" 313 + pagesVersViewHelper.getPage().getID() + "]")); 314 } 315 request.setAttribute("engineView","revisionsList"); 317 return continueForward(mapping,request,errors,forward); 318 } 319 320 331 public ActionForward showSiteMap(ActionMapping mapping, 332 ActionForm form, 333 HttpServletRequest request, 334 HttpServletResponse response) 335 throws IOException, ServletException { 336 337 ActionForward forward = mapping.findForward("sitemap"); 338 ActionMessages errors = new ActionMessages(); 339 PagesVersioningViewHelper pagesVersViewHelper = null; 340 JahiaEngineCommonData engineCommonData = null; 341 try { 342 init(mapping,request); 343 getRevisionsListFormData(mapping,form,request,response); 344 getSiteMapFormData(mapping,form,request,response); 345 pagesVersViewHelper = (PagesVersioningViewHelper) 346 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 347 engineCommonData = (JahiaEngineCommonData) 348 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 349 initRestoreDateListener(pagesVersViewHelper,request); 350 pagesVersViewHelper.loadSiteMapViewHelper( 351 engineCommonData.getParamBean().getUser(),request); 352 353 String paramVal = request.getParameter("operationType"); 355 if ( paramVal != null ){ 356 try { 357 pagesVersViewHelper.setOperationType(Integer.parseInt(paramVal)); 358 }catch(Throwable t){ 359 } 360 } 361 362 if ( pagesVersViewHelper.getSelectedPages().size()==0 364 && pagesVersViewHelper.getOperationType() == PagesVersioningViewHelper.RESTORE_ARCHIVE_CONTENT_OPERATION ){ 365 pagesVersViewHelper.getSelectedPages().add(pagesVersViewHelper.getPage().getObjectKey()); 366 } 367 368 String siteMapParam = request.getParameter("sitemap"); 369 if (siteMapParam != null) { 370 ServicesRegistry.getInstance().getJahiaSiteMapService() 371 .invokeTreeSiteMapViewHelperMethod(engineCommonData.getParamBean().getUser(), 372 pagesVersViewHelper.getPage(), engineCommonData.getParamBean().getSessionID(), 373 ContentPage.ARCHIVED_PAGE_INFOS, 374 null, siteMapParam); 375 } 376 377 } catch ( Throwable t ){ 378 JahiaErrorDisplay.DisplayException(request, response, 379 super.getServlet().getServletContext(), t); 380 errors.add(ActionMessages.GLOBAL_MESSAGE, 381 new ActionMessage("Error preparing sitemap view")); 382 } 383 request.setAttribute("engineView","sitemap"); 385 return continueForward(mapping,request,errors,forward); 386 } 387 388 399 public ActionForward showConfirmRestore(ActionMapping mapping, 400 ActionForm form, 401 HttpServletRequest request, 402 HttpServletResponse response) 403 throws IOException, ServletException { 404 405 ActionForward forward = null; 406 ActionMessages errors = new ActionMessages(); 407 PagesVersioningViewHelper pagesVersViewHelper = null; 408 JahiaEngineCommonData engineCommonData = null; 409 try { 410 init(mapping,request); 411 getSiteMapFormData(mapping,form,request,response); 412 pagesVersViewHelper = (PagesVersioningViewHelper) 413 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 414 pagesVersViewHelper.setPagesToRestore(getPagesToRestore(request)); 416 417 engineCommonData = (JahiaEngineCommonData) 418 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 419 420 switch( pagesVersViewHelper.getOperationType() ){ 421 case PagesVersioningViewHelper.UNDO_STAGING_OPERATION : 422 { 423 forward = mapping.findForward("confirmUndoStaging"); 424 break; 425 } 426 case PagesVersioningViewHelper.RESTORE_ARCHIVE_CONTENT_OPERATION : 427 { 428 forward = mapping.findForward("confirmRestore"); 429 break; 430 } 431 case PagesVersioningViewHelper.RESTORE_DELETED_PAGES : 432 { 433 forward = mapping.findForward("confirmPageUndelete"); 434 break; 435 } 436 } 437 438 if ( pagesVersViewHelper.getPagesToRestore().size()==0 ){ 439 forward = this.showSiteMap(mapping,form,request,response); 440 request.setAttribute("engineView","sitemap"); 442 return continueForward(mapping,request,errors,forward); 443 } else { 444 445 JahiaEngineButtonsHelper jahiaEngineButtonsHelper = 447 new JahiaEngineButtonsHelper(); 448 449 jahiaEngineButtonsHelper.addOkButton(); 450 jahiaEngineButtonsHelper.addApplyButton(); 451 jahiaEngineButtonsHelper.addCloseButton(); 452 453 jahiaEngineButtonsHelper.addAuthoringButton(); 454 if ( engineCommonData.getParamBean().getPage() 455 .checkAdminAccess(engineCommonData.getParamBean().getUser()) ){ 456 jahiaEngineButtonsHelper.addRightsButton(); 457 jahiaEngineButtonsHelper.addVersioningButton(); 458 jahiaEngineButtonsHelper.addLogsButton(); 459 } 460 461 request.setAttribute(JahiaEngineButtonsHelper.JAHIA_ENGINE_BUTTONS_HELPER, 462 jahiaEngineButtonsHelper); 463 464 Date d = new java.util.Date ( 466 pagesVersViewHelper.getSiteMapDisplayDate().longValue()); 467 request.setAttribute("pagesversioning.full_restore_date", 468 DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM, 469 engineCommonData.getParamBean().getLocale()).format(d)); 470 request.setAttribute("pagesversioning.nb_pages_to_restore", 471 new Integer (pagesVersViewHelper.getPagesToRestore().size()/2)); 472 request.setAttribute("pagesversioning.restore_exact", 473 pagesVersViewHelper.exactRestore()?"yes":"no"); 474 } 475 } catch ( Throwable t ){ 476 JahiaErrorDisplay.DisplayException(request, response, 477 super.getServlet().getServletContext(), t); 478 errors.add(ActionMessages.GLOBAL_MESSAGE, 479 new ActionMessage("Error preparing confirm restore view")); 480 } 481 request.setAttribute("engineView","confirmRestore"); 483 return continueForward(mapping,request,errors,forward); 484 } 485 486 497 public ActionForward restoreSave(ActionMapping mapping, 498 ActionForm form, 499 HttpServletRequest request, 500 HttpServletResponse response) 501 throws IOException, ServletException { 502 503 ActionForward forward = mapping.findForward("sitemap"); 504 ActionMessages errors = new ActionMessages(); 505 PagesVersioningViewHelper pagesVersViewHelper = null; 506 JahiaEngineCommonData engineCommonData = null; 507 try { 508 init(mapping,request); 509 pagesVersViewHelper = (PagesVersioningViewHelper) 510 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 511 if ( pagesVersViewHelper.getPagesToRestore().size()==0 ){ 512 forward = this.showSiteMap(mapping,form,request,response); 513 } else { 514 engineCommonData = (JahiaEngineCommonData) 515 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 516 boolean activeRestoredPages = 517 "yes".equals(request.getParameter("activate_pages_after_restore")); 518 boolean applyPageMoveWhenRestore = 519 "yes".equals(request.getParameter("apply_page_move_when_restore")); 520 521 pagesVersViewHelper.setApplyPageMoveWhenRestore(applyPageMoveWhenRestore); 522 523 ArrayList pagesToRestoreArray = pagesVersViewHelper.getPagesToRestore(); 524 HashMap pagesToRestore = new HashMap(); 525 int size = pagesToRestoreArray.size(); 526 for ( int i=0 ; i<size-1 ; i+=2){ 527 String lang = (String )pagesToRestoreArray.get(i); 528 Integer pageID = (Integer )pagesToRestoreArray.get(i+1); 529 ArrayList langs = (ArrayList)pagesToRestore.get(pageID); 530 if ( langs == null ){ 531 langs = new ArrayList(); 532 } 533 langs.add(lang); 534 pagesToRestore.put(pageID,langs); 535 } 536 537 switch( pagesVersViewHelper.getOperationType() ){ 538 case PagesVersioningViewHelper.UNDO_STAGING_OPERATION : 539 { 540 this.undoStaging(engineCommonData.getParamBean(), 541 request, pagesToRestore); 542 break; 543 } 544 case PagesVersioningViewHelper.RESTORE_ARCHIVE_CONTENT_OPERATION : 545 { 546 this.restorePages(engineCommonData.getParamBean(), request, 547 pagesToRestore, 548 engineCommonData.getParamBean().getUser(), 549 pagesVersViewHelper.getSiteMapDisplayDate().longValue(), 550 pagesVersViewHelper.exactRestore(), 551 activeRestoredPages); 552 break; 553 } 554 case PagesVersioningViewHelper.RESTORE_DELETED_PAGES : 555 this.restorePages(engineCommonData.getParamBean(), request, 556 pagesToRestore, 557 engineCommonData.getParamBean().getUser(), 558 pagesVersViewHelper.getSiteMapDisplayDate().longValue(), 559 pagesVersViewHelper.exactRestore(), 560 activeRestoredPages); 561 break; 562 563 } 564 565 if ( pagesVersViewHelper.getContentTreeRevisionsVisitor() != null ){ 567 pagesVersViewHelper.getContentTreeRevisionsVisitor().loadRevisions(true); 568 } 569 570 String method = request.getParameter(mapping.getParameter()); 571 if ( method.equals("restoreSave") ){ 572 releaseTreeLocks(engineCommonData.getParamBean()); 573 request.setAttribute("engines.close.refresh-opener","yes"); 574 request.setAttribute("engines.close.opener-url-params","&reloaded=yes"); 575 forward = mapping.findForward("EnginesCloseAnyPopup"); 576 } else if ( method.equals("restoreApply") ){ 577 Properties params = new Properties(); 578 params.put("method","showOperationChoices"); 579 params.put("engineview","restore"); 580 String requestURL = PagesVersioningAction.composeActionURL(pagesVersViewHelper.getPage(), 581 engineCommonData.getParamBean(),mapping.getPath(),params,null); 582 request.setAttribute("engines.apply.new-url",requestURL); 583 request.setAttribute("engines.apply.refresh-opener","yes"); 584 request.setAttribute("engines.apply.opener-url-params","&reloaded=yes"); 585 forward = mapping.findForward("EnginesApplyAnyPopup"); 586 } else { 587 forward = this.showRevisionsList(mapping,form,request,response); 588 } 589 } 590 } catch ( Throwable t ){ 591 JahiaErrorDisplay.DisplayException(request, response, 592 super.getServlet().getServletContext(), t); 593 errors.add(ActionMessages.GLOBAL_MESSAGE, 594 new ActionMessage("Unable to retrieve pid or versionid")); 595 } 596 request.setAttribute("engineView","sitemap"); 598 return continueForward(mapping,request,errors,forward); 599 } 600 601 612 public ActionForward restoreApply(ActionMapping mapping, 613 ActionForm form, 614 HttpServletRequest request, 615 HttpServletResponse response) 616 throws IOException, ServletException { 617 return restoreSave(mapping,form,request,response); 618 } 619 620 631 public ActionForward revisionsDetail(ActionMapping mapping, 632 ActionForm form, 633 HttpServletRequest request, 634 HttpServletResponse response) 635 throws IOException, ServletException { 636 637 ActionForward forward = mapping.findForward("revisionsDetail"); 638 ActionMessages errors = new ActionMessages(); 639 PagesVersioningViewHelper pagesVersViewHelper = null; 640 try { 641 init(mapping,request); 642 pagesVersViewHelper = (PagesVersioningViewHelper) 643 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 644 String revisionEntryParam = request.getParameter("revisionEntrySet"); 645 RevisionEntrySet revisionEntrySet = getRevisionEntrySet(revisionEntryParam); 646 647 JTree tree = null; 648 ContentTreeRevisionsVisitor revisionsVisitor = 649 pagesVersViewHelper.getContentTreeRevisionsVisitor(); 650 ArrayList revisions = revisionsVisitor.getRevisions(); 651 if ( revisions.size()>0 ){ 652 int index = revisions.indexOf(revisionEntrySet); 653 if ( index != -1 ){ 654 revisionEntrySet = (RevisionEntrySet)revisions.get(index); 655 tree = RevisionsTreeTools.getTreeOfPageRevisions( 656 (PageRevisionEntrySet)revisionEntrySet, 657 revisionsVisitor.getUser(), 658 revisionsVisitor.getEntryLoadRequest(), 659 revisionsVisitor.getOperationMode()); 660 } 661 } 662 663 request.setAttribute(RevisionEntrySetDetailAction.REVISIONS_TREE, 665 tree); 666 request.setAttribute(RevisionEntrySetDetailAction.REVISIONENTRYSET, 667 revisionEntrySet); 668 669 } catch ( Throwable t ){ 670 JahiaErrorDisplay.DisplayException(request, response, 671 super.getServlet().getServletContext(), t); 672 errors.add(ActionMessages.GLOBAL_MESSAGE, 673 new ActionMessage("Exception processing show restore version test result")); 674 } 675 request.setAttribute("engineView","revisionsDetail"); 676 return continueForward(mapping,request,errors,forward); 677 } 678 679 689 public ActionForward close(ActionMapping mapping, 690 ActionForm form, 691 HttpServletRequest request, 692 HttpServletResponse response) 693 throws IOException, ServletException { 694 695 ActionForward forward = mapping.findForward("close"); 696 ActionMessages errors = new ActionMessages(); 697 JahiaEngineCommonData engineCommonData = null; 698 try { 699 init(mapping,request); 700 getRevisionsListFormData(mapping,form,request,response); 701 getSiteMapFormData(mapping,form,request,response); 702 engineCommonData = (JahiaEngineCommonData) 703 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 704 705 releaseTreeLocks(engineCommonData.getParamBean()); 706 707 releaseActionLock(engineCommonData.getParamBean()); 709 710 } catch ( Throwable t ){ 711 JahiaErrorDisplay.DisplayException(request, response, 712 super.getServlet().getServletContext(), t); 713 errors.add(ActionMessages.GLOBAL_MESSAGE, 714 new ActionMessage("Error preparing Operation Choices view")); 715 } 716 request.setAttribute("engineView","close"); 718 return continueForward(mapping,request,errors,forward); 719 } 720 721 730 private void getRevisionsListFormData(ActionMapping mapping, 731 ActionForm form, 732 HttpServletRequest request, 733 HttpServletResponse response) 734 throws IOException, ServletException, JahiaSessionExpirationException { 735 736 PagesVersioningViewHelper pagesVersViewHelper = 737 (PagesVersioningViewHelper) 738 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 739 JahiaEngineCommonData engineCommonData = (JahiaEngineCommonData) 740 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 741 742 String revisionEntryParam = request.getParameter("revisionEntrySet"); 744 String useRevisionEntryParam = request.getParameter("useRevisionEntry"); 745 RevisionEntrySet revisionEntrySet = getRevisionEntrySet(revisionEntryParam); 746 747 if ( revisionEntrySet != null ){ 748 pagesVersViewHelper.setRevisionEntrySet(revisionEntrySet); 749 if ( useRevisionEntryParam.equals("yes") ){ 750 pagesVersViewHelper.setSiteMapDisplayDate(revisionEntrySet.getVersionID()*1000L); 751 String restoreDateKey = "PagesVersioningAction_restoredate_" + 753 engineCommonData.getParamBean().getSessionID(); 754 DatePicker.getInstance().removeListener(restoreDateKey); 755 } 756 } 757 758 String paramVal = request.getParameter("rev_type"); 760 if ( paramVal != null ){ 761 try { 762 pagesVersViewHelper.setTypeOfRevisions(Integer.parseInt(paramVal)); 763 }catch(Throwable t){ 764 } 765 } 766 767 paramVal = request.getParameter("level"); 769 if ( paramVal != null ){ 770 try { 771 pagesVersViewHelper.setPageLevel(Integer.parseInt(paramVal)); 772 }catch(Throwable t){ 773 } 774 } 775 776 paramVal = request.getParameter("nbmax_rev"); 778 if ( paramVal != null ){ 779 try { 780 pagesVersViewHelper.setNbMaxOfRevisions(Integer.parseInt(paramVal)); 781 }catch(Throwable t){ 782 } 783 } 784 785 paramVal = request.getParameter("sortAttribute"); 787 if ( paramVal != null ){ 788 try { 789 pagesVersViewHelper.setSortAttribute(Integer.parseInt(paramVal)); 790 }catch(Throwable t){ 791 } 792 } 793 794 paramVal = request.getParameter("sortOrder"); 796 if ( paramVal != null ){ 797 try { 798 pagesVersViewHelper.setSortOrder(Integer.parseInt(paramVal)); 799 }catch(Throwable t){ 800 } 801 } 802 803 } 804 805 814 private void getSiteMapFormData(ActionMapping mapping, 815 ActionForm form, 816 HttpServletRequest request, 817 HttpServletResponse response) 818 throws IOException, ServletException { 819 820 try { 821 PagesVersioningViewHelper pagesVersViewHelper = 822 (PagesVersioningViewHelper) 823 request.getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 824 JahiaEngineCommonData engineCommonData = (JahiaEngineCommonData) 825 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 826 ParamBean jParams = engineCommonData.getParamBean(); 827 828 String siteMapParam = request.getParameter("sitemap"); 829 if (siteMapParam != null) { 830 ServicesRegistry.getInstance().getJahiaSiteMapService() 831 .invokeTreeSiteMapViewHelperMethod(jParams.getUser(), 832 pagesVersViewHelper.getPage(), jParams.getSessionID(), 833 ContentPage.ARCHIVED_PAGE_INFOS, 834 null, siteMapParam); 835 } 836 837 String paramVal = request.getParameter("exact_restore"); 839 if ( paramVal != null ){ 840 pagesVersViewHelper.setExactRestore("yes".equals(paramVal)); 841 } 842 } catch ( Throwable t ){ 843 logger.debug("Error occurred",t); 844 } 845 } 846 847 862 private void restorePages(ParamBean jParams, 863 HttpServletRequest request, 864 HashMap pagesToRestore, 865 JahiaUser user, 866 long restoreDate, 867 boolean removeMoreRecentActive, 868 boolean activeRestoredPages) throws JahiaException{ 869 870 PagesVersioningViewHelper pagesVersViewHelper = 871 (PagesVersioningViewHelper)request 872 .getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 873 874 ArrayList selectedPages = new ArrayList(); 876 Iterator iterator = pagesToRestore.keySet().iterator(); 877 while ( iterator.hasNext() ){ 878 Integer pageID = (Integer )iterator.next(); 879 if ( pageID != null ){ 880 selectedPages.add(pageID); 881 } 882 } 883 884 Vector sortedPages = ServicesRegistry.getInstance().getJahiaPageService() 886 .sortPages(selectedPages,jParams.getEntryLoadRequest(), 887 jParams.getUser(),jParams.getOperationMode()); 888 Enumeration enumeration = sortedPages.elements(); 889 890 899 900 ArrayList processedPages = new ArrayList(); 901 while ( enumeration.hasMoreElements() ){ 902 Integer pageID = (Integer ) enumeration.nextElement(); 903 ArrayList langsToRestore = (ArrayList)pagesToRestore.get(pageID); 904 String lang = (String )langsToRestore.get(0); 905 if ( processedPages.contains(pageID) ){ 906 continue; 907 } 908 ContentPage contentPage = ContentPage.getPage(pageID.intValue()); 909 910 Set langs = new HashSet(); 911 langs.add(lang); 912 ContentObjectEntryState entryState = 913 new ContentObjectEntryState(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 914 (int)(restoreDate/1000),lang); 915 916 boolean undeletePage = false; 917 918 if ( pagesVersViewHelper.getOperationType() == 920 PagesVersioningViewHelper.RESTORE_DELETED_PAGES ){ 921 925 if ( contentPage.isStagedEntryMarkedForDeletion(lang) ){ 927 HashMap pages = new HashMap(); 929 langs.add(lang); 930 pages.put(pageID,langs); 931 this.undoStaging(jParams,request,pages); 932 entryState = null; } else { 934 int deleteVersionID = contentPage.getDeleteVersionID(); 935 if ( deleteVersionID != -1 ){ 936 undeletePage = true; 937 entryState = 941 new ContentObjectEntryState(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 942 (deleteVersionID),lang); 943 } 946 } 947 } 948 if ( entryState != null ){ 949 RestoreVersionStateModificationContext stateModificationContext = 950 new RestoreVersionStateModificationContext(contentPage.getObjectKey(),langs,entryState); 951 stateModificationContext.setDescendingInSubPages(false); 952 953 contentPage.restoreVersion(user,ParamBean.EDIT,entryState, 955 (removeMoreRecentActive && !undeletePage), 956 selectedPages.contains(new Integer (contentPage.getID())), 957 stateModificationContext); 958 959 ArrayList langsArray = (ArrayList)pagesToRestore 961 .get(new Integer (contentPage.getID())); 962 langsArray.remove(lang); 963 Iterator it = langsArray.iterator(); 964 while ( it.hasNext() ){ 965 String lng = (String )it.next(); 966 entryState = new ContentObjectEntryState(entryState.getWorkflowState(), 967 entryState.getVersionID(),lng); 968 stateModificationContext.getLanguageCodes().clear(); 969 stateModificationContext.getLanguageCodes().add(lng); 970 971 contentPage.restoreVersion(user,ParamBean.EDIT,entryState, 972 (removeMoreRecentActive && !undeletePage), 973 selectedPages.contains(new Integer (contentPage.getID())), 974 stateModificationContext); 975 } 976 977 processedPages.add(pageID); 978 979 if ( removeMoreRecentActive ){ 981 this.removeMoreRecentActivePages(contentPage,user,ParamBean.EDIT, 982 entryState,stateModificationContext, 983 new RestoreVersionTestResults(), 984 pagesToRestore, selectedPages, processedPages, 985 jParams); 986 } 987 } 988 } 989 } 990 991 999 private void undoStaging(ParamBean jParams, 1000 HttpServletRequest request, 1001 HashMap pagesToRestore) throws JahiaException{ 1002 1003 PagesVersioningViewHelper pagesVersViewHelper = 1004 (PagesVersioningViewHelper)request 1005 .getAttribute(JahiaEngineViewHelper.ENGINE_VIEW_HELPER); 1006 1007 ArrayList processedPages = new ArrayList(); 1008 EntryLoadRequest loadRequest = 1009 (EntryLoadRequest)jParams.getEntryLoadRequest().clone(); 1010 loadRequest.setWithMarkedForDeletion(true); 1011 Iterator iterator = pagesToRestore.keySet().iterator(); 1012 1013 ArrayList pageIDs = new ArrayList(); 1015 while ( iterator.hasNext() ){ 1016 try { 1017 Integer pageID = (Integer ) iterator.next(); 1018 if ( pageID != null ){ 1019 pageIDs.add(pageID); 1020 } 1021 } catch ( Throwable t ){ 1022 logger.debug(t); 1023 } 1024 } 1025 Vector sortedPages = ServicesRegistry.getInstance().getJahiaPageService() 1026 .sortPages(pageIDs,jParams.getEntryLoadRequest(), 1027 jParams.getUser(),jParams.getOperationMode()); 1028 Enumeration enumeration = sortedPages.elements(); 1029 1030 while ( enumeration.hasMoreElements() ){ 1031 Integer pageID = (Integer )enumeration.nextElement(); 1032 if ( !processedPages.contains(pageID) ){ 1033 ContentPage contentPage = ContentPage.getPage(pageID.intValue()); 1034 UndoStagingContentTreeVisitor visitor = 1035 new UndoStagingContentTreeVisitor(contentPage,jParams.getUser(), 1036 loadRequest,jParams.getOperationMode(),jParams); 1037 visitor.undoStaging(); 1038 processedPages.add(new Integer (pageID.intValue())); 1039 contentPage.commitChanges(true,jParams); 1041 } 1042 } 1043 ServicesRegistry.getInstance().getJahiaSiteMapService().resetSiteMap(); 1045 pagesVersViewHelper.loadSiteMapViewHelper(jParams.getUser(),request); 1046 } 1047 1048 1057 private ActionForward continueForward( 1058 ActionMapping mapping, 1059 HttpServletRequest request, 1060 ActionMessages errors, 1061 ActionForward continueForward){ 1062 1063 if(errors != null && !errors.isEmpty()){ 1064 saveErrors(request,errors); 1065 return mapping.findForward("EnginesErrors"); 1066 } 1067 return continueForward; 1068 } 1069 1070 1076 private void initRevisionsDateListener(PagesVersioningViewHelper engineViewHelper, 1077 HttpServletRequest request) 1078 throws JahiaSessionExpirationException { 1079 1080 JahiaEngineCommonData engineCommonData = (JahiaEngineCommonData) 1081 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 1082 1083 String fromDateKey = "PagesVersioningAction_fromdate_" + 1085 request.getSession().getId(); 1086 DatePickerEventListener fromDateListener = DatePicker.getInstance() 1087 .getListener(fromDateKey); 1088 long dateLong = new Date().getTime(); 1089 if ( fromDateListener == null ){ 1090 DateValidator validator = new DateValidator(dateLong, 1091 DateValidator.NO_COMP); 1092 fromDateListener = new DatePickerEventListener(fromDateKey,dateLong,validator); 1093 DatePicker.getInstance().addListener(fromDateKey,fromDateListener); 1094 } 1095 request.setAttribute("pagesversioning.startdate", 1096 DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM, 1097 engineCommonData.getParamBean().getLocale()).format(new Date(fromDateListener.getDate()))); 1098 request.setAttribute("from_" + DatePickerAction.DATE_EVENT_PARAM,fromDateKey); 1099 engineViewHelper.setFromRevisionDate(fromDateListener.getDate()); 1100 1101 String toDateKey = "PagesVersioningAction_todate_" + 1103 request.getSession().getId(); 1104 DatePickerEventListener toDateListener = DatePicker.getInstance() 1105 .getListener(toDateKey); 1106 1107 DateValidator validator = 1108 new DateValidator(fromDateListener.getDate(), 1109 DateValidator.COMP_BIGGER_EQUAL); 1110 if ( toDateListener == null ){ 1111 toDateListener = 1112 new DatePickerEventListener(toDateKey,fromDateListener.getDate(),validator); 1113 } else { 1114 toDateListener.setValidator(validator); 1115 if ( toDateListener.getDate() < fromDateListener.getDate() ){ 1116 toDateListener.setDate(fromDateListener.getDate()); 1117 } 1118 } 1119 1120 DatePicker.getInstance().addListener(toDateKey,toDateListener); 1121 1122 request.setAttribute("pagesversioning.stopdate", 1123 DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM, 1124 engineCommonData.getParamBean().getLocale()).format(new Date(toDateListener.getDate()))); 1125 request.setAttribute("to_" + DatePickerAction.DATE_EVENT_PARAM,toDateKey); 1126 engineViewHelper.setToRevisionDate(toDateListener.getDate()); 1127 1128 } 1129 1130 1135 private void initRestoreDateListener(PagesVersioningViewHelper engineViewHelper, 1136 HttpServletRequest request) 1137 throws JahiaSessionExpirationException { 1138 1139 JahiaEngineCommonData engineCommonData = (JahiaEngineCommonData) 1140 request.getAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA); 1141 1142 String restoreDateKey = "PagesVersioningAction_restoredate_" + 1144 request.getSession().getId(); 1145 DatePickerEventListener restoreDateListener = DatePicker.getInstance() 1146 .getListener(restoreDateKey); 1147 1148 java.util.Date d = new java.util.Date (); 1149 long currentTime = d.getTime(); 1150 DateValidator validator = new DateValidator(currentTime, 1151 DateValidator.COMP_SMALLER_EQUAL); 1152 1153 if (engineViewHelper.getSiteMapDisplayDate().longValue() == 0 ){ 1154 engineViewHelper.setSiteMapDisplayDate(currentTime); 1155 } 1156 if ( restoreDateListener == null ){ 1157 restoreDateListener = 1158 new DatePickerEventListener(restoreDateKey, 1159 engineViewHelper.getSiteMapDisplayDate().longValue(),validator); 1160 } else { 1161 restoreDateListener.setValidator(validator); 1162 engineViewHelper.setSiteMapDisplayDate(restoreDateListener.getDate()); 1163 } 1164 1165 DatePicker.getInstance().addListener(restoreDateKey,restoreDateListener); 1166 request.setAttribute("pagesversioning.restoredate", 1167 DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM, 1168 engineCommonData.getParamBean().getLocale()) 1169 .format(new Date(restoreDateListener.getDate()))); 1170 d = new java.util.Date (restoreDateListener.getDate()); 1172 request.setAttribute("pagesversioning.fullrestoredate", 1173 DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM, 1174 engineCommonData.getParamBean().getLocale()).format(d)); 1175 1176 request.setAttribute("restore_" + DatePickerAction.DATE_EVENT_PARAM,restoreDateKey); 1177 } 1178 1179 1190 public static String composeActionURL(ContentPage contentPage, 1191 ParamBean jParams, 1192 String strutsAction, 1193 Properties properties, 1194 String params) 1195 throws JahiaException { 1196 if ( properties == null ){ 1198 properties = new Properties(); 1199 } 1200 properties.put("pageid",String.valueOf(contentPage.getID())); 1201 String url = jParams.composeStrutsUrl(strutsAction,properties,params); 1202 return url; 1203 } 1204 1205 1211 private ArrayList getPageToRestore(String pageParamStr){ 1212 1213 ArrayList array = new ArrayList(); 1214 1215 try { 1216 StringTokenizer strToken = new StringTokenizer(pageParamStr, "_"); 1217 String id = ""; 1218 String type = ""; 1219 String parentID = ""; 1220 String lang = ""; 1221 1222 if (strToken.countTokens()>4) { 1223 strToken.nextToken(); 1224 type = strToken.nextToken(); 1225 id = strToken.nextToken(); 1226 parentID = strToken.nextToken(); 1227 while ( strToken.hasMoreTokens() ){ 1228 lang += strToken.nextToken(); 1229 if ( strToken.hasMoreTokens() ) { 1230 lang += "_"; 1231 } 1232 } 1233 array.add(lang); 1234 array.add(new Integer (id)); 1235 } 1236 } catch ( Throwable t ){ 1237 logger.debug("Error occurred",t); 1238 } 1239 return array; 1240 } 1241 1242 1251 private ArrayList getPagesToRestore(HttpServletRequest request) 1252 throws JahiaException{ 1253 ArrayList pages = new ArrayList(); 1254 Enumeration paramNames = request.getParameterNames(); 1255 String paramName = ""; 1256 while ( paramNames.hasMoreElements() ){ 1257 paramName = (String )paramNames.nextElement(); 1258 if (paramName.startsWith("checkbox_ContentPage_") ){ 1259 ArrayList array = getPageToRestore(paramName); 1260 pages.addAll(array); 1261 } 1262 } 1263 return pages; 1264 } 1265 1266 1271 private RevisionEntrySet getRevisionEntrySet(String revisionEntrySetKey){ 1272 1273 PageRevisionEntrySet revisionEntrySet = null; 1274 try { 1275 StringTokenizer strToken = new StringTokenizer(revisionEntrySetKey, "_"); 1276 String objType = ""; 1277 String objID = ""; 1278 String w = ""; 1279 String v = ""; 1280 1281 if (strToken.countTokens()==4) { 1282 objType = strToken.nextToken(); 1283 objID = strToken.nextToken(); 1284 w = strToken.nextToken(); 1285 v = strToken.nextToken(); 1286 revisionEntrySet = 1287 new PageRevisionEntrySet(Integer.parseInt(v), 1288 ObjectKey.getInstance(objType + "_" + objID)); 1289 } 1290 } catch ( Throwable t ){ 1291 } 1293 return revisionEntrySet; 1294 } 1295 1296 1297 1307 private void removeMoreRecentActivePages(ContentPage contentPage, 1308 JahiaUser user, 1309 String operationMode, 1310 ContentObjectEntryState entryState, 1311 StateModificationContext stateModificationContext, 1312 RestoreVersionTestResults result, 1313 HashMap pagesToRestore, 1314 ArrayList selectedPages, 1315 ArrayList processedPages, 1316 ParamBean jParams ) throws JahiaException{ 1317 Enumeration childs = contentPage.getChilds(jParams); 1318 while (childs.hasMoreElements()){ 1319 JahiaPage child = (JahiaPage)childs.nextElement(); 1320 ContentPage contentPageChild = ContentPage.getPage(child.getID()); 1321 if ( processedPages.contains(new Integer (child.getID())) ){ 1322 continue; 1323 } 1324 if ( !contentPageChild.hasActiveEntries() && 1325 !contentPageChild.hasStagingEntries() ){ 1326 continue; 1329 } 1330 1331 if ( contentPageChild.getParentID(EntryLoadRequest.STAGED) 1333 != contentPage.getID() ){ 1334 continue; } 1336 1337 if ( child.getPageType()==ContentPage.TYPE_DIRECT 1338 && contentPageChild.isDeletedOrDoesNotExist(entryState.getVersionID()) ){ 1339 1342 1347 1348 ContentObjectEntryState removeEntryState = 1349 new ContentObjectEntryState(entryState.getWorkflowState(), 1350 entryState.getVersionID(), 1351 entryState.getLanguageCode()); 1352 RestoreVersionStateModificationContext smc = 1353 new RestoreVersionStateModificationContext(contentPageChild.getObjectKey(), 1354 stateModificationContext.getLanguageCodes(),removeEntryState); 1355 result.merge(contentPageChild.restoreVersion(user,operationMode, 1356 removeEntryState,true, 1357 selectedPages.contains(new Integer (contentPageChild.getID())), 1358 smc)); 1359 1360 ArrayList langsArray = (ArrayList)pagesToRestore 1362 .get(new Integer (contentPage.getID())); 1363 if ( langsArray != null ){ 1364 langsArray.remove(entryState.getLanguageCode()); 1365 Iterator it = langsArray.iterator(); 1366 while (it.hasNext()) { 1367 String lng = (String ) it.next(); 1368 removeEntryState = new ContentObjectEntryState( 1369 removeEntryState.getWorkflowState(), 1370 removeEntryState.getVersionID(), lng); 1371 smc.getLanguageCodes().clear(); 1372 smc.getLanguageCodes().add(lng); 1373 result.merge(contentPageChild.restoreVersion(user, 1374 operationMode, 1375 removeEntryState, true, 1376 selectedPages.contains(new Integer (contentPageChild.getID())), 1377 smc)); 1378 } 1379 pagesToRestore.put(new Integer (contentPageChild.getID()), 1380 langsArray.clone()); 1381 } 1382 1383 processedPages.add(new Integer (contentPageChild.getID())); 1384 removeMoreRecentActivePages(contentPageChild,user, 1386 operationMode,entryState,stateModificationContext,result, 1387 pagesToRestore, selectedPages, processedPages, 1388 jParams); 1389 } 1390 } 1391 } 1392 1393 1395 1403 private boolean acquireTreeLocks (ParamBean jParams, ActionMessages actionMessages) 1404 throws JahiaException { 1405 ArrayList acquiredPageLocks = new ArrayList(); 1406 if (Jahia.getSettings ().areLocksActivated ()) { 1407 JahiaUser user = jParams.getUser (); 1408 HtmlCache htmlCache = CacheFactory.getHtmlCache(); 1409 ContentPage contentPage = ServicesRegistry.getInstance (). 1410 getJahiaPageService ().lookupContentPage (jParams.getPageID (), false); 1411 JahiaSiteMapService siteMapService = ServicesRegistry.getInstance (). 1412 getJahiaSiteMapService (); 1413 int pageInfosFlag = ContentPage.ACTIVE_PAGE_INFOS | ContentPage.STAGING_PAGE_INFOS; 1416 siteMapService.invokeTreeSiteMapViewHelperMethod (jParams.getUser (), 1417 contentPage, jParams.getSessionID (), pageInfosFlag, 1418 null, "expandall|0"); 1419 1420 SiteMapViewHelper treeSiteMapViewHelper = siteMapService. 1423 getTreeSiteMapViewHelper (jParams.getUser (), contentPage, 1424 jParams.getSessionID (), ContentPage.ACTIVE_PAGE_INFOS | 1425 ContentPage.STAGING_PAGE_INFOS, 1426 null, Integer.MAX_VALUE); 1427 1428 LockService lockRegistry = ServicesRegistry.getInstance ().getLockService (); 1430 1431 for (int i = 0; i < treeSiteMapViewHelper.size (); i++) { 1435 ContentPage siteMapContentPage = treeSiteMapViewHelper.getContentPage (i); 1436 if (siteMapContentPage != null) { 1437 LockKey lockKey = LockKey.composeLockKey (LockKey.UPDATE_PAGE_TYPE, 1438 siteMapContentPage.getID (), siteMapContentPage.getID ()); 1439 if (!lockRegistry.isAcquireable (lockKey, user, jParams.getSessionID ())) { 1440 actionMessages.add(ActionMessages.GLOBAL_MESSAGE, 1443 new ActionMessage("message.org.jahia.views.engines.versioning.pages.cannotLockPage", new Integer (siteMapContentPage.getID()))); 1444 return false; 1445 } 1446 } 1447 } 1448 1449 for (int i = 0; i < treeSiteMapViewHelper.size (); i++) { 1450 ContentPage siteMapContentPage = treeSiteMapViewHelper.getContentPage (i); 1451 if (siteMapContentPage != null) { 1452 LockKey lockKey = LockKey.composeLockKey (LockKey.UPDATE_PAGE_TYPE, 1453 siteMapContentPage.getID (), siteMapContentPage.getID ()); 1454 if (lockRegistry.acquire (lockKey, user, jParams.getSessionID (), 1455 jParams.getSession ().getMaxInactiveInterval ())) { 1456 htmlCache.invalidatePageEntries(Integer.toString(siteMapContentPage.getID())); 1457 logger.debug ( 1458 "Lock acquired for page " + 1459 siteMapContentPage.getTitles (true)); 1460 acquiredPageLocks.add(new Integer (siteMapContentPage.getID())); 1461 } else { 1462 logger.warn ("Warning, page tree was partly locked for updating, you might want to clear the locks manually."); 1467 return false; 1468 } 1469 } 1470 } 1471 } 1472 jParams.getSession().setAttribute(SESSION_VERSIONING_LOCK_LIST, acquiredPageLocks); 1473 return true; 1474 } 1475 1476 private void releaseTreeLocks (ParamBean jParams) 1477 throws JahiaException { 1478 if (Jahia.getSettings ().areLocksActivated ()) { 1479 ArrayList acquiredPageLocks = (ArrayList) jParams.getSession().getAttribute(SESSION_VERSIONING_LOCK_LIST); 1480 if (acquiredPageLocks == null){ 1481 return; 1482 } 1483 HtmlCache htmlCache = CacheFactory.getHtmlCache(); 1484 ServicesRegistry.getInstance (). 1485 getJahiaPageService ().lookupContentPage (jParams.getPageID (), false); 1486 1487 LockService lockRegistry = ServicesRegistry.getInstance ().getLockService (); 1489 Iterator acquiredPageIter = acquiredPageLocks.iterator(); 1490 while (acquiredPageIter.hasNext()) { 1491 int curPageID = ((Integer ) acquiredPageIter.next()).intValue(); 1492 LockKey lockKey = LockKey.composeLockKey (LockKey.UPDATE_PAGE_TYPE, 1493 curPageID, curPageID); 1494 lockRegistry.release (lockKey, jParams.getUser (), jParams.getSessionID ()); 1495 htmlCache.invalidatePageEntries(Integer.toString(curPageID)); 1496 } 1497 jParams.getSession().removeAttribute(SESSION_VERSIONING_LOCK_LIST); 1498 } 1499 } 1500 1501 private void releaseActionLock(ParamBean jParams) 1502 throws JahiaException { 1503 if (jParams.settings ().areLocksActivated ()) { 1504 HtmlCache htmlCache = CacheFactory.getHtmlCache(); 1505 LockService lockRegistry = ServicesRegistry.getInstance ().getLockService (); 1506 LockKey lockKey = LockKey.composeLockKey (LockKey.UPDATE_PAGE_TYPE, 1507 jParams.getPageID(), jParams.getPageID()); 1508 lockRegistry.release (lockKey, jParams.getUser (), jParams.getSessionID ()); 1509 htmlCache.invalidatePageEntries(Integer.toString(jParams.getPageID())); 1510 } 1511 } 1512 1514} 1515 | Popular Tags |