1 31 32 package com.opencms.legacy; 33 34 import org.opencms.main.CmsException; 35 import org.opencms.main.CmsLog; 36 import org.opencms.main.OpenCms; 37 38 import com.opencms.template.*; 39 40 import java.io.File ; 41 import java.io.FileInputStream ; 42 import java.io.InputStream ; 43 import java.util.Hashtable ; 44 45 import org.w3c.dom.Document ; 46 import org.w3c.dom.Element ; 47 import org.w3c.dom.NodeList ; 48 49 64 public class CmsRegistry extends A_CmsXmlContent { 65 66 67 public static final int C_ANY_VERSION = -1; 68 69 70 private String m_regFileName; 71 72 73 private Document m_xmlReg; 74 75 private static CmsRegistry m_registry; 76 77 82 public static CmsRegistry getInstance() { 83 if (m_registry == null) { 84 if (CmsLog.INIT.isInfoEnabled()) { 86 CmsLog.INIT.info(". Initializing registry: starting"); 87 } 88 String path = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf("config/registry.xml"); 89 try { 90 m_registry = new CmsRegistry(path); 91 if (CmsLog.INIT.isInfoEnabled()) { 92 CmsLog.INIT.info(". Initializing registry: finished"); 93 } 94 } catch (CmsException e) { 95 CmsLog.getLog(CmsRegistry.class).error("Unable to read registry.xml from path: '" + path + "'", e); 96 } 97 } 98 return m_registry; 99 } 100 101 107 public CmsRegistry(String regFileName) throws CmsException { 108 super(); 109 try { 110 m_regFileName = regFileName; 112 113 File xmlFile = new File (m_regFileName); 115 116 InputStream content = new FileInputStream (xmlFile); 118 m_xmlReg = parse(content); 119 } catch (Exception exc) { 120 throw new CmsLegacyException("couldn't init registry", CmsLegacyException.C_REGISTRY_ERROR, exc); 121 } 122 } 123 124 127 public String getContentDescription() { 128 return "Registry"; 129 } 130 131 136 public Element getSystemElement() { 137 return (Element )m_xmlReg.getElementsByTagName("system").item(0); 138 } 139 140 149 public String getSystemValue(String key) { 150 String retValue = null; 151 try { 152 Element systemElement = (Element )m_xmlReg.getElementsByTagName("system").item(0); 153 retValue = systemElement.getElementsByTagName(key).item(0).getFirstChild().getNodeValue(); 154 } catch (Exception exc) { 155 } 157 return retValue; 158 } 159 160 166 public Hashtable getSystemValues(String key) { 167 Hashtable retValue = new Hashtable (); 168 try { 169 170 Element systemElement = (Element )m_xmlReg.getElementsByTagName("system").item(0); 171 NodeList list = systemElement.getElementsByTagName(key).item(0).getChildNodes(); 172 for (int i = 0; i < list.getLength(); i++) { 173 String regKey = list.item(i).getNodeName(); 174 String regValue=null; 175 if (list.item(i).hasChildNodes()) { 176 regValue = list.item(i).getFirstChild().getNodeValue(); 177 } 178 if (regValue!=null) { 179 retValue.put(regKey, regValue); 180 } 181 } 182 } catch (Exception exc) { 183 } 185 return retValue; 186 } 187 188 193 public String getXmlDocumentTagName() { 194 return "registry"; 195 } 196 } 197 198
| Popular Tags
|