KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > version > ContentObjectRevisions


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.version;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.SortedSet JavaDoc;
18 import java.util.TreeSet JavaDoc;
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     /**
30      *
31      * @param rootObject
32      * @param user
33      * @param loadRequest
34      * @param operationMode
35      */

36     public ContentObjectRevisions(JahiaUser user,
37                                   EntryLoadRequest loadRequest,
38                                   String JavaDoc operationMode){
39     }
40
41     /**
42      *
43      * @param contentObject
44      * @param user
45      * @param loadRequest
46      * @param operationMode
47      * @param withChildsContent
48      * @param pageLevel
49      * @param containerListLevel
50      * @return
51      * @throws JahiaException
52      */

53     public static SortedSet JavaDoc getRevisions(ContentObject contentObject,
54                                      JahiaUser user,
55                                      EntryLoadRequest loadRequest,
56                                      String JavaDoc 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 JavaDoc revisions = new TreeSet JavaDoc();
67         SortedSet JavaDoc entryStates =
68                 contentObject.getEntryStates();
69
70         Iterator JavaDoc 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 JavaDoc 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 JavaDoc childs =
93                 contentObject.getChilds(user, loadRequest);
94         iterator = childs.iterator();
95         while( iterator.hasNext() ){
96             childObject = (ContentObject)iterator.next();
97             SortedSet JavaDoc 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