1 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 ; 41 import java.util.Collections ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 45 import org.apache.commons.digester.Digester; 46 47 import org.dom4j.Element; 48 49 58 public class CmsModuleConfiguration extends A_CmsXmlConfiguration implements I_CmsXmlConfiguration { 59 60 61 public static final String CONFIGURATION_DTD_NAME = "opencms-modules.dtd"; 62 63 64 public static final String DEFAULT_XML_FILE_NAME = "opencms-modules.xml"; 65 66 67 public static final String N_MODULES = "modules"; 68 69 70 private CmsModuleManager m_moduleManager; 71 72 73 private List m_modules; 74 75 78 public CmsModuleConfiguration() { 79 80 setXmlFileName(DEFAULT_XML_FILE_NAME); 81 m_modules = new ArrayList (); 82 if (CmsLog.INIT.isInfoEnabled()) { 83 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_MODULE_CONFIG_INIT_0)); 84 } 85 } 86 87 90 public void addXmlDigesterRules(Digester digester) { 91 92 digester.addCallMethod("*/" + N_MODULES, "initializeFinished"); 94 95 CmsModuleXmlHandler.addXmlDigesterRules(digester); 97 } 98 99 102 public Element generateXml(Element parent) { 103 104 List modules; 105 if (OpenCms.getRunLevel() >= OpenCms.RUNLEVEL_3_SHELL_ACCESS) { 106 modules = new ArrayList (); 107 Iterator names = OpenCms.getModuleManager().getModuleNames().iterator(); 108 while (names.hasNext()) { 109 CmsModule module = OpenCms.getModuleManager().getModule((String )names.next()); 110 if (module != null) { 111 modules.add(module); 112 } 113 } 114 Collections.sort(modules); 115 } else { 116 modules = m_modules; 118 } 119 120 Element modulesNode = parent.addElement(N_MODULES); 122 123 for (int i = 0; i < modules.size(); i++) { 124 CmsModule module = (CmsModule)modules.get(i); 126 Element moduleNode = CmsModuleXmlHandler.generateXml(module); 127 modulesNode.add(moduleNode); 128 } 129 130 return modulesNode; 132 } 133 134 137 public String getDtdFilename() { 138 139 return CONFIGURATION_DTD_NAME; 140 } 141 142 147 public CmsModuleManager getModuleManager() { 148 149 return m_moduleManager; 150 } 151 152 155 public void initializeFinished() { 156 157 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 169 public void setModule(CmsModuleXmlHandler moduleHandler) { 170 171 m_modules.add(moduleHandler.getModule()); 173 } 174 } | Popular Tags |