1 13 package org.jahia.services.version; 14 15 import java.util.ArrayList ; 16 import java.util.Iterator ; 17 import java.util.SortedSet ; 18 import java.util.TreeSet ; 19 20 import org.jahia.content.ContentObject; 21 import org.jahia.content.ObjectKey; 22 import org.jahia.exceptions.JahiaException; 23 import org.jahia.services.containers.ContentContainerList; 24 import org.jahia.services.fields.ContentPageField; 25 import org.jahia.services.usermanager.JahiaUser; 26 27 public class ContentObjectRevisions { 28 29 36 public ContentObjectRevisions(JahiaUser user, 37 EntryLoadRequest loadRequest, 38 String operationMode){ 39 } 40 41 53 public static SortedSet getRevisions(ContentObject contentObject, 54 JahiaUser user, 55 EntryLoadRequest loadRequest, 56 String operationMode, 57 boolean withChildsContent, 58 int pageLevel, 59 int containerListLevel) 60 throws JahiaException { 61 62 if ( contentObject == null ){ 63 return null; 64 } 65 66 SortedSet revisions = new TreeSet (); 67 SortedSet entryStates = 68 contentObject.getEntryStates(); 69 70 Iterator iterator = entryStates.iterator(); 71 while ( iterator.hasNext() ){ 72 ContentObjectEntryState entryState = 73 (ContentObjectEntryState)iterator.next(); 74 try { 75 RevisionEntry revisionEntry = 76 new RevisionEntry(entryState, 77 ObjectKey.getInstance(contentObject.getObjectKey().getType() 78 + "_" + contentObject.getObjectKey().getIDInType())); 79 revisions.add(revisionEntry); 80 } catch ( Throwable t ){ 81 throw new JahiaException("Exception creating revision entry ", 82 "Exception creating revision entry ", 83 JahiaException.DATA_ERROR, 84 JahiaException.DATA_ERROR,t); 85 } 86 } 87 if ( !withChildsContent ){ 88 return revisions; 89 } 90 91 ContentObject childObject = null; 92 ArrayList childs = 93 contentObject.getChilds(user, loadRequest); 94 iterator = childs.iterator(); 95 while( iterator.hasNext() ){ 96 childObject = (ContentObject)iterator.next(); 97 SortedSet childRevisions = null; 98 if ( childObject instanceof ContentPageField ){ 99 childRevisions = 100 getRevisions(childObject,user,loadRequest, 101 operationMode, 102 (pageLevel == -1 || pageLevel>0), 103 pageLevel-1, containerListLevel); 104 } else if ( childObject instanceof ContentContainerList ){ 105 childRevisions = 106 getRevisions(childObject,user,loadRequest, 107 operationMode, 108 (containerListLevel == -1 || containerListLevel>0), 109 pageLevel, containerListLevel-1); 110 } else { 111 childRevisions = 112 getRevisions(childObject,user,loadRequest, 113 operationMode, 114 withChildsContent, 115 pageLevel, containerListLevel); 116 } 117 if ( childRevisions != null ){ 118 revisions.addAll(childRevisions); 119 } 120 } 121 return revisions; 122 } 123 } 124 | Popular Tags |