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 ContentPageXRefManager { 25 26 private static final String NAME_SEPARATOR = "_"; 27 28 private static ContentPageXRefManager theObject = null; 29 30 protected ContentPageXRefManager() { 31 JahiaConsole.println("PageXRefManager", 32 "Initializing..."); 33 } 34 35 41 public static synchronized ContentPageXRefManager getInstance() 42 { 43 if (theObject == null) { 44 theObject = new ContentPageXRefManager(); 45 } 46 return theObject; 47 } 49 58 public Set getPageIDs(int targetPageID) 59 throws JahiaException { 60 61 65 ContentPageKey pageKey = new ContentPageKey(targetPageID); 66 67 Set objectRefs = CrossReferenceManager.getInstance().getObjectXRefs(pageKey); 68 Set pageIDs = new TreeSet (); 69 if (objectRefs == null) { 70 JahiaConsole.println("PageXRefManager.getPageIDs", 71 "No references found for page " + targetPageID); 72 return pageIDs; 73 } 74 Iterator objectRefIter = objectRefs.iterator(); 75 while (objectRefIter.hasNext()) { 76 Object ref = objectRefIter.next(); 77 if (ref instanceof ObjectKey) { 78 ObjectKey refKey = (ObjectKey) ref; 79 if (ContentPageKey.PAGE_TYPE.equals(refKey.getType())) { 80 ContentPageKey pageRefKey = (ContentPageKey) refKey; 81 Integer pageID = new Integer (pageRefKey.getPageID()); 82 pageIDs.add(pageID); 83 } else { 84 JahiaConsole.println("PageXRefManager.getPageIDs", 85 "Expected page type in cross reference list, ignoring value... "); 86 } 87 } else { 88 JahiaConsole.println("PageXRefManager.getPageIDs", 89 "Invalid key object in cross reference list, ignoring... "); 90 } 91 } 92 return pageIDs; 93 } 94 95 103 public void setPageID(int targetPageID, int refPageID) 104 throws JahiaException { 105 110 ContentPageKey pageKey = new ContentPageKey(targetPageID); 114 ContentPageKey refPageKey = new ContentPageKey(refPageID); 115 CrossReferenceManager.getInstance().setObjectXRef(pageKey, refPageKey); 116 } 117 118 124 public void removePage(int targetPageID) 125 throws JahiaException { 126 ContentPageKey pageKey = new ContentPageKey(targetPageID); 127 CrossReferenceManager.getInstance().removeObjectXRefs(pageKey); 128 } 129 130 139 public void removePagePageID(int targetPageID, int referencePageID) 140 throws JahiaException { 141 ContentPageKey pageKey = new ContentPageKey(targetPageID); 142 ContentPageKey referencePageKey = new ContentPageKey(referencePageID); 143 CrossReferenceManager.getInstance().removeObjectXRef(pageKey, referencePageKey); 144 } 145 146 } | Popular Tags |