KickJava   Java API By Example, From Geeks To Geeks.

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


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
9 /**
10  * Title: Jahia
11  * Description: The purpose of this class is to provide a cross reference
12  * system between container and pages, in order to know which pages reference
13  * a container. This is necessary since currently this information is defined
14  * only by template developpers and is useful for the HTML cache system when a
15  * container modification is done. This class allows lookups such as : "which
16  * pages access this container via the absolute container reference system?"
17  * Copyright: Copyright (c) 2002
18  * Company: Jahia Ltd
19  * @author Serge Huber
20  * @version 1.0
21  */

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     /**
35      * Returns a singleton instance of this service
36      * Note : this is a synchronized access method so it might affect performance
37      * if a lot of threads must access it simultaneously.
38      * @returns the singleton instance.
39      */

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

48     /**
49      * Retrieves a list of pageIDs that contain references to a specific
50      * absolute container list.
51      * @param containerListID the identifier of the container list
52      * @returns a Set of Integers containing pageIDs
53      * @throws JahiaException in the case there was a problem retrieving the
54      * references from the database.
55      */

56     public Set JavaDoc getAbsoluteContainerListPageIDs(int containerListID)
57         throws JahiaException {
58         ContentContainerListKey containerListKey = new ContentContainerListKey(containerListID);
59
60         Set JavaDoc objectRefs = CrossReferenceManager.getInstance().getObjectXRefs(containerListKey);
61         Set JavaDoc pageIDs = new TreeSet JavaDoc();
62         if (objectRefs == null) {
63             return pageIDs;
64         }
65         Iterator JavaDoc objectRefIter = objectRefs.iterator();
66         while (objectRefIter.hasNext()) {
67             Object JavaDoc 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 JavaDoc pageID = new Integer JavaDoc(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     /**
85      * Retrieves a set of container list keys that are used on the page as
86      * absolute container list references.
87      * @param pageID the identifier of the page
88      * @return a Set containing ContainerListKey objects that identify the
89      * containers lists that are used on the page.
90      * @throws JahiaException in case there was a problem retrieving the
91      * references from the database
92      */

93     public Set JavaDoc getAbsoluteContainerListsFromPageID(int pageID)
94         throws JahiaException {
95
96         ContentPageKey pageKey = new ContentPageKey(pageID);
97
98         Set JavaDoc objectRefs = CrossReferenceManager.getInstance().getReverseObjectXRefs(pageKey);
99         Set JavaDoc containerListKeys = new TreeSet JavaDoc();
100         if (objectRefs == null) {
101             return containerListKeys;
102         }
103         Iterator JavaDoc objectRefIter = objectRefs.iterator();
104         while (objectRefIter.hasNext()) {
105             Object JavaDoc 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     /**
123      * Adds or updates a cross reference between an absolute container list and
124      * a page
125      * @param containerListID the identifier of the container list
126      * @param referencePageID the page identifier
127      * @throws JahiaException in the case there was a problem storing the
128      * references in the database
129      */

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     /**
139      * Removes all the cross references for a specified absolute container list
140      * @param containerListID the identifier of the container list
141      * the containerList
142      * @throws JahiaException is thrown in case there was a problem
143      * communicating with the database that stores the link persistently
144      */

145     public void removeAbsoluteContainerList(int containerListID)
146         throws JahiaException {
147         ContentContainerListKey containerListKey = new ContentContainerListKey(containerListID);
148         CrossReferenceManager.getInstance().removeObjectXRefs(containerListKey);
149     }
150
151     /**
152      * Removes a specific page cross reference for an absolute container list
153      * @param containerListID the identifier for the container list addressed
154      * absolutely
155      * @param referencePageID the page identifier that is referencing the
156      * container list absolutely
157      * @throws JahiaException is thrown in case there was a problem
158      * communicating with the database that stores the link persistently
159      */

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