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 import org.jahia.utils.JahiaConsole; 9 10 23 24 public class ContentFieldXRefManager { 25 26 private static ContentFieldXRefManager theObject = null; 27 28 protected ContentFieldXRefManager() { 29 JahiaConsole.println("FieldXRefManager", 30 "Initializing..."); 31 } 32 33 39 public static synchronized ContentFieldXRefManager getInstance() 40 { 41 if (theObject == null) { 42 theObject = new ContentFieldXRefManager(); 43 } 44 return theObject; 45 } 47 55 public Set getAbsoluteFieldPageIDs(int fieldID) 56 throws JahiaException { 57 58 ContentFieldKey fieldKey = new ContentFieldKey(fieldID); 59 60 Set objectRefs = CrossReferenceManager.getInstance().getObjectXRefs(fieldKey); 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 JahiaConsole.println("FieldXRefManager.getAbsoluteFieldPageIDs", 76 "Expected page type in cross reference list, ignoring value... "); 77 } 78 } else { 79 JahiaConsole.println("FieldXRefManager.getAbsoluteFieldPageIDs", 80 "Invalid key object in cross reference list, ignoring... "); 81 } 82 } 83 return pageIDs; 84 } 85 86 95 public Set getAbsoluteFieldsFromPageID(int pageID) 96 throws JahiaException { 97 98 ContentPageKey pageKey = new ContentPageKey(pageID); 99 100 Set objectRefs = CrossReferenceManager.getInstance().getReverseObjectXRefs(pageKey); 101 Set fieldKeys = new TreeSet (); 102 if (objectRefs == null) { 103 return fieldKeys; 104 } 105 Iterator objectRefIter = objectRefs.iterator(); 106 while (objectRefIter.hasNext()) { 107 Object source = objectRefIter.next(); 108 if (source instanceof ObjectKey) { 109 ObjectKey sourceKey = (ObjectKey) source; 110 if (ContentFieldKey.FIELD_TYPE.equals(sourceKey.getType())) { 111 ContentFieldKey fieldKey = (ContentFieldKey) sourceKey; 112 fieldKeys.add(fieldKey); 113 } else { 114 } 117 } else { 118 JahiaConsole.println("FieldXRefManager.getAbsoluteFieldPageIDs", 119 "Invalid key object in cross reference list, ignoring... "); 120 } 121 } 122 return fieldKeys; 123 124 } 125 126 135 public void setAbsoluteFieldPageID(int fieldID, 136 int referencePageID) 137 throws JahiaException { 138 ContentFieldKey fieldKey = new ContentFieldKey(fieldID); 139 ContentPageKey pageKey = new ContentPageKey(referencePageID); 140 CrossReferenceManager.getInstance().setObjectXRef(fieldKey, pageKey); 141 } 142 143 149 public void removeAbsoluteField(int fieldID) 150 throws JahiaException { 151 ContentFieldKey fieldKey = new ContentFieldKey(fieldID); 152 CrossReferenceManager.getInstance().removeObjectXRefs(fieldKey); 153 } 154 155 163 public void removeAbsoluteFieldPageID(int fieldID, int referencePageID) 164 throws JahiaException { 165 ContentFieldKey fieldKey = new ContentFieldKey(fieldID); 166 ContentPageKey pageKey = new ContentPageKey(referencePageID); 167 CrossReferenceManager.getInstance().removeObjectXRef(fieldKey, pageKey); 168 } 169 170 } | Popular Tags |