KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/template/cache/CmsElementDefinitionCollection.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 import java.util.Vector JavaDoc;
34
35 /**
36  * Used to collect a set of element definitions.
37  * Two CmsElementDefinitionCollections can be merged using the join constructor.
38  *
39  * @author Alexander Lucas
40  *
41  * @deprecated Will not be supported past the OpenCms 6 release.
42  */

43 public class CmsElementDefinitionCollection {
44
45     /** Hashtable for storing all definitions */
46     private Hashtable JavaDoc m_eldefs = new Hashtable JavaDoc();
47
48     /** Default constructor */
49     public CmsElementDefinitionCollection() {
50     }
51
52     /**
53      * Join cunstructor.
54      * Two CmsElementDefinitionCollections can be merged using this constructor.
55      * If a definition is defined in both source collections
56      * the single parts of this definitions will be merged.
57      * If a <em>part</em> of a definition is defined twice, the collection
58      * primary will be preferred.
59      * @param primary Source CmsElementDefinitionCollection
60      * @param secondary Source CmsElementDefinitionCollection
61      */

62     public CmsElementDefinitionCollection(CmsElementDefinitionCollection primary, CmsElementDefinitionCollection secondary) {
63         Vector JavaDoc allKeys = new Vector JavaDoc();
64         Enumeration JavaDoc keys1 = primary.m_eldefs.keys();
65         Enumeration JavaDoc keys2 = secondary.m_eldefs.keys();
66         while(keys1.hasMoreElements()) {
67             allKeys.addElement(keys1.nextElement());
68         }
69         while(keys2.hasMoreElements()) {
70             Object JavaDoc o = keys2.nextElement();
71             if(!allKeys.contains(o)) {
72                 allKeys.addElement(o);
73             }
74         }
75         Enumeration JavaDoc loop = allKeys.elements();
76         while(loop.hasMoreElements()) {
77             String JavaDoc currentKey = (String JavaDoc)loop.nextElement();
78             CmsElementDefinition def1 = (CmsElementDefinition)primary.m_eldefs.get(currentKey);
79             CmsElementDefinition def2 = (CmsElementDefinition)secondary.m_eldefs.get(currentKey);
80             m_eldefs.put(currentKey, new CmsElementDefinition(def1, def2));
81         }
82     }
83
84     /**
85      * Add a definition to the collection.
86      * @param def CmsElementDefinition that should be added
87      */

88     public void add(CmsElementDefinition def) {
89         m_eldefs.put(def.getName(), def);
90     }
91
92     /**
93      * Geta definition from the collection.
94      * @param name Name of the element definition requested
95      * @return CmsElementDefinition for <code>name</code> or <code>null</code>, if not defined.
96      */

97     public CmsElementDefinition get(String JavaDoc name) {
98         return (CmsElementDefinition)m_eldefs.get(name);
99     }
100
101     /**
102      * @return a Enumeration with the element names
103      */

104     public Enumeration JavaDoc getAllElementNames(){
105         return m_eldefs.keys();
106     }
107
108     /**
109      * Get a string representation of this collection.
110      * @return String representation.
111      */

112     public String JavaDoc toString() {
113         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
114         result.append("-----------------------------------------------------------------\n");
115         result.append("Element definition dump: \n");
116         Enumeration JavaDoc keys = m_eldefs.keys();
117         while(keys.hasMoreElements()) {
118             String JavaDoc name = (String JavaDoc)keys.nextElement();
119             CmsElementDefinition current = (CmsElementDefinition)m_eldefs.get(name);
120             result.append(current.toString() + "\n");
121         }
122         result.append("-----------------------------------------------------------------\n");
123         return result.toString();
124     }
125 }
Popular Tags