Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/template/cache/CmsElementCache.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/template/cache/CmsElementCache.java,v $
3   * Date   : $Date: 2003/01/20 23:59:22 $
4   * Version: $Revision: 1.13 $
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 com.opencms.core.CmsException;
32  import com.opencms.file.CmsObject;
33  
34  import java.util.Hashtable;
35  import java.util.Vector;
36  
37  /**
38   * This is the starting class for OpenCms element cache. Element cache was implemented for
39   * performance issues. The idea is to create a flat hirarchie of elements that
40   * can be accessed fast and efficient for the frontend users in the online
41   * project.
42   *
43   * On publishing-time the data in the element cache area will be created or updated.
44   * All inefficiant XML-files are changed to the efficient element cache data
45   * structure. For createing the content no XML-parsing and DOM-accessing is
46   * neccessairy.
47   * @author Andreas Schouten
48   */
49  public class CmsElementCache {
50  
51      private CmsUriLocator m_uriLocator;
52  
53      private CmsElementLocator m_elementLocator;
54  
55      private int m_variantCachesize;
56  
57      public CmsElementCache(){
58          m_uriLocator = new CmsUriLocator(10000);
59          m_elementLocator = new CmsElementLocator(50000);
60          m_variantCachesize = 100;
61      }
62  
63      public CmsElementCache(int uriCachesize, int elementCachesize, int variantCachesize) {
64          m_uriLocator = new CmsUriLocator(uriCachesize);
65          m_elementLocator = new CmsElementLocator(elementCachesize);
66          if (variantCachesize < 2){
67              variantCachesize = 100;
68          }
69          m_variantCachesize = variantCachesize;
70      }
71  
72      public CmsUriLocator getUriLocator() {
73          return m_uriLocator;
74      }
75  
76      public CmsElementLocator getElementLocator() {
77          return m_elementLocator;
78      }
79  
80      /**
81       * returns the size of the variant cache for each element.
82       */
83      public int getVariantCachesize(){
84          return m_variantCachesize;
85      }
86  
87      /**
88       * Deletes all the content of the caches that depend on the changed resources
89       * after publishProject.
90       * @param changedResources A vector (of Strings) with the resources that have
91       *                          changed during publishing.
92       */
93      public void cleanupCache(Vector changedResources, Vector changedModuleRes){
94  
95          // chanchedResources have chanched, first we have to edit them
96          Vector resForUpdate = new Vector();
97          if(changedResources != null){
98              for(int i=0; i<changedResources.size(); i++){
99                  String current = (String)changedResources.elementAt(i);
100                 int rootIndex = current.indexOf("/", current.indexOf("/",1)+1);
101                 resForUpdate.add(current.substring(rootIndex));
102             }
103         }
104         m_uriLocator.deleteUris(resForUpdate);
105         m_elementLocator.cleanupElementCache(resForUpdate);
106 
107         // for the dependencies cache we use the original vectors
108         m_elementLocator.cleanupDependencies(changedResources);
109         m_elementLocator.cleanupDependencies(changedModuleRes);
110     }
111 
112     /**
113      * Clears the uri and the element cache compleatly.
114      * and the extern dependencies.
115      */
116     public void clearCache(){
117         m_elementLocator.clearCache();
118         m_uriLocator.clearCache();
119     }
120 
121     /**
122      * prints the cache info in the errorlog.
123      * @param int   1: print the info for the dependencies cache.
124      *              2:
125      */
126     public void printCacheInfo(int which){
127         if(which ==1){
128             // the dependencies cache
129             m_elementLocator.printCacheInfo(which);
130         }
131     }
132 
133     /**
134      * Gets the Information of max size and size for the uriCache and the
135      * element cache.
136      * @return a Vector whith informations about the size of the caches.
137      */
138     public Vector getCacheInfo(){
139         Vector uriInfo = m_uriLocator.getCacheInfo();
140         Vector elementInfo = m_elementLocator.getCacheInfo();
141         for (int i=0; i < elementInfo.size(); i++){
142             uriInfo.addElement(elementInfo.elementAt(i));
143         }
144         return uriInfo;
145     }
146 
147     public byte[] callCanonicalRoot(CmsObject cms, Hashtable parameters) throws CmsException {
148         CmsUri uri = m_uriLocator.get(new CmsUriDescriptor(cms.getRequestContext().getUri()));
149         return uri.callCanonicalRoot(this, cms, parameters);
150     }
151 
152 }