KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsAdminElementCache


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminElementCache.java,v $
3 * Date : $Date: 2005/05/31 15:51:19 $
4 * Version: $Revision: 1.2 $
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.workplace;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.main.CmsException;
33 import org.opencms.main.CmsLog;
34
35 import com.opencms.legacy.CmsXmlTemplateLoader;
36 import com.opencms.template.cache.CmsElementCache;
37
38 import java.util.Hashtable JavaDoc;
39 import java.util.Vector JavaDoc;
40 /**
41  * Template class for displaying OpenCms workplace elementCache administration.
42  * <P>
43  *
44  * @author Hanjo Riege
45  * @version $Revision: 1.2 $ $Date: 2005/05/31 15:51:19 $
46  *
47  * @deprecated Will not be supported past the OpenCms 6 release.
48  */

49 public class CmsAdminElementCache extends CmsWorkplaceDefault {
50
51     /**
52      * Gets the content of a defined section in a given template file and its subtemplates
53      * with the given parameters.
54      *
55      * @see #getContent(CmsObject, String, String, Hashtable, String)
56      * @param cms CmsObject Object for accessing system resources.
57      * @param templateFile Filename of the template file.
58      * @param elementName Element name of this template in our parent template.
59      * @param parameters Hashtable with all template class parameters.
60      * @param templateSelector template section that should be processed.
61      */

62
63     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
64             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
65         if(C_DEBUG && CmsLog.getLog(this).isDebugEnabled()) {
66             CmsLog.getLog(this).debug("Getting content of element "
67                             + ((elementName == null) ? "<root>" : elementName));
68             CmsLog.getLog(this).debug("Template file is: " + templateFile);
69             CmsLog.getLog(this).debug("Selected template section is: "
70                             + ((templateSelector == null) ? "<default>" : templateSelector));
71         }
72         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
73
74         // need the element cache
75
CmsElementCache cache = CmsXmlTemplateLoader.getOnlineElementCache();
76         // any debug action?
77
String JavaDoc info = (String JavaDoc)parameters.get("info");
78         if(info != null && "dep_out".equals(info)){
79             // print out the pependencies cache
80
cache.printCacheInfo(1);
81         }
82         // get the parameter
83
String JavaDoc action = (String JavaDoc)parameters.get("action");
84         if((action == null) || ("".equals(action))){
85             // first call, fill the process tags
86
Vector JavaDoc cacheInfo = cache.getCacheInfo();
87             xmlTemplateDocument.setData("urisize", ((Integer JavaDoc)cacheInfo.elementAt(1)).toString() + " | " +
88                                                     ((Integer JavaDoc)cacheInfo.elementAt(0)).toString());
89             xmlTemplateDocument.setData("elementsize", ((Integer JavaDoc)cacheInfo.elementAt(3)).toString() + " | " +
90                                                        ((Integer JavaDoc)cacheInfo.elementAt(2)).toString());
91         }else{
92             // action! clear the cache
93
cache.clearCache();
94             templateSelector = "done";
95         }
96
97         // Now load the template file and start the processing
98
return startProcessing(cms, xmlTemplateDocument, elementName, parameters,
99                 templateSelector);
100     }
101
102     /**
103      * Checks if the current user is <strong>administrator</strong> and the element cache is activ.
104      * <P>
105      * This method is used by workplace icons to decide whether the icon should
106      * be activated or not. Icons will use this method if the attribute <code>method="isElementcacheAdmin"</code>
107      * is defined in the <code>&lt;ICON&gt;</code> tag.
108      *
109      * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
110      * @param lang reference to the currently valid language file <em>(not used here)</em>.
111      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
112      * @return <code>true</code> if the current project is the online project, <code>false</code> otherwise.
113      * @throws CmsException if there were errors while accessing project data.
114      */

115     public Boolean JavaDoc isElementcacheAdmin(CmsObject cms, CmsXmlLanguageFile lang, Hashtable JavaDoc parameters) throws CmsException {
116         return new Boolean JavaDoc(cms.isAdmin() && (CmsXmlTemplateLoader.getElementCache() != null));
117     }
118
119     /**
120      * Indicates if the results of this class are cacheable.
121      *
122      * @param cms CmsObject Object for accessing system resources
123      * @param templateFile Filename of the template file
124      * @param elementName Element name of this template in our parent template.
125      * @param parameters Hashtable with all template class parameters.
126      * @param templateSelector template section that should be processed.
127      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
128      */

129     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
130             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
131         return false;
132     }
133
134 }
Popular Tags