KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > legacy > CmsRegistry


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/legacy/CmsRegistry.java,v $
3  * Date : $Date: 2005/06/27 23:27:46 $
4  * Version: $Revision: 1.9 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9  * Copyright (C) 2002 Alkacon Software (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, 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 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 JavaDoc;
41 import java.io.FileInputStream JavaDoc;
42 import java.io.InputStream JavaDoc;
43 import java.util.Hashtable JavaDoc;
44
45 import org.w3c.dom.Document JavaDoc;
46 import org.w3c.dom.Element JavaDoc;
47 import org.w3c.dom.NodeList JavaDoc;
48
49 /**
50  * The OpenCms registry.<p>
51  *
52  * This registry contains information about the installed OpenCms modules,
53  * and also important other system information
54  * e.g. the mail server settings for the task management,
55  * the workplace views and other items.<p>
56  *
57  * @author Thomas Weckert (t.weckert@alkacon.com)
58  * @author Alexander Kandzior (a.kandzior@alkacon.com)
59  *
60  * @version $Revision: 1.9 $
61  *
62  * @deprecated The registry has been replaced by the new XML configuration.
63  */

64 public class CmsRegistry extends A_CmsXmlContent {
65
66     /** Id to identify that the version is not important .*/
67     public static final int C_ANY_VERSION = -1;
68     
69     /** The filename for this registry. */
70     private String JavaDoc m_regFileName;
71
72     /** The xml-document representing this registry. */
73     private Document JavaDoc m_xmlReg;
74     
75     private static CmsRegistry m_registry;
76
77     /**
78      * Returns the registry to read values from it.<p>
79      *
80      * @return the registry
81      */

82     public static CmsRegistry getInstance() {
83         if (m_registry == null) {
84             // initialize the (deprecated) XML registry
85
if (CmsLog.INIT.isInfoEnabled()) {
86                 CmsLog.INIT.info(". Initializing registry: starting");
87             }
88             String JavaDoc 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     /**
102      * Creates a new CmsRegistry that is initialized with the contents from the given filename.<p>
103      *
104      * @param regFileName the path to the registry file
105      * @throws CmsException in case somthing goes wrong
106      */

107     public CmsRegistry(String JavaDoc regFileName) throws CmsException {
108         super();
109         try {
110             // store the filename
111
m_regFileName = regFileName;
112
113             // get the file
114
File JavaDoc xmlFile = new File JavaDoc(m_regFileName);
115
116             // parse the registry-xmlfile and store it.
117
InputStream JavaDoc content = new FileInputStream JavaDoc(xmlFile);
118             m_xmlReg = parse(content);
119         } catch (Exception JavaDoc exc) {
120             throw new CmsLegacyException("couldn't init registry", CmsLegacyException.C_REGISTRY_ERROR, exc);
121         }
122     }
123
124     /**
125      * @see com.opencms.template.A_CmsXmlContent#getContentDescription()
126      */

127     public String JavaDoc getContentDescription() {
128         return "Registry";
129     }
130
131     /**
132      * Return the XML "system" node Element from the registry for further
133      * processing in another class.
134      * @return the system node.
135      */

136     public Element JavaDoc getSystemElement() {
137         return (Element JavaDoc)m_xmlReg.getElementsByTagName("system").item(0);
138     }
139
140     /**
141      * Returns a value for a system key.<p>
142      *
143      * E.g. <code>&lt;system&gt;&lt;mailserver&gt;mail.server.com&lt;/mailserver&gt;&lt;/system&gt;</code>
144      * can be requested via <code>getSystemValue("mailserver");</code> and returns "mail.server.com".<p>
145      *
146      * @param key the key of the system value
147      * @return the system value for that key
148      */

149     public String JavaDoc getSystemValue(String JavaDoc key) {
150         String JavaDoc retValue = null;
151         try {
152             Element JavaDoc systemElement = (Element JavaDoc)m_xmlReg.getElementsByTagName("system").item(0);
153             retValue = systemElement.getElementsByTagName(key).item(0).getFirstChild().getNodeValue();
154         } catch (Exception JavaDoc exc) {
155             // ignore the exception - registry is not wellformed
156
}
157         return retValue;
158     }
159
160     /**
161      * Returns a vector of values for a system key.<p>
162      *
163      * @param key the key of the system value
164      * @return the values for that system key
165      */

166     public Hashtable JavaDoc getSystemValues(String JavaDoc key) {
167         Hashtable JavaDoc retValue = new Hashtable JavaDoc();
168         try {
169                 
170             Element JavaDoc systemElement = (Element JavaDoc)m_xmlReg.getElementsByTagName("system").item(0);
171             NodeList JavaDoc list = systemElement.getElementsByTagName(key).item(0).getChildNodes();
172             for (int i = 0; i < list.getLength(); i++) {
173                 String JavaDoc regKey = list.item(i).getNodeName();
174                 String JavaDoc 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 JavaDoc exc) {
183             // ignore the exception - registry is not wellformed
184
}
185         return retValue;
186     }
187
188     /**
189      * Gets the expected tagname for the XML documents of this content type.<p>
190      *
191      * @return Expected XML tagname
192      */

193     public String JavaDoc getXmlDocumentTagName() {
194         return "registry";
195     }
196 }
197
198
Popular Tags