1 package org.jahia.content; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.Stack ; 6 7 import org.jahia.exceptions.JahiaException; 8 import org.jahia.services.fields.ContentPageField; 9 import org.jahia.services.usermanager.JahiaUser; 10 import org.jahia.services.version.EntryLoadRequest; 11 12 21 22 public class ContentTree { 23 24 private ContentObject rootContentObject; 25 26 private Stack contentTreeStatusStack = new Stack (); 28 29 34 public ContentTree(ContentObject aRootContentObject) { 35 36 this.rootContentObject = aRootContentObject; 37 } 38 39 44 public ContentObject getRootContentObject(){ 45 return this.rootContentObject; 46 } 47 48 53 public void iterate(ContentTreeVisitorInterface visitor) 54 throws JahiaException { 55 this.contentTreeStatusStack = new Stack (); 56 iterate(this.rootContentObject,visitor,0); 57 } 58 59 70 public ArrayList getContentChilds(ContentObject contentObject, 71 JahiaUser user, 72 EntryLoadRequest loadRequest, 73 String operationMode) 74 throws JahiaException { 75 ArrayList childs 76 = contentObject.getChilds(user, loadRequest); 77 return childs; 78 } 79 80 85 public Stack getContentTreeStatusStack(){ 86 return this.contentTreeStatusStack; 87 } 88 89 97 private void iterate(ContentObject contentObject, 98 ContentTreeVisitorInterface visitor, 99 int currentPageLevel) 100 throws JahiaException { 101 102 int descendingPageLevel = visitor.getDescendingPageLevel(); 103 104 ContentTreeStatusInterface contentTreeStatus = 105 visitor.getContentTreeStatus(contentObject,currentPageLevel); 106 107 this.contentTreeStatusStack.push(contentTreeStatus); 108 109 if ( descendingPageLevel != -1 110 && currentPageLevel>descendingPageLevel ){ 111 112 visitor.processLastContentPageField(contentObject, currentPageLevel); 114 } else { 116 visitor.processContentObjectBeforeChilds(contentObject, 118 currentPageLevel); 119 120 if (visitor.withChildsContent() 122 && contentTreeStatus.continueWithChilds()) { 123 ArrayList childs = visitor.getChilds(contentObject, 124 currentPageLevel); 125 Iterator childsIterator = childs.iterator(); 126 ContentObject childContentObject; 127 while (childsIterator.hasNext() 128 && contentTreeStatus.continueWithChilds()) { 129 childContentObject = (ContentObject) childsIterator.next(); 130 if (childContentObject instanceof ContentPageField) { 131 iterate(childContentObject, visitor, 132 currentPageLevel + 1); 133 } 134 else { 135 iterate(childContentObject, visitor, currentPageLevel); 136 } 137 } 138 } 139 if (contentTreeStatus.continueAfterChilds()) { 140 visitor.processContentObjectAfterChilds(contentObject, 141 currentPageLevel); 142 } else { 143 visitor.stopProcessContentObjectAfterChilds(contentObject, 144 currentPageLevel); 145 } 146 } 147 this.contentTreeStatusStack.pop(); 149 } 150 } 151 | Popular Tags |