KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/cache/CmsElementDefinition.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.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33
34 /**
35  * An instance of CmsElementDefinitions represents an "pointer" to other
36  * elements. This pointers are stored in CmsElement's. An ElementDfinitions
37  * stores information about an element, like the name, className, templateName
38  * and parameters for the pointed element.
39  *
40  * @author Andreas Schouten
41  * @author Alexander Lucas
42  *
43  * @deprecated Will not be supported past the OpenCms 6 release.
44  */

45 public class CmsElementDefinition implements Cloneable JavaDoc {
46
47     /**
48      * The name of this element.
49      */

50     private String JavaDoc m_name;
51
52     /**
53      * The class-name of this element definition.
54      */

55     private String JavaDoc m_className;
56
57     /**
58      * The template-name of this element definition.
59      */

60     private String JavaDoc m_templateName;
61
62     /**
63      * The template-selector of this element definition.
64      */

65     private String JavaDoc m_templateSelector;
66
67     /**
68      * The parameters of this element.
69      */

70     private Hashtable JavaDoc m_elements;
71
72     /**
73      * The constructor with name, classname and templateName. This fits for some
74      * default - needs.
75      * @param name the name of this element-definition.
76      * @param className the classname of this element-definition.
77      * @param templateName the name of the template for this element-definition.
78      */

79     public CmsElementDefinition(String JavaDoc name, String JavaDoc className,
80         String JavaDoc templateName) {
81         m_name = name;
82         m_className = className;
83         m_templateName = templateName;
84     }
85
86     /**
87      * The constructor without any parameters. This fits for some needs.
88      * @param name the name of this element-definition.
89      * @param className the classname of this element-definition.
90      * @param templateName the name of the template.
91      * @param templateSelector the name of the template selector.
92      */

93     public CmsElementDefinition(String JavaDoc name, String JavaDoc className,
94         String JavaDoc templateName, String JavaDoc templateSelector) {
95         this(name, className, templateName);
96         m_templateSelector = templateSelector;
97     }
98
99     /**
100      * The complete constructor.
101      * @param name the name of this element-definition.
102      * @param className the classname of this element-definition.
103      * @param templateName the name of the template.
104      * @param templateSelector the name of the template selector.
105      * @param elements a hashtable with parameters.
106      */

107     public CmsElementDefinition(String JavaDoc name, String JavaDoc className,
108         String JavaDoc templateName, String JavaDoc templateSelector, Hashtable JavaDoc elements) {
109         this(name, className, templateName, templateSelector);
110         m_elements = elements;
111     }
112
113     /**
114      * Join constructor.
115      * @param primary Original object 1 with primary rights
116      * @param secondary Original object 2 with primary rights
117      */

118     public CmsElementDefinition(CmsElementDefinition primary, CmsElementDefinition secondary) {
119
120         m_elements = new Hashtable JavaDoc();
121
122         if(primary != null) {
123             m_name = primary.m_name;
124             m_className = primary.m_className;
125             m_templateName = primary.m_templateName;
126             m_templateSelector = primary.m_templateSelector;
127         }
128
129         if(secondary != null) {
130             if(m_name == null) {
131                 m_name = secondary.m_name;
132             }
133
134             if(m_className == null) {
135                 m_className = secondary.m_className;
136             }
137
138             if(m_templateName == null) {
139                 m_templateName = secondary.m_templateName;
140             }
141
142             if(m_templateSelector == null) {
143                 m_templateSelector = secondary.m_templateSelector;
144             }
145
146             m_elements.putAll(secondary.m_elements);
147         }
148
149         // Join parameters
150
if(primary != null) {
151             m_elements.putAll(primary.m_elements);
152         }
153     }
154
155     /**
156      * Get an element descriptor for looking up the
157      * corresponding element of this definition using the element locator
158      * @return Element descriptor for this definition
159      */

160     public CmsElementDescriptor getDescriptor() {
161         return new CmsElementDescriptor(m_className, m_templateName);
162     }
163
164     /**
165      * Get the name of the element defined.
166      * @return Name of the element.
167      */

168     public String JavaDoc getName() {
169         return m_name;
170     }
171
172     /**
173      * Get the templateSelector of the element defined.
174      * @return templateSelector of the element.
175      */

176     public String JavaDoc getTemplateSelector() {
177         return m_templateSelector;
178     }
179
180     /**
181      * Get the class name for the element defined.
182      * @return Class name for the element.
183      */

184     public String JavaDoc getClassName() {
185         return m_className;
186     }
187
188     /**
189      * Get the template name for the element defined.
190      * @return Template name for the element.
191      */

192     public String JavaDoc getTemplateName() {
193         return m_templateName;
194     }
195
196     /**
197      * This method adds the parameter from the elementDefinition to the
198      * requestParameters.
199      *
200      * @param The hashtable with the requestparameters.
201      */

202     public void joinParameters(Hashtable JavaDoc parameter){
203         Enumeration JavaDoc enu = m_elements.keys();
204         while(enu.hasMoreElements()){
205             String JavaDoc key = (String JavaDoc)enu.nextElement();
206             String JavaDoc value = (String JavaDoc)m_elements.get(key);
207             key = m_name + "." + key;
208             parameter.put(key, value);
209         }
210     }
211
212     /**
213      * Get a string representation of this definition.
214      * @return String representation.
215      */

216     public String JavaDoc toString() {
217         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
218
219         result.append("DEF: " + m_name + " ");
220
221         String JavaDoc part1 = m_className==null?"":m_className.substring(m_className.lastIndexOf(".") + 1);
222         String JavaDoc part2 = m_templateName==null?"":m_templateName.substring(m_templateName.lastIndexOf("/") + 1);
223         String JavaDoc part3 = m_templateSelector==null?"":m_templateSelector.substring(m_templateSelector.lastIndexOf("/") + 1);
224
225         result.append(part1 + "/" + part2 + "/" + part3 + " (");
226
227         if(m_elements != null) {
228             Enumeration JavaDoc params = m_elements.keys();
229             while(params.hasMoreElements()) {
230                 String JavaDoc name = (String JavaDoc)params.nextElement();
231                 String JavaDoc value = (String JavaDoc)m_elements.get(name);
232                 result.append(name + "=" + value);
233                 if(params.hasMoreElements()) result.append(", ");
234             }
235             result.append(")");
236         }
237         return result.toString();
238     }
239 }
Popular Tags