1 package org.jahia.services.version; 2 3 import java.util.HashSet ; 4 import java.util.Set ; 5 import java.util.Stack ; 6 7 import org.jahia.content.ObjectKey; 8 9 20 21 public class StateModificationContext { 22 23 private static org.apache.log4j.Logger logger = 24 org.apache.log4j.Logger.getLogger(StateModificationContext.class); 25 26 private Set languageCodes; 29 30 private boolean descendingInSubPages = false; 33 34 private Stack currentTreePath = new Stack (); 37 38 private Stack allLanguagesStack = new Stack (); 42 43 47 private StateModificationContext() { 48 allLanguagesStack.push(new Boolean (false)); 49 } 50 51 60 public StateModificationContext(ObjectKey startObject, Set languageCodes) { 61 this(); 62 currentTreePath.push(startObject); 63 if (languageCodes != null) { 64 this.languageCodes = languageCodes; 65 } else { 66 logger.debug("ActivationContext constructor passed null languageCode set !!!"); 67 this.languageCodes = new HashSet (); 68 } 69 } 70 71 84 public StateModificationContext(ObjectKey startObject, 85 Set languageCodes, boolean descendingInSubPages) { 86 this(startObject, languageCodes); 87 this.descendingInSubPages = descendingInSubPages; 88 } 89 90 96 public boolean isDescendingInSubPages() { 97 return descendingInSubPages; 98 } 99 100 108 public void setDescendingInSubPages(boolean descendingInSubPages) { 109 this.descendingInSubPages = descendingInSubPages; 110 } 111 112 119 public java.util.Stack getCurrentTreePath() { 120 return currentTreePath; 121 } 122 123 127 public void pushObjectID(ObjectKey objectID) { 128 currentTreePath.push(objectID); 129 } 130 131 137 public ObjectKey popObjectID() { 138 if (currentTreePath.size() > 1) { 139 return (ObjectKey) currentTreePath.pop(); 140 } else { 141 return (ObjectKey) currentTreePath.firstElement(); 142 } 143 } 144 145 public ObjectKey getStartObject() { 146 return (ObjectKey) currentTreePath.firstElement(); 147 } 148 149 156 public boolean isObjectIDInPath(ObjectKey objectID) { 157 return currentTreePath.contains(objectID); 158 } 159 160 public Set getLanguageCodes() { 161 return languageCodes; 162 } 163 164 public String toString() { 165 StringBuffer result = new StringBuffer (); 166 result.append("stateModifContext=["); 167 result.append("descendingInSubPages="); 168 result.append(isDescendingInSubPages()); 169 result.append(",currentTreePath="); 170 result.append(currentTreePath.toString()); 171 result.append(",languageCodes="); 172 result.append(languageCodes.toString()); 173 result.append("]"); 174 return result.toString(); 175 } 176 177 public boolean isAllLanguages() { 178 Boolean firstElement = (Boolean ) allLanguagesStack.peek(); 179 return firstElement.booleanValue(); 180 } 181 182 189 public void pushAllLanguages(boolean allLanguages) { 190 if (allLanguages) { 191 logger.debug("Warning : all languages for content object will be "+ 192 "deleted from here down !"); 193 } 194 this.allLanguagesStack.push(new Boolean (allLanguages)); 195 } 196 197 public boolean popAllLanguages() { 198 Boolean removedElement = (Boolean ) allLanguagesStack.pop(); 199 return removedElement.booleanValue(); 200 } 201 202 } | Popular Tags |