KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > template > cache > CmsElementCache


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/cache/CmsElementCache.java,v $
3 * Date : $Date: 2005/06/21 15:49:58 $
4 * Version: $Revision: 1.4 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.template.cache;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.main.CmsEvent;
33 import org.opencms.main.CmsException;
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.I_CmsEventListener;
36 import org.opencms.main.OpenCms;
37
38 import java.util.Hashtable JavaDoc;
39 import java.util.Vector JavaDoc;
40
41 /**
42  * This is the starting class for OpenCms element cache. Element cache was implemented for
43  * performance issues. The idea is to create a flat hirarchie of elements that
44  * can be accessed fast and efficient for the frontend users in the online
45  * project.
46  *
47  * On publishing-time the data in the element cache area will be created or updated.
48  * All inefficiant XML-files are changed to the efficient element cache data
49  * structure. For createing the content no XML-parsing and DOM-accessing is
50  * neccessairy.
51  * @author Andreas Schouten
52  *
53  * @deprecated Will not be supported past the OpenCms 6 release.
54  */

55 public class CmsElementCache extends Object JavaDoc implements I_CmsEventListener {
56
57     private CmsUriLocator m_uriLocator;
58
59     private CmsElementLocator m_elementLocator;
60
61     private int m_variantCachesize;
62
63     public CmsElementCache() {
64         this(10000, 50000, 100);
65     }
66
67     public CmsElementCache(int uriCachesize, int elementCachesize, int variantCachesize) {
68         m_uriLocator = new CmsUriLocator(uriCachesize);
69         m_elementLocator = new CmsElementLocator(elementCachesize);
70         if (variantCachesize < 2) {
71             variantCachesize = 100;
72         }
73         m_variantCachesize = variantCachesize;
74         
75         if (CmsLog.INIT.isInfoEnabled()) {
76             CmsLog.INIT.info(". Legacy element cache : Uri cache size = " + uriCachesize);
77             CmsLog.INIT.info(". Legacy element cache : Element cache size = " + elementCachesize);
78             CmsLog.INIT.info(". Legacy element cache : Variant cache size = " + variantCachesize);
79         }
80         
81         // add this class as an event handler to the Cms event listener
82
OpenCms.addCmsEventListener(this, new int[] {
83                 I_CmsEventListener.EVENT_PUBLISH_PROJECT,
84                 I_CmsEventListener.EVENT_CLEAR_CACHES,
85                 I_CmsEventListener.EVENT_CLEAR_ONLINE_CACHES,
86                 I_CmsEventListener.EVENT_CLEAR_OFFLINE_CACHES
87         });
88     }
89
90     public CmsUriLocator getUriLocator() {
91         return m_uriLocator;
92     }
93
94     public CmsElementLocator getElementLocator() {
95         return m_elementLocator;
96     }
97
98     /**
99      * returns the size of the variant cache for each element.
100      */

101     public int getVariantCachesize() {
102         return m_variantCachesize;
103     }
104
105     /**
106      * Deletes all the content of the caches that depend on the changed resources
107      * after publishProject.
108      * @param changedResources A vector (of Strings) with the resources that have
109      * changed during publishing.
110      */

111     public void cleanupCache(Vector JavaDoc changedResources, Vector JavaDoc changedModuleRes) {
112         // chanchedResources have chanched, first we have to edit them
113
Vector JavaDoc resForUpdate = new Vector JavaDoc();
114         if (changedResources != null) {
115             for (int i = 0; i < changedResources.size(); i++) {
116                 String JavaDoc current = (String JavaDoc) changedResources.elementAt(i);
117                 resForUpdate.add(current);
118                 resForUpdate.add(current + com.opencms.core.I_CmsConstants.C_XML_CONTROL_FILE_SUFFIX);
119             }
120         }
121         m_uriLocator.deleteUris(resForUpdate);
122         m_elementLocator.cleanupElementCache(resForUpdate);
123
124         // for the dependencies cache we use the original vectors
125
m_elementLocator.cleanupDependencies(changedResources);
126         m_elementLocator.cleanupDependencies(changedModuleRes);
127     }
128
129     /**
130      * Clears the uri and the element cache compleatly.
131      * and the extern dependencies.
132      */

133     public void clearCache() {
134         m_elementLocator.clearCache();
135         m_uriLocator.clearCache();
136     }
137
138     /**
139      * prints the cache info in the errorlog.
140      * @param int 1: print the info for the dependencies cache.
141      * 2:
142      */

143     public void printCacheInfo(int which) {
144         if (which == 1) {
145             // the dependencies cache
146
m_elementLocator.printCacheInfo(which);
147         }
148     }
149
150     /**
151      * Gets the Information of max size and size for the uriCache and the
152      * element cache.
153      * @return a Vector whith informations about the size of the caches.
154      */

155     public Vector JavaDoc getCacheInfo() {
156         Vector JavaDoc uriInfo = m_uriLocator.getCacheInfo();
157         Vector JavaDoc elementInfo = m_elementLocator.getCacheInfo();
158         for (int i = 0; i < elementInfo.size(); i++) {
159             uriInfo.addElement(elementInfo.elementAt(i));
160         }
161         return uriInfo;
162     }
163
164     public byte[] callCanonicalRoot(CmsObject cms, Hashtable JavaDoc parameters) throws CmsException {
165         CmsUri uri = m_uriLocator.get(new CmsUriDescriptor(cms.getRequestContext().getUri()));
166         return uri.callCanonicalRoot(this, cms, parameters);
167     }
168
169     public byte[] callCanonicalRoot(CmsObject cms, Hashtable JavaDoc parameters, String JavaDoc uriParam) throws CmsException {
170         CmsUri uri = m_uriLocator.get(new CmsUriDescriptor(uriParam));
171         return uri.callCanonicalRoot(this, cms, parameters);
172     }
173
174     /**
175      * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent)
176      */

177     public void cmsEvent(CmsEvent event) {
178         switch (event.getType()) {
179             case I_CmsEventListener.EVENT_PUBLISH_PROJECT :
180             case I_CmsEventListener.EVENT_CLEAR_CACHES :
181             case I_CmsEventListener.EVENT_CLEAR_ONLINE_CACHES:
182             case I_CmsEventListener.EVENT_CLEAR_OFFLINE_CACHES:
183                 clearCache();
184                 break;
185         }
186     }
187 }
Popular Tags