1 13 package org.jahia.services.containers; 14 15 import java.io.Serializable ; 16 import java.util.*; 17 18 import org.jahia.content.ContainerDefinitionKey; 19 import org.jahia.content.ContentContainerKey; 20 import org.jahia.content.ContentObject; 21 import org.jahia.content.JahiaObject; 22 import org.jahia.content.ObjectKey; 23 import org.jahia.content.PageReferenceableInterface; 24 import org.jahia.data.containers.ContainersChangeEventListener; 25 import org.jahia.data.containers.JahiaContainer; 26 import org.jahia.data.fields.LoadFlags; 27 import org.jahia.data.fields.JahiaPageField; 28 import org.jahia.exceptions.JahiaException; 29 import org.jahia.params.ParamBean; 30 import org.jahia.registries.JahiaListenersRegistry; 31 import org.jahia.registries.ServicesRegistry; 32 import org.jahia.services.fields.ContentField; 33 import org.jahia.services.fields.ContentPageField; 34 import org.jahia.services.pages.ContentPage; 35 import org.jahia.services.usermanager.JahiaUser; 36 import org.jahia.services.version.ContentObjectEntryState; 37 import org.jahia.services.version.EntryLoadRequest; 38 import org.jahia.services.version.EntryStateable; 39 import org.jahia.services.version.RestoreVersionStateModificationContext; 40 import org.jahia.services.version.RestoreVersionTestResults; 41 import org.jahia.services.version.StateModificationContext; 42 import org.jahia.services.version.VersioningDifferenceStatus; 43 import org.jahia.utils.LanguageCodeConverters; 44 45 54 55 public class ContentContainer extends ContentObject 56 implements PageReferenceableInterface, Cloneable , Serializable { 57 58 private static org.apache.log4j.Logger logger = 59 org.apache.log4j.Logger.getLogger (ContentContainer.class); 60 61 private ArrayList activeAndStagedEntryStates; 62 private ArrayList versionedEntryStates = null; 63 private int parentContainerListID; 64 private int aclID; 65 66 private int jahiaID; 67 private int pageID; 68 private int ctnDefID; 69 70 static { 71 JahiaObject.registerType (ContentContainerKey.CONTAINER_TYPE, 72 ContentContainer.class.getName ()); 73 } 74 75 80 public int getPageID () { 81 return this.pageID; 82 } 83 84 public int getSiteID() { 85 return this.jahiaID; 86 } 87 88 93 public ContentPage getPage () throws JahiaException { 94 return ContentPage.getPage (this.getPageID ()); 95 } 96 97 104 public int getDefinitionID (EntryLoadRequest loadRequest) { 105 return this.ctnDefID; 106 } 107 108 116 public ObjectKey getDefinitionKey (EntryLoadRequest loadRequest) { 117 int defID = getDefinitionID (loadRequest); 118 ContainerDefinitionKey ctnDefKey = (ContainerDefinitionKey) 119 ContainerDefinitionKey.getChildInstance (String.valueOf (defID)); 120 return ctnDefKey; 121 } 122 123 public static ContentObject getChildInstance (String IDInType) { 124 try { 125 return getContainer (Integer.parseInt (IDInType)); 126 } catch (JahiaException je) { 127 logger.debug ("Error retrieving container instance for id : " + IDInType, je); 128 } 129 return null; 130 } 131 132 protected ContentContainer (int ID, int aJahiaID, int aPageID, int aCtnDefID, int listID, 133 int anAclID, ArrayList anActiveAndStagedEntryStates) { 134 super (new ContentContainerKey (ID)); 135 this.jahiaID = aJahiaID; 136 this.pageID = aPageID; 137 this.ctnDefID = aCtnDefID; 138 this.parentContainerListID = listID; 139 this.activeAndStagedEntryStates = anActiveAndStagedEntryStates; 140 this.aclID = anAclID; 141 } 142 143 146 public SortedSet getActiveAndStagingEntryStates () { 147 SortedSet entries = new TreeSet (); 148 entries.addAll (activeAndStagedEntryStates); 149 return entries; 150 } 151 152 public SortedSet getEntryStates () 153 throws JahiaException { 154 SortedSet resultSet = new TreeSet (); 155 if (versionedEntryStates == null) { 156 versionedEntryStates = 157 ContentContainerDB.getInstance ().getVersionedEntryStates (getID (), false); 158 } 159 resultSet.addAll (activeAndStagedEntryStates); 160 resultSet.addAll (versionedEntryStates); 161 return resultSet; 162 } 163 164 public ArrayList getChilds(JahiaUser user, EntryLoadRequest loadRequest) throws JahiaException { 165 return getChilds(user, loadRequest, ContainerFactoryProxy.LOAD_FIELD_AND_SUBCONTAINER_LISTS); 166 } 167 168 public ArrayList getChilds (JahiaUser user, 169 EntryLoadRequest loadRequest, 170 int loadFlag) 171 throws JahiaException { 172 173 ArrayList resultList = new ArrayList (); 174 if ((loadFlag & ContainerFactoryProxy.LOAD_FIELDS) != 0) { 175 Vector fieldIDs = ContentContainerTools.getInstance().getFieldIDsByContainer(getID(), loadRequest); 176 177 Enumeration fieldIDEnum = fieldIDs.elements(); 178 if (fieldIDEnum.hasMoreElements()) { 179 int fieldID = ((Integer ) fieldIDEnum.nextElement()).intValue(); 180 ContentField currentField = ContentField.getFieldFromCacheOnly(fieldID); 181 if (currentField == null) { 182 ContentField.preloadActiveOrStagedFieldsByContainerID(getID()); 183 } 184 currentField = ContentField.getField(fieldID); 185 if (currentField != null) { 186 resultList.add(currentField); 187 } 188 189 while (fieldIDEnum.hasMoreElements()) { 190 fieldID = ((Integer ) fieldIDEnum.nextElement()).intValue(); 191 currentField = ContentField.getField(fieldID); 192 if (currentField != null) { 193 resultList.add(currentField); 194 } 195 } 196 } 197 } 198 if ((loadFlag & ContainerFactoryProxy.LOAD_SUBCONTAINER_LISTS) != 0) { 199 Enumeration subContainerListIDEnum = JahiaContainerUtilsDB.getInstance().getContainerSubContainerListIDs( 202 getID(), loadRequest).elements(); 203 while (subContainerListIDEnum.hasMoreElements()) { 204 Integer curContainerListID = (Integer ) subContainerListIDEnum.nextElement(); 205 ContentContainerList curContainerList = ContentContainerList.getContainerList(curContainerListID 206 .intValue()); 207 if (curContainerList != null) { 208 resultList.add(curContainerList); 209 } 210 } 211 } 212 return resultList; 213 } 214 215 public ContentObject getParent (JahiaUser user, 216 EntryLoadRequest loadRequest, 217 String operationMode) 218 throws JahiaException { 219 return ContentContainerList.getContainerList (parentContainerListID); 220 } 221 222 public static ContentContainer getContainer (int containerID) 223 throws JahiaException { 224 return ContentContainerTools.getInstance() 225 .getContainer(containerID); 226 } 227 228 235 public static ContentContainer getContainer (int containerID, boolean loadFromDB) 236 throws JahiaException { 237 return ContentContainerTools.getInstance() 238 .getContainer(containerID,loadFromDB); 239 } 240 241 249 public static Properties getContainerProperties(int containerID) 250 throws JahiaException 251 { 252 return ContentContainerTools.getInstance().getContainerProperties( 253 containerID); 254 } 255 256 public RestoreVersionTestResults isValidForRestore (JahiaUser user, 257 String operationMode, 258 ContentObjectEntryState entryState, 259 boolean removeMoreRecentActive, 260 StateModificationContext stateModificationContext) 261 throws JahiaException { 262 RestoreVersionTestResults opResult = new RestoreVersionTestResults (); 265 opResult.merge ( 266 super.isValidForRestore (user, operationMode, entryState, 267 removeMoreRecentActive, stateModificationContext)); 268 if (opResult.getStatus () == RestoreVersionTestResults.FAILED_OPERATION_STATUS) { 269 return opResult; 270 } 271 272 ArrayList locales = new ArrayList (); 275 locales.add ( 276 LanguageCodeConverters.languageCodeToLocale (ContentObject.SHARED_LANGUAGE)); 277 locales.add (LanguageCodeConverters.languageCodeToLocale (entryState.getLanguageCode ())); 278 EntryLoadRequest loadRequest = new EntryLoadRequest (entryState.getWorkflowState (), 279 entryState.getVersionID (), locales); 280 ArrayList children = getChilds (user, loadRequest); 281 ListIterator childrenIter = children.listIterator (); 282 while (childrenIter.hasNext ()) { 283 ContentObject curChild = (ContentObject) childrenIter.next (); 284 opResult.merge ( 285 curChild.isValidForRestore (user, operationMode, entryState, 286 removeMoreRecentActive, stateModificationContext)); 287 } 288 return opResult; 289 } 290 291 private boolean hasEntry (EntryStateable entryState) 292 throws JahiaException { 293 getEntryStates (); ContentObjectEntryState entryStateObject = new ContentObjectEntryState (entryState); 296 if (entryStateObject.getWorkflowState () >= ContentObjectEntryState.WORKFLOW_STATE_ACTIVE) { 297 int objectPos = activeAndStagedEntryStates.indexOf (entryStateObject); 298 if (objectPos != -1) { 299 return true; 300 } 301 } else { 302 int objectPos = versionedEntryStates.indexOf (entryStateObject); 303 if (objectPos != -1) { 304 return true; 305 } 306 307 } 308 return false; 309 } 310 311 private void removeEntryFromCaches (EntryStateable entryState) 312 throws JahiaException { 313 getEntryStates (); ContentObjectEntryState entryStateObject = new ContentObjectEntryState (entryState); 316 if (entryStateObject.getWorkflowState () >= ContentObjectEntryState.WORKFLOW_STATE_ACTIVE) { 317 int objectPos = activeAndStagedEntryStates.indexOf (entryStateObject); 318 if (objectPos != -1) { 319 activeAndStagedEntryStates.remove (objectPos); 320 } 321 } else { 322 int objectPos = versionedEntryStates.indexOf (entryStateObject); 323 if (objectPos != -1) { 324 versionedEntryStates.remove (objectPos); 325 } 326 327 } 328 } 329 330 338 protected void copyEntry (EntryStateable fromEntryState, 339 EntryStateable toEntryState) 340 throws JahiaException { 341 342 ContentObjectEntryState fromE = new ContentObjectEntryState (fromEntryState); 343 ContentObjectEntryState toE = new ContentObjectEntryState (toEntryState); 344 if (this.isShared ()) { 345 fromE = new ContentObjectEntryState (fromEntryState.getWorkflowState (), 347 fromEntryState.getVersionID (), ContentObject.SHARED_LANGUAGE); 348 349 toE = new ContentObjectEntryState (toEntryState.getWorkflowState (), 350 toEntryState.getVersionID (), ContentObject.SHARED_LANGUAGE); 351 } 352 353 if (hasEntry (toE)) { 354 deleteEntry (toE); 355 } 356 357 ContentContainerDB.getInstance ().copyEntry (getID (), fromE, toE); 358 359 if (toE.getWorkflowState () >= ContentObjectEntryState.WORKFLOW_STATE_ACTIVE) { 360 activeAndStagedEntryStates.add (toE); 361 } else { 362 versionedEntryStates.add (toE); 363 } 364 } 365 366 375 protected void deleteEntry (EntryStateable deleteEntryState) 376 throws JahiaException { 377 removeEntryFromCaches (deleteEntryState); 378 ContentContainerDB.getInstance ().deleteEntry (getID (), deleteEntryState); 379 } 380 381 397 public void markLanguageForDeletion (JahiaUser user, 398 String languageCode, 399 StateModificationContext 400 stateModificationContext) 401 throws JahiaException { 402 ServicesRegistry.getInstance ().getJahiaContainersService () 403 .markContainerLanguageForDeletion (getID (), user, languageCode, 404 stateModificationContext); 405 406 notifyContainerUpdate(ContainersChangeEventListener.CONTAINER_DELETED); 407 } 408 409 public int getAclID () { 410 return aclID; 411 } 412 413 public RestoreVersionTestResults restoreVersion (JahiaUser user, 414 String operationMode, 415 ContentObjectEntryState entryState, 416 boolean removeMoreRecentActive, 417 RestoreVersionStateModificationContext 418 stateModificationContext) 419 throws JahiaException { 420 421 RestoreVersionTestResults opResult = new RestoreVersionTestResults (); 422 423 getClosestVersionedEntryState(entryState); 425 boolean isDeleted = this.isDeletedOrDoesNotExist(entryState.getVersionID()); 426 427 ArrayList locales = new ArrayList(); 428 locales.add(LanguageCodeConverters.languageCodeToLocale(entryState.getLanguageCode())); 429 EntryLoadRequest loadRequest = null; 430 431 ArrayList children = null; 432 if ( !isDeleted ){ 433 loadRequest = new EntryLoadRequest(entryState. 436 getWorkflowState(), 437 entryState.getVersionID(), 438 locales); 439 children = getChilds(user, loadRequest); 440 441 ArrayList processedChilds = new ArrayList(); 443 444 ListIterator childrenIter = children.listIterator(); 445 while (childrenIter.hasNext()) { 446 ContentObject curChild = (ContentObject) childrenIter.next(); 447 opResult.merge(curChild.restoreVersion(user, 448 operationMode, entryState, (removeMoreRecentActive), 449 stateModificationContext)); 450 processedChilds.add(curChild.getObjectKey().toString()); 451 } 452 453 if ( removeMoreRecentActive ){ 458 461 loadRequest = 463 new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 464 0, locales); 465 children = getChilds(user, loadRequest); 466 childrenIter = children.listIterator(); 467 468 while (childrenIter.hasNext()) { 469 ContentObject curChild = (ContentObject) childrenIter.next(); 470 471 if (!processedChilds.contains(curChild.getObjectKey(). 472 toString())) { 473 opResult.merge(curChild.restoreVersion(user, 474 operationMode, entryState, removeMoreRecentActive, 475 stateModificationContext)); 476 } 477 } 478 } 479 } 480 481 ContentContainer contentContainer 485 = ContentContainer.getContainer(this.getID(),true); 486 contentContainer.getEntryStates(); 487 this.activeAndStagedEntryStates = 488 new ArrayList(contentContainer.getActiveAndStagingEntryStates()); 489 this.versionedEntryStates = 490 new ArrayList(contentContainer.versionedEntryStates); 491 492 opResult.merge(super.restoreVersion(user, operationMode, entryState, 493 removeMoreRecentActive, 494 stateModificationContext)); 495 496 if (stateModificationContext.getContainerPageChildId() == -1){ 498 Set stagedStates = this.getStagingLanguages(false); 499 if ( !stagedStates.isEmpty() ){ 500 loadRequest = new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, locales); 501 loadRequest.setWithMarkedForDeletion(true); 502 children = this.getChilds(user,loadRequest); 503 Iterator it = children.iterator(); 504 boolean processLive = true; 505 RestoreVersionStateModificationContext smc = new RestoreVersionStateModificationContext(stateModificationContext.getStartObject(),stateModificationContext.getLanguageCodes(),stateModificationContext.getEntryState()); 506 smc.pushAllLanguages(true); 507 while ( it.hasNext() ){ 508 ContentObject curChild = (ContentObject) it.next(); 509 if ( curChild instanceof ContentPageField){ 510 JahiaPageField jahiaPageField = (JahiaPageField)((ContentPageField)curChild).getJahiaField(loadRequest); 511 try { 512 int pageId = Integer.parseInt(jahiaPageField.getValue()); 513 if ( pageId != -1 ){ 514 ContentPage contentPage = ContentPage.getPage(pageId); 515 if ( contentPage != null ){ 516 if ( !contentPage.hasActiveOrStagingEntries() || contentPage.isMarkedForDelete() ) { 517 this.markLanguageForDeletion(user,ContentObject.SHARED_LANGUAGE,stateModificationContext); 518 } else { 519 ContentPageField pageField = (ContentPageField)contentPage.getParent(EntryLoadRequest.STAGED); 521 if ( pageField != null && pageField.getContainerID() != this.getID() ){ 522 this.markLanguageForDeletion(user,ContentObject.SHARED_LANGUAGE,stateModificationContext); 523 } 524 } 525 526 } 527 } 528 } catch ( Throwable t ){ 529 } 530 processLive = false; 531 break; 532 } 533 } 534 if ( processLive ){ 535 loadRequest = new EntryLoadRequest(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 536 ServicesRegistry.getInstance() 537 .getJahiaVersionService().getCurrentVersionID(), locales); 538 loadRequest.setWithDeleted(true); 539 children = this.getChilds(user,loadRequest); 540 it = children.iterator(); 541 while ( it.hasNext() ){ 542 ContentObject curChild = (ContentObject) it.next(); 543 if ( curChild instanceof ContentPageField ){ 544 JahiaPageField jahiaPageField = (JahiaPageField)((ContentPageField)curChild).getJahiaField(loadRequest); 545 try { 546 int pageId = Integer.parseInt(jahiaPageField.getValue()); 547 if ( pageId != -1 ){ 548 ContentPage contentPage = ContentPage.getPage(pageId); 549 if ( contentPage != null ){ 550 if ( !contentPage.hasActiveOrStagingEntries() || contentPage.isMarkedForDelete() ) { 551 this.markLanguageForDeletion(user,ContentObject.SHARED_LANGUAGE,stateModificationContext); 552 } else { 553 ContentPageField pageField = (ContentPageField)contentPage.getParent(EntryLoadRequest.STAGED); 555 if ( pageField != null && pageField.getContainerID() != this.getID() ){ 556 this.markLanguageForDeletion(user,ContentObject.SHARED_LANGUAGE,stateModificationContext); 557 } 558 } 559 } 560 } 561 } catch ( Throwable t ){ 562 } 563 break; 564 } 565 } 566 } 567 } 568 } 569 570 notifyContainerUpdate(ContainersChangeEventListener.CONTAINER_UPDATED); 571 572 return opResult; 573 } 574 575 578 public boolean isShared () { 579 return true; 580 } 581 582 587 public int getParentContainerListID () { 588 return this.parentContainerListID; 589 } 590 591 public JahiaContainer getJahiaContainer (ParamBean jParams, EntryLoadRequest loadRequest) 592 throws JahiaException { 593 return ServicesRegistry.getInstance ().getJahiaContainersService ().loadContainer ( 594 getID (), LoadFlags.ALL, jParams, loadRequest); 595 } 596 597 605 public synchronized void undoStaging (ParamBean jParams) 606 throws JahiaException { 607 608 Vector stagedEntryStates = new Vector (); 610 for (int i = 0; i < activeAndStagedEntryStates.size (); i++) { 611 ContentObjectEntryState entryState = (ContentObjectEntryState) activeAndStagedEntryStates.get ( 612 i); 613 if (entryState.isStaging ()) { 615 stagedEntryStates.add (entryState); 616 } 617 } 618 619 for (int i = 0; i < stagedEntryStates.size (); i++) { 621 ContentObjectEntryState curEntryState = (ContentObjectEntryState) stagedEntryStates.get ( 622 i); 623 624 this.deleteEntry (curEntryState); 626 } 627 notifyContainerUpdate(ContainersChangeEventListener.CONTAINER_UPDATED); 628 } 629 630 645 public int getRestoreStatus (int oldVersion, int newVersion, boolean exactRestore) 646 throws JahiaException { 647 648 int status = VersioningDifferenceStatus.UNCHANGED; 649 650 ContentObjectEntryState oldEntryState = 652 ContentObjectEntryState.getEntryState (oldVersion, 653 ContentObject.SHARED_LANGUAGE); 654 oldEntryState = this.getEntryState (oldEntryState, false, false); 655 656 ContentObjectEntryState newEntryState = 658 ContentObjectEntryState.getEntryState (newVersion, 659 ContentObject.SHARED_LANGUAGE); 660 newEntryState = this.getEntryState (newEntryState, false, false); 661 662 status = getRestoreStatus (oldEntryState, newEntryState, exactRestore); 663 return status; 664 } 665 666 676 public int getRestoreStatus (ContentObjectEntryState oldEntryState, 677 ContentObjectEntryState newEntryState, 678 boolean exactRestore) { 679 680 int status = VersioningDifferenceStatus.UNCHANGED; 681 if (oldEntryState == null && newEntryState == null) { 682 return status; 683 } 684 685 if (oldEntryState == null) { 686 if (exactRestore) { 688 if (newEntryState != null) { 689 if ((newEntryState.getWorkflowState () == -1) 690 || (newEntryState.isStaging () && newEntryState.getVersionID () 691 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED)) { 692 status = VersioningDifferenceStatus.CURRENTLY_DELETED_AND_NOT_RESTORED; 693 } else { 694 status = VersioningDifferenceStatus.TO_BE_REMOVED; 696 } 697 } 698 } else { 699 if (newEntryState != null) { 700 if ((newEntryState.getWorkflowState () == -1) 701 || (newEntryState.isStaging () && newEntryState.getVersionID () 702 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED)) { 703 status = VersioningDifferenceStatus.CURRENTLY_DELETED_AND_NOT_RESTORED; 704 } else { 705 status = VersioningDifferenceStatus.ADDED; 706 } 707 } else { 708 status = VersioningDifferenceStatus.ADDED; 709 } 710 } 711 } else { 712 if (newEntryState == null) { 713 if (oldEntryState.getWorkflowState () 714 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED) { 715 status = VersioningDifferenceStatus.CURRENTLY_DELETED_AND_NOT_RESTORED; 716 } 717 } else { 718 if (exactRestore) { 719 if (oldEntryState.getWorkflowState () 720 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED) { 721 if (newEntryState.getWorkflowState () 722 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED 723 || (newEntryState.isStaging () && newEntryState.getVersionID () 724 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED)) { 725 status = 726 VersioningDifferenceStatus.CURRENTLY_DELETED_AND_NOT_RESTORED; 727 } else { 728 status = VersioningDifferenceStatus.TO_BE_REMOVED; 730 } 731 } else { 732 if (newEntryState.getWorkflowState () 733 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED 734 || (newEntryState.isStaging () 735 && newEntryState.getVersionID () 736 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED)) { 737 status = VersioningDifferenceStatus.TO_BE_RESTORED; 739 } else { 740 status = VersioningDifferenceStatus.TO_BE_UPDATED; 741 } 742 } 743 } else { 744 if (oldEntryState.getWorkflowState () 745 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED) { 746 if (newEntryState.getWorkflowState () 747 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED 748 || (newEntryState.isStaging () && newEntryState.getVersionID () 749 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED)) { 750 status = 751 VersioningDifferenceStatus.CURRENTLY_DELETED_AND_NOT_RESTORED; 752 } 753 } else { 754 if (newEntryState.getWorkflowState () 755 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED 756 || (newEntryState.isStaging () 757 && newEntryState.getVersionID () 758 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED)) { 759 status = VersioningDifferenceStatus.TO_BE_RESTORED; 761 } else { 762 status = VersioningDifferenceStatus.TO_BE_UPDATED; 763 } 764 } 765 } 766 } 767 } 768 return status; 769 } 770 771 777 public int getStagingStatus () 778 throws JahiaException { 779 780 int status = VersioningDifferenceStatus.UNCHANGED; 781 782 ContentObjectEntryState activeEntryState = 784 ContentObjectEntryState.getEntryState (1, 785 ContentObject.SHARED_LANGUAGE); 786 activeEntryState = this.getEntryState (activeEntryState, false, false); 787 788 ContentObjectEntryState stagingEntryState = 790 ContentObjectEntryState.getEntryState (0, 791 ContentObject.SHARED_LANGUAGE); 792 stagingEntryState = this.getEntryState (stagingEntryState, false, false); 793 794 if (stagingEntryState != null) { 795 if (stagingEntryState.getVersionID () 796 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED) { 797 status = VersioningDifferenceStatus.TO_BE_REMOVED; 798 } else { 799 if (activeEntryState == null) { 800 status = VersioningDifferenceStatus.ADDED; 801 } else { 802 status = VersioningDifferenceStatus.TO_BE_UPDATED; 803 } 804 } 805 } 806 return status; 807 } 808 809 819 public Map getLanguagesStatesWithoutChilds () { 820 821 int size = activeAndStagedEntryStates.size (); 822 Map languageStates = new HashMap (); 823 824 for (int i = 0; i < size; i++) { 826 ContentObjectEntryState entryState = (ContentObjectEntryState) activeAndStagedEntryStates.get ( 827 i); 828 if (!entryState.isStaging ()) { 830 languageStates.put (entryState.getLanguageCode (), 831 new Integer (entryState.getWorkflowState ())); 832 } 833 } 834 835 for (int i = 0; i < size; i++) { 837 ContentObjectEntryState entryState = (ContentObjectEntryState) activeAndStagedEntryStates.get ( 838 i); 839 if (entryState.isStaging ()) { 841 languageStates.put (entryState.getLanguageCode (), 842 new Integer (entryState.getWorkflowState ())); 843 } 844 } 845 846 return languageStates; 847 } 848 849 854 public static void notifyContainerUpdate(int containerID, String operation){ 855 856 ContentContainerTools.getInstance().invalidateContainerFromCache(containerID); 858 try { 859 ContentContainer contentContainer = getContainer(containerID); 861 if ( contentContainer != null ){ 862 contentContainer.notifyContainerUpdate(operation,false); 863 } 864 } catch ( JahiaException je ){ 865 logger.debug("Exception occured on ContentContainer id=" + containerID, 866 je); 867 } 868 } 869 870 875 private void notifyContainerUpdate(String operation){ 876 notifyContainerUpdate(operation,true); 877 } 878 879 884 private void notifyContainerUpdate(String operation, boolean updateCache){ 885 886 if ( updateCache ){ 887 ContentContainerTools.getInstance().invalidateContainerFromCache(this.getID()); 889 ServicesRegistry.getInstance ().getJahiaContainersService () 890 .invalidateContainerFromCache(this.getID()); 891 JahiaContainerUtilsDB.getInstance().invalidateCtnIdsByCtnListCache(this.getParentContainerListID()); 892 } 893 ContainersChangeEventListener listener = ( 894 ContainersChangeEventListener)JahiaListenersRegistry. 895 getInstance () 896 .getListener (ContainersChangeEventListener.class.getName ()); 897 if ( listener != null ){ 898 listener.notifyChange(this,operation); 899 } 900 } 901 902 906 public Object clone () { 907 ArrayList localActiveAndStagedEntryStates = new ArrayList(); 908 if ( this.activeAndStagedEntryStates != null ){ 909 localActiveAndStagedEntryStates = (ArrayList) 910 this.activeAndStagedEntryStates.clone(); 911 } 912 ContentContainer clone = 913 new ContentContainer (this.getID(),this.jahiaID,this.getPageID(), 914 this.ctnDefID, this.parentContainerListID, 915 this.aclID, localActiveAndStagedEntryStates); 916 if ( this.versionedEntryStates != null ){ 917 clone.versionedEntryStates = 918 (ArrayList)this.versionedEntryStates.clone(); 919 } 920 return clone; 921 } 922 923 public static void invalidateContainerCache(int containerID) { 924 ContentContainerTools.getInstance().invalidateContainerFromCache(containerID); 925 } 926 927 } 928 929 | Popular Tags |