Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/template/cache/CmsElementDefinitionCollection.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/template/cache/CmsElementDefinitionCollection.java,v $
3   * Date   : $Date: 2003/01/20 23:59:22 $
4   * Version: $Revision: 1.7 $
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;
32  import java.util.Hashtable;
33  import java.util.Vector;
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 <alexander.lucas@framfab.de>
40   */
41  public class CmsElementDefinitionCollection {
42  
43      /** Hashtable for storing all definitions */
44      private Hashtable m_eldefs = new Hashtable();
45  
46      /** Default constructor */
47      public CmsElementDefinitionCollection() {
48      }
49  
50      /**
51       * Join cunstructor.
52       * Two CmsElementDefinitionCollections can be merged using this constructor.
53       * If a definition is defined in both source collections
54       * the single parts of this definitions will be merged.
55       * If a <em>part</em> of a definition is defined twice, the collection
56       * primary will be preferred.
57       * @param primary Source CmsElementDefinitionCollection
58       * @param secondary Source CmsElementDefinitionCollection
59       */
60      public CmsElementDefinitionCollection(CmsElementDefinitionCollection primary, CmsElementDefinitionCollection secondary) {
61          Vector allKeys = new Vector();
62          Enumeration keys1 = primary.m_eldefs.keys();
63          Enumeration keys2 = secondary.m_eldefs.keys();
64          while(keys1.hasMoreElements()) {
65              allKeys.addElement(keys1.nextElement());
66          }
67          while(keys2.hasMoreElements()) {
68              Object o = keys2.nextElement();
69              if(!allKeys.contains(o)) {
70                  allKeys.addElement(o);
71              }
72          }
73          Enumeration loop = allKeys.elements();
74          while(loop.hasMoreElements()) {
75              String currentKey = (String)loop.nextElement();
76              CmsElementDefinition def1 = (CmsElementDefinition)primary.m_eldefs.get(currentKey);
77              CmsElementDefinition def2 = (CmsElementDefinition)secondary.m_eldefs.get(currentKey);
78              m_eldefs.put(currentKey, new CmsElementDefinition(def1, def2));
79          }
80      }
81  
82      /**
83       * Add a definition to the collection.
84       * @param def CmsElementDefinition that should be added
85       */
86      public void add(CmsElementDefinition def) {
87          m_eldefs.put(def.getName(), def);
88      }
89  
90      /**
91       * Geta definition from the collection.
92       * @param name Name of the element definition requested
93       * @return CmsElementDefinition for <code>name</code> or <code>null</code>, if not defined.
94       */
95      public CmsElementDefinition get(String name) {
96          return (CmsElementDefinition)m_eldefs.get(name);
97      }
98  
99      /**
100      * @return a Enumeration with the element names
101      */
102     public Enumeration getAllElementNames(){
103         return m_eldefs.keys();
104     }
105 
106     /**
107      * Get a string representation of this collection.
108      * @return String representation.
109      */
110     public String toString() {
111         StringBuffer result = new StringBuffer();
112         result.append("-----------------------------------------------------------------\n");
113         result.append("Element definition dump: \n");
114         Enumeration keys = m_eldefs.keys();
115         while(keys.hasMoreElements()) {
116             String name = (String)keys.nextElement();
117             CmsElementDefinition current = (CmsElementDefinition)m_eldefs.get(name);
118             result.append(current.toString() + "\n");
119         }
120         result.append("-----------------------------------------------------------------\n");
121         return result.toString();
122     }
123 }