1 package org.jahia.content; 2 3 import java.util.Iterator ; 4 import java.util.Set ; 5 import java.util.TreeSet ; 6 7 import org.jahia.exceptions.JahiaException; 8 9 22 23 public class ContentContainerListsXRefManager { 24 25 private static org.apache.log4j.Logger logger = 26 org.apache.log4j.Logger.getLogger(ContentContainerListsXRefManager.class); 27 28 private static ContentContainerListsXRefManager theObject = null; 29 30 protected ContentContainerListsXRefManager() { 31 logger.debug("Initializing..."); 32 } 33 34 40 public static synchronized ContentContainerListsXRefManager getInstance() 41 { 42 if (theObject == null) { 43 theObject = new ContentContainerListsXRefManager(); 44 } 45 return theObject; 46 } 48 56 public Set getAbsoluteContainerListPageIDs(int containerListID) 57 throws JahiaException { 58 ContentContainerListKey containerListKey = new ContentContainerListKey(containerListID); 59 60 Set objectRefs = CrossReferenceManager.getInstance().getObjectXRefs(containerListKey); 61 Set pageIDs = new TreeSet (); 62 if (objectRefs == null) { 63 return pageIDs; 64 } 65 Iterator objectRefIter = objectRefs.iterator(); 66 while (objectRefIter.hasNext()) { 67 Object ref = objectRefIter.next(); 68 if (ref instanceof ObjectKey) { 69 ObjectKey refKey = (ObjectKey) ref; 70 if (ContentPageKey.PAGE_TYPE.equals(refKey.getType())) { 71 ContentPageKey pageRefKey = (ContentPageKey) refKey; 72 Integer pageID = new Integer (pageRefKey.getPageID()); 73 pageIDs.add(pageID); 74 } else { 75 logger.debug("Expected page type in cross reference list, ignoring value... "); 76 } 77 } else { 78 logger.debug("Invalid key object in cross reference list, ignoring... "); 79 } 80 } 81 return pageIDs; 82 } 83 84 93 public Set getAbsoluteContainerListsFromPageID(int pageID) 94 throws JahiaException { 95 96 ContentPageKey pageKey = new ContentPageKey(pageID); 97 98 Set objectRefs = CrossReferenceManager.getInstance().getReverseObjectXRefs(pageKey); 99 Set containerListKeys = new TreeSet (); 100 if (objectRefs == null) { 101 return containerListKeys; 102 } 103 Iterator objectRefIter = objectRefs.iterator(); 104 while (objectRefIter.hasNext()) { 105 Object source = objectRefIter.next(); 106 if (source instanceof ObjectKey) { 107 ObjectKey sourceKey = (ObjectKey) source; 108 if (ContentContainerListKey.CONTAINERLIST_TYPE.equals(sourceKey.getType())) { 109 ContentContainerListKey containerListKey = (ContentContainerListKey) sourceKey; 110 containerListKeys.add(containerListKey); 111 } else { 112 logger.debug("Expected page type in cross reference list, ignoring value... "); 113 } 114 } else { 115 logger.debug("Invalid key object in cross reference list, ignoring... "); 116 } 117 } 118 return containerListKeys; 119 120 } 121 122 130 public void setAbsoluteContainerListPageID(int containerListID, 131 int referencePageID) 132 throws JahiaException { 133 ContentContainerListKey containerListKey = new ContentContainerListKey(containerListID); 134 ContentPageKey pageKey = new ContentPageKey(referencePageID); 135 CrossReferenceManager.getInstance().setObjectXRef(containerListKey, pageKey); 136 } 137 138 145 public void removeAbsoluteContainerList(int containerListID) 146 throws JahiaException { 147 ContentContainerListKey containerListKey = new ContentContainerListKey(containerListID); 148 CrossReferenceManager.getInstance().removeObjectXRefs(containerListKey); 149 } 150 151 160 public void removeAbsoluteContainerListPageID(int containerListID, 161 int referencePageID) 162 throws JahiaException { 163 ContentContainerListKey containerListKey = new ContentContainerListKey(containerListID); 164 ContentPageKey pageKey = new ContentPageKey(referencePageID); 165 CrossReferenceManager.getInstance().removeObjectXRef(containerListKey, pageKey); 166 } 167 168 } | Popular Tags |