KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/cache/CmsElementDump.java,v $
3 * Date : $Date: 2005/05/17 13:47:27 $
4 * Version: $Revision: 1.1 $
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.CmsException;
33
34 import com.opencms.template.A_CmsCacheDirectives;
35 import com.opencms.template.CmsCacheDirectives;
36 import com.opencms.template.I_CmsTemplate;
37
38 import java.util.Hashtable JavaDoc;
39
40 /**
41  * An instance of CmsElementDump represents an requestable dump element in the OpenCms
42  * element cache area. It contains all informations to generate the content of this
43  * element. It also stores the variants of once generated content to speed up
44  * performance.
45  *
46  * This special case of an element doesn't point to other depending elements.
47  * It may only be used for dumping plain text or binary data.
48  *
49  * @author Alexander Lucas
50  *
51  * @deprecated Will not be supported past the OpenCms 6 release.
52  */

53 public class CmsElementDump extends A_CmsElement {
54
55     /**
56      * Constructor for an element with the given class and template name.
57      */

58     public CmsElementDump(String JavaDoc className, String JavaDoc templateName, CmsCacheDirectives cd, int variantCachesize) {
59         init(className, templateName, cd, variantCachesize);
60     }
61
62     /**
63      * A construcor which creates an element with the given element
64      * definitions.
65      * @param name the name of this element-definition.
66      * @param className the classname of this element-definition.
67      * @param cd Cache directives for this element
68      * @param defs CmsElementDefinitionCollection for this element.
69      * @param variantCachesize The size of the variant cache.
70      */

71     public CmsElementDump(String JavaDoc className, String JavaDoc templateName, CmsCacheDirectives cd, CmsElementDefinitionCollection defs, int variantCachesize) {
72         init(className, templateName, cd, defs, variantCachesize);
73     }
74
75     /**
76      * Get the content of this element.
77      * @param elementCache Entry point for the element cache
78      * @param cms CmsObject for accessing system resources
79      * @param elDefs Definitions of this element's subelements
80      * @param parameters All parameters of this request
81      * @param methodParameter not used here.
82      * @return Byte array with the processed content of this element.
83      * @throws CmsException
84      */

85     public byte[] getContent(CmsElementCache elementCache, CmsObject cms, CmsElementDefinitionCollection elDefs, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc methodParameter) throws CmsException {
86         byte[] result = null;
87
88         // get template class
89
I_CmsTemplate templateClass = getTemplateClass(cms, m_className);
90
91         // Collect cache directives from subtemplates
92
A_CmsCacheDirectives cd = getCacheDirectives();
93
94         CmsElementVariant variant = null;
95
96         Object JavaDoc cacheKey = cd.getCacheKey(cms, parameters);
97
98         // In classic mode, now the cache-control headers of the response
99
// are setted. What shall we do here???
100
// Now check, if there is a variant of this element in the cache.
101

102         if(cd.isInternalCacheable()) {
103             checkReadAccess(cms);
104             variant = getVariant(cacheKey);
105         }
106
107         if(variant != null) {
108             result = resolveVariant(cms, variant, elementCache, elDefs, parameters);
109         } else {
110             // This element was not found in the variant cache.
111
// We have to generate it.
112
try {
113                 result = templateClass.getContent(cms, m_templateName, elementName, parameters);
114                 if(cd.isInternalCacheable()) {
115                     variant = new CmsElementVariant();
116                     variant.add(result);
117                     addVariant(cacheKey, variant);
118                 }
119
120             }
121             catch(CmsException e) {
122                 // Clear cache and do logging here
123
throw e;
124             }
125         }
126         return result;
127     }
128 }
Popular Tags