1 package org.jahia.services.version; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.SortedSet ; 6 7 import org.jahia.content.ContentObject; 8 import org.jahia.content.ContentTreeStatusInterface; 9 import org.jahia.content.ObjectKey; 10 import org.jahia.content.PageReferenceableInterface; 11 import org.jahia.exceptions.JahiaException; 12 import org.jahia.services.fields.ContentField; 13 import org.jahia.services.fields.ContentPageField; 14 import org.jahia.services.pages.ContentPage; 15 import org.jahia.services.usermanager.JahiaUser; 16 17 26 public class PageRevisionsCompositor extends ContentTreeRevisionsVisitor { 27 28 private static org.apache.log4j.Logger logger = 29 org.apache.log4j.Logger.getLogger(PageRevisionsCompositor.class); 30 31 public static final int ALL_REVISIONS = 0; 32 public static final int CURRENT_PAGE_MODIFICATION_REVISIONS = 1; 33 public static final int PAGES_MODIFICATION_REVISIONS = 2; 34 public static final int CURRENT_PAGE_FIELDS_AND_CONTAINERS_REVISIONS = 3; 35 public static final int PAGES_FIELDS_AND_CONTAINERS_REVISIONS = 4; 36 37 private int typeOfRevisions = PAGES_MODIFICATION_REVISIONS; 38 39 46 public PageRevisionsCompositor(ContentObject rootContentObject, 47 JahiaUser user, 48 EntryLoadRequest loadRequest, 49 String operationMode){ 50 super(rootContentObject,user,loadRequest,operationMode); 51 } 52 53 60 public void processContentObjectBeforeChilds(ContentObject contentObject, int currentPageLevel) 61 throws JahiaException{ 62 63 ContentTreeStatusInterface contentTreeStatus = (ContentTreeStatusInterface) 64 this.getContentTree().getContentTreeStatusStack().peek(); 65 66 if ( !contentObject.checkAdminAccess(this.getUser()) 68 && !contentObject.checkWriteAccess(this.getUser()) ){ 69 contentTreeStatus.setContinueWithChilds(false); 71 contentTreeStatus.setContinueAfterChilds(false); 72 return; 73 } 74 75 boolean hasActiveEntries 77 = contentObject.hasActiveEntries(); 78 if ( !this.isWithDeletedContent() && !hasActiveEntries ){ 79 contentTreeStatus.setContinueWithChilds(false); 81 contentTreeStatus.setContinueAfterChilds(false); 82 return; 83 } 84 85 ArrayList revisions = new ArrayList (); 86 SortedSet entryStates = 87 contentObject.getEntryStates(); 88 89 Iterator iterator = entryStates.iterator(); 90 while ( iterator.hasNext() ){ 91 try { 92 ContentObjectEntryState entryState = 93 (ContentObjectEntryState)iterator.next(); 94 95 if ( entryState.getWorkflowState() 97 > ContentObjectEntryState.WORKFLOW_STATE_ACTIVE ){ 98 continue; 99 } 100 101 if ( !this.isWithActiveRevisions() && entryState.getWorkflowState() 103 == ContentObjectEntryState.WORKFLOW_STATE_ACTIVE ){ 104 continue; 105 } 106 107 if ( !this.isWithDeletedRevisions() && entryState.getWorkflowState() 109 == ContentObjectEntryState.WORKFLOW_STATE_VERSIONING_DELETED ){ 110 continue; 111 } 112 113 if ( inDateRange(entryState) ){ 114 115 119 if ( contentObject instanceof ContentPageField ){ 121 if ( ((ContentField)contentObject).getContainerID() == 0 ){ 122 continue; 123 } 124 } 125 126 RevisionEntrySet revisionEntrySet = null; 127 128 RevisionEntry revisionEntry = new RevisionEntry( 129 new ContentObjectEntryState( 130 entryState.getWorkflowState(), 131 entryState.getVersionID(), 132 entryState.getLanguageCode()), 133 ObjectKey.getInstance(contentObject.getObjectKey().getType() 134 + "_" + contentObject.getObjectKey().getIDInType())); 135 136 if ( !(contentObject instanceof ContentPage) ){ 137 ContentPage objectPage = 138 ((PageReferenceableInterface)contentObject).getPage(); 139 140 revisionEntrySet = new PageRevisionEntrySet( 141 entryState.getVersionID(), 142 ObjectKey.getInstance(objectPage.getObjectKey().getType() 143 + "_" + objectPage.getObjectKey().getIDInType())); 144 setRevisionTitle(revisionEntrySet); 145 146 addRevision(revisionEntry, revisionEntrySet, revisions); 147 continue; 148 } 149 150 181 182 revisionEntrySet = new PageRevisionEntrySet( entryState.getVersionID(), 184 ObjectKey.getInstance(contentObject.getObjectKey().getType() 185 + "_" + contentObject.getObjectKey().getIDInType())); 186 setRevisionTitle(revisionEntrySet); 187 addRevision(revisionEntry, revisionEntrySet, revisions); 188 } 189 } catch ( Throwable t ){ 190 throw new JahiaException("Exception creating revision entry ", 191 "Exception creating revision entry ", 192 JahiaException.DATA_ERROR, 193 JahiaException.DATA_ERROR,t); 194 } 195 } 196 197 this.getRevisions().addAll(revisions); 198 } 199 200 204 public int getTypeOfRevisions(){ 205 return this.typeOfRevisions; 206 } 207 208 212 public void setTypeOfRevisions(int value){ 213 if ( value != this.typeOfRevisions ){ 214 this.hasAttributeChange = true; 215 } 216 this.typeOfRevisions = value; 217 } 218 } 219 | Popular Tags |