KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > configuration > CmsModuleConfiguration


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsModuleConfiguration.java,v $
3  * Date : $Date: 2006/03/27 14:52:46 $
4  * Version: $Revision: 1.13 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
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 Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.configuration;
33
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.OpenCms;
36 import org.opencms.module.CmsModule;
37 import org.opencms.module.CmsModuleManager;
38 import org.opencms.module.CmsModuleXmlHandler;
39
40 import java.util.ArrayList JavaDoc;
41 import java.util.Collections JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.List JavaDoc;
44
45 import org.apache.commons.digester.Digester;
46
47 import org.dom4j.Element;
48
49 /**
50  * VFS master configuration class.<p>
51  *
52  * @author Alexander Kandzior
53  *
54  * @version $Revision: 1.13 $
55  *
56  * @since 6.0.0
57  */

58 public class CmsModuleConfiguration extends A_CmsXmlConfiguration implements I_CmsXmlConfiguration {
59
60     /** The name of the DTD for this configuration. */
61     public static final String JavaDoc CONFIGURATION_DTD_NAME = "opencms-modules.dtd";
62
63     /** The name of the default XML file for this configuration. */
64     public static final String JavaDoc DEFAULT_XML_FILE_NAME = "opencms-modules.xml";
65
66     /** The node name for the modules top node. */
67     public static final String JavaDoc N_MODULES = "modules";
68
69     /** The module manager generated from the configuration. */
70     private CmsModuleManager m_moduleManager;
71
72     /** The configured list of module descriptions. */
73     private List JavaDoc m_modules;
74
75     /**
76      * Public constructor, will be called by configuration manager.<p>
77      */

78     public CmsModuleConfiguration() {
79
80         setXmlFileName(DEFAULT_XML_FILE_NAME);
81         m_modules = new ArrayList JavaDoc();
82         if (CmsLog.INIT.isInfoEnabled()) {
83             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_MODULE_CONFIG_INIT_0));
84         }
85     }
86
87     /**
88      * @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester.Digester)
89      */

90     public void addXmlDigesterRules(Digester digester) {
91
92         // add finish rule
93
digester.addCallMethod("*/" + N_MODULES, "initializeFinished");
94
95         // add the module rules for the module digester
96
CmsModuleXmlHandler.addXmlDigesterRules(digester);
97     }
98
99     /**
100      * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
101      */

102     public Element generateXml(Element parent) {
103
104         List JavaDoc modules;
105         if (OpenCms.getRunLevel() >= OpenCms.RUNLEVEL_3_SHELL_ACCESS) {
106             modules = new ArrayList JavaDoc();
107             Iterator JavaDoc names = OpenCms.getModuleManager().getModuleNames().iterator();
108             while (names.hasNext()) {
109                 CmsModule module = OpenCms.getModuleManager().getModule((String JavaDoc)names.next());
110                 if (module != null) {
111                     modules.add(module);
112                 }
113             }
114             Collections.sort(modules);
115         } else {
116             // simple unit tests
117
modules = m_modules;
118         }
119
120         // generate modules node and subnodes
121
Element modulesNode = parent.addElement(N_MODULES);
122
123         for (int i = 0; i < modules.size(); i++) {
124             // append all configured modules
125
CmsModule module = (CmsModule)modules.get(i);
126             Element moduleNode = CmsModuleXmlHandler.generateXml(module);
127             modulesNode.add(moduleNode);
128         }
129
130         // return the modules node
131
return modulesNode;
132     }
133
134     /**
135      * @see org.opencms.configuration.I_CmsXmlConfiguration#getDtdFilename()
136      */

137     public String JavaDoc getDtdFilename() {
138
139         return CONFIGURATION_DTD_NAME;
140     }
141
142     /**
143      * Returns the configured module manager.<p>
144      *
145      * @return the configured module manager
146      */

147     public CmsModuleManager getModuleManager() {
148
149         return m_moduleManager;
150     }
151
152     /**
153      * Will be called when configuration of this object is finished.<p>
154      */

155     public void initializeFinished() {
156
157         // create the module manager with the configured modules
158
m_moduleManager = new CmsModuleManager(m_modules);
159         if (CmsLog.INIT.isInfoEnabled()) {
160             CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_MODULE_CONFIG_FINISHED_0));
161         }
162     }
163
164     /**
165      * Adds a new module to the list of configured modules.<p>
166      *
167      * @param moduleHandler contains the imported module
168      */

169     public void setModule(CmsModuleXmlHandler moduleHandler) {
170
171         // add the module info to the list of configured modules
172
m_modules.add(moduleHandler.getModule());
173     }
174 }
Popular Tags