KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > content > ContentPageXRefManager


1 package org.jahia.content;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Set JavaDoc;
5 import java.util.TreeSet JavaDoc;
6
7 import org.jahia.exceptions.JahiaException;
8 import org.jahia.utils.JahiaConsole;
9
10 /**
11  * Title: Jahia
12  * Description: The purpose of this class is to provide a cross reference
13  * system between pages and pages, in order to know which pages reference
14  * a specific page . This is necessary since currently this information is defined
15  * only by template developpers and is useful for the HTML cache system when a
16  * container modification is done. This class allows lookups such as : "which
17  * pages access this page ?"
18  * Copyright: Copyright (c) 2002
19  * Company: Jahia Ltd
20  * @author Serge Huber
21  * @version 1.0
22  */

23
24 public class ContentPageXRefManager {
25
26     private static final String JavaDoc NAME_SEPARATOR = "_";
27
28     private static ContentPageXRefManager theObject = null;
29
30     protected ContentPageXRefManager() {
31         JahiaConsole.println("PageXRefManager",
32                              "Initializing...");
33     }
34
35     /**
36      * Returns a singleton instance of this service
37      * Note : this is a synchronized access method so it might affect performance
38      * if a lot of threads must access it simultaneously.
39      * @returns the singleton instance.
40      */

41     public static synchronized ContentPageXRefManager getInstance()
42     {
43         if (theObject == null) {
44             theObject = new ContentPageXRefManager();
45         }
46         return theObject;
47     } // end getInstance
48

49     /**
50      * Retrieves a list of pageIDs that contain references to a specific
51      * page
52      * @param targetPageID the target pageID for which to send xrefs.
53      * @returns a Set of Integers containing pageIDs that reference the target
54      * page.
55      * @throws JahiaException is thrown in case there was a problem
56      * communicating with the database that stores the link persistently
57      */

58     public Set JavaDoc getPageIDs(int targetPageID)
59         throws JahiaException {
60
61         /*
62         JahiaConsole.println("PageXRefManager.getPageIDs",
63                              "Getting page ids for page " + Integer.toString(targetPageID));
64         */

65         ContentPageKey pageKey = new ContentPageKey(targetPageID);
66
67         Set JavaDoc objectRefs = CrossReferenceManager.getInstance().getObjectXRefs(pageKey);
68         Set JavaDoc pageIDs = new TreeSet JavaDoc();
69         if (objectRefs == null) {
70             JahiaConsole.println("PageXRefManager.getPageIDs",
71                                  "No references found for page " + targetPageID);
72             return pageIDs;
73         }
74         Iterator JavaDoc objectRefIter = objectRefs.iterator();
75         while (objectRefIter.hasNext()) {
76             Object JavaDoc 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 JavaDoc pageID = new Integer JavaDoc(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     /**
96      * Adds or updates a cross reference between an target and
97      * a page reference
98      * @param targetPageID the target page ID for which to add a xref
99      * @param refPageID the page that has the xref to the target page
100      * @throws JahiaException is thrown in case there was a problem
101      * communicating with the database that stores the link persistently
102      */

103     public void setPageID(int targetPageID, int refPageID)
104     throws JahiaException {
105         /*
106         JahiaConsole.println("PageXRefManager.setPageID",
107                              "Target=" + Integer.toString(targetPageID) +
108                              ", refPageID=" + Integer.toString(refPageID));
109         */

110         //JahiaConsole.println("PageXRefManager","siteName =" + siteName);
111
//JahiaConsole.println("PageXRefManager","targetPageID =" + targetPageID);
112
//JahiaConsole.println("PageXRefManager","refPageID =" + refPageID);
113
ContentPageKey pageKey = new ContentPageKey(targetPageID);
114         ContentPageKey refPageKey = new ContentPageKey(refPageID);
115         CrossReferenceManager.getInstance().setObjectXRef(pageKey, refPageKey);
116     }
117
118     /**
119      * Removes all the cross references for a specified page
120      * @param targetPageID the target page ID for which to remove the xrefs
121      * @throws JahiaException is thrown in case there was a problem
122      * communicating with the database that stores the link persistently
123      */

124     public void removePage(int targetPageID)
125         throws JahiaException {
126         ContentPageKey pageKey = new ContentPageKey(targetPageID);
127         CrossReferenceManager.getInstance().removeObjectXRefs(pageKey);
128     }
129
130     /**
131      * Removes a specific page cross reference for a target page
132      * @param targetPageID the identifier for the page that is the target of
133      * the reference
134      * @param referencePageID the page identifier that is referencing the
135      * target page
136      * @throws JahiaException is thrown in case there was a problem
137      * communicating with the database that stores the link persistently
138      */

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