KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/cache/CmsElementVariant.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 java.io.UnsupportedEncodingException JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 /**
35  * An instance of CmsElementVariant stores a single cached variant for an
36  * element. This is the generated output (content) of an element. This cache
37  * stores all generated strings of this element and all links to other elements.
38  *
39  * @author Andreas Schouten
40  * @author Alexander Lucas
41  *
42  * @deprecated Will not be supported past the OpenCms 6 release.
43  */

44 public class CmsElementVariant {
45
46     /**
47      * The content of this variant. In this vector object of type String
48      * and of CmsElementLink can be stored.
49      */

50     Vector JavaDoc m_content;
51
52     /**
53      * The dependencies of this variant. In this vector objects of type String
54      * can be stored. These Strings are resources in the vfs or the cos. If one
55      * of the resources change this variant is decleared void.
56      */

57     Vector JavaDoc m_dependencies;
58
59     /**
60      * The date when this variant must be new generated. Only used if it is not 0.
61      */

62     private long m_nextTimeout = 0;
63
64     /**
65      * Marker that indicates if this variant was exported before.
66      */

67     private boolean m_exported = false;
68
69     /**
70      * Creates a new empty variant for an element.
71      */

72     public CmsElementVariant() {
73         m_content = new Vector JavaDoc();
74     }
75
76     /**
77      * Adds static content to this variant.
78      * @param staticContent - part of the variant. A peace static content of
79      * type string.
80      */

81     public void add(String JavaDoc staticContent) {
82         m_content.add(staticContent);
83     }
84
85     /**
86      * Adds static content to this variant.
87      * @param staticContent - part of the variant. A peace static content of
88      * type byte-array.
89      */

90     public void add(byte[] staticContent) {
91         m_content.add(staticContent);
92     }
93
94     /**
95      * Adds static content to this variant.
96      * @param staticContent - part of the variant. A peace static content of
97      * type byte-array.
98      */

99     public void add(byte[] staticContent, String JavaDoc encoding) {
100         try {
101             m_content.add(new String JavaDoc(staticContent, encoding));
102         } catch (UnsupportedEncodingException JavaDoc uee) {
103             m_content.add(staticContent);
104         }
105     }
106
107     /**
108      * Adds an element-link to this variant.
109      * @param elementLink - part of the variant. A link to another element.
110      */

111     public void add(CmsElementLink elementLink) {
112         m_content.add(elementLink);
113     }
114
115     /**
116      * Adds an method-link to this variant.
117      * @param methodLink - part of the variant. A link to an method.
118      */

119     public void add(CmsMethodLink methodLink) {
120         m_content.add(methodLink);
121     }
122
123     /**
124      * Get the number of objects in this variant.
125      */

126     public int size() {
127         return m_content.size();
128     }
129
130     /**
131      * Returns a peace of this variant. It can be of the type String, byte[] or
132      * CmsElementLink.
133      * @param i - the index to the vector of variant-pieces.
134      */

135     public Object JavaDoc get(int i) {
136         return m_content.get(i);
137     }
138
139     /**
140      * Sets the dependencies Vector for this Variant.
141      * @param dependencies A Vector of Strings.
142      */

143     public void setDependencies(Vector JavaDoc dependencies){
144         m_dependencies = dependencies;
145     }
146
147     /**
148      * Returns true if this variant was allready exported.
149      */

150     public boolean wasExported(){
151         return m_exported;
152     }
153
154     /**
155      * Sets the marker exported to true. Used when this variant is created in
156      * export modus.
157      */

158     public void setExported(){
159         m_exported = true;
160     }
161
162     /**
163      * Gets the dependencies Vector of this Variant.
164      *
165      * @return dependencies A Vector of Strings.
166      */

167     public Vector JavaDoc getDependencies(){
168         return m_dependencies;
169     }
170
171     /**
172      * Add a dependencies Vector to this.
173      *
174      * @param depVariant The Vector with the dependencies.
175      */

176     public void addDependencies(Vector JavaDoc depVariant){
177         if(m_dependencies == null){
178             m_dependencies = depVariant;
179         }else if (depVariant != null){
180             // both vectors not null, we have to merge
181
for (int i = 0; i < depVariant.size(); i++){
182                 m_dependencies.add(depVariant.elementAt(i));
183             }
184         }
185     }
186
187     /**
188      * Get a string representation of this variant.
189      * @return String representation.
190      */

191     public String JavaDoc toString() {
192         int len = m_content.size();
193         StringBuffer JavaDoc result = new StringBuffer JavaDoc("[CmsElementVariant] (" + len + ") :");
194         for(int i=0; i<len; i++) {
195             Object JavaDoc o = m_content.elementAt(i);
196             if(o instanceof byte[] || o instanceof String JavaDoc) {
197                 result.append("TXT");
198             } else {
199                 result.append("(");
200                 result.append(o.toString());
201                 result.append(")");
202             }
203             if(i < len-1) result.append("-");
204         }
205         return result.toString();
206     }
207
208     /**
209      * Merges the time when this variant has to be new generated.
210      * Sets it to the minimum of the old and the new value, whereby 0 don't count.
211      * @param timeout. The date as a long.
212      */

213     public void mergeNextTimeout(long timeout){
214
215         if(m_nextTimeout == 0 || timeout == 0){
216             if(m_nextTimeout < timeout){
217                 m_nextTimeout = timeout;
218             }
219         }else{
220             if(m_nextTimeout > timeout){
221                 m_nextTimeout = timeout;
222             }
223         }
224     }
225     /**
226      * Returns the time when this variant has to be new generated.
227      * @return timeout. The date as a long.
228      */

229     public long getNextTimeout(){
230         return m_nextTimeout;
231     }
232     /**
233      * Returns true if this variant has an expiration date.
234      */

235     public boolean isTimeCritical(){
236         return m_nextTimeout != 0;
237     }
238 }
Popular Tags