KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > xml > ModuleReader


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9  */

10 package org.mmbase.util.xml;
11
12 import java.util.*;
13 import org.w3c.dom.Document JavaDoc;
14 import org.w3c.dom.Element JavaDoc;
15 import org.xml.sax.InputSource JavaDoc;
16
17 import org.mmbase.util.XMLEntityResolver;
18
19 /**
20  * @javadoc
21  * @since MMBase-1.8
22  * @author Daniel Ockeloen
23  * @author Pierre van Rooden
24  * @version $Id: ModuleReader.java,v 1.3 2005/10/13 12:06:58 michiel Exp $
25  */

26 public class ModuleReader extends DocumentReader {
27
28     /** Public ID of the Module DTD version 1.0 */
29     public static final String JavaDoc PUBLIC_ID_MODULE_1_0 = "-//MMBase//DTD module config 1.0//EN";
30     private static final String JavaDoc PUBLIC_ID_MODULE_1_0_FAULT = "-//MMBase/DTD module config 1.0//EN";
31     private static final String JavaDoc PUBLIC_ID_MODULE_1_0_FAULT2 = "-//MMBase/ DTD module config 1.0//EN";
32     /** Public ID of the most recent Module DTD */
33     public static final String JavaDoc PUBLIC_ID_MODULE = PUBLIC_ID_MODULE_1_0;
34
35     /** DTD resource filename of the most recent Module DTD */
36     public static final String JavaDoc DTD_MODULE_1_0 = "module_1_0.dtd";
37     /** DTD resource filename of the most recent Module DTD */
38     public static final String JavaDoc DTD_MODULE = DTD_MODULE_1_0;
39
40     /**
41      * Register the Public Ids for DTDs used by ModuleReader
42      * This method is called by XMLEntityResolver.
43      * @since MMBase-1.7
44      */

45     public static void registerPublicIDs() {
46         XMLEntityResolver.registerPublicID(PUBLIC_ID_MODULE_1_0, DTD_MODULE_1_0, ModuleReader.class);
47         // legacy public IDs (wrong, don't use these)
48
XMLEntityResolver.registerPublicID(PUBLIC_ID_MODULE_1_0_FAULT, DTD_MODULE_1_0, ModuleReader.class);
49         XMLEntityResolver.registerPublicID(PUBLIC_ID_MODULE_1_0_FAULT2, DTD_MODULE_1_0, ModuleReader.class);
50     }
51
52     public ModuleReader(InputSource JavaDoc is) {
53         super(is, ModuleReader.class);
54     }
55
56     /**
57      * @since MMBase-1.8
58      */

59     public ModuleReader(Document JavaDoc doc) {
60         super(doc);
61     }
62
63     /**
64      * Get the status of this module
65      */

66     public String JavaDoc getStatus() {
67         Element JavaDoc e = getElementByPath("module.status");
68         String JavaDoc s = getElementValue(e);
69         return s.equals("") ? "active" : s;
70     }
71
72     /**
73      * Get the version of this module
74      */

75     public int getVersion() {
76         Element JavaDoc e = getElementByPath("module");
77         String JavaDoc version = getElementAttributeValue(e, "version");
78         int n = 0;
79         if (version == null) {
80             return n;
81         } else {
82             try {
83                 n = Integer.parseInt(version);
84             } catch (Exception JavaDoc f) {
85                 n = 0;
86             }
87             return n;
88         }
89     }
90
91     /**
92      * Get the maintainer of this module
93      */

94     public String JavaDoc getMaintainer() {
95         Element JavaDoc e = getElementByPath("module");
96         String JavaDoc tmp = getElementAttributeValue(e, "maintainer");
97         if (tmp != null && !tmp.equals("")) {
98             return tmp;
99         } else {
100             return "mmbase.org";
101         }
102     }
103
104     /**
105      * The name of the class which is implementing this Module.
106      */

107     public String JavaDoc getClassName() {
108         Element JavaDoc e = getElementByPath("module.class");
109         if (e != null) return getElementValue(e);
110         // legacy fall back
111
e = getElementByPath("module.classfile");
112         return getElementValue(e);
113
114     }
115
116     /**
117      * get the optional resource url for the module
118      * @return the url of the resource or null if no url was defined
119      **/

120     public String JavaDoc getURLString(){
121         Element JavaDoc e = getElementByPath("module.url");
122         if (e != null){
123             return getElementValue(e);
124         }
125         return null;
126     }
127
128     /**
129      * Get the properties of this builder
130      */

131     public Map getProperties() {
132         Map map = new LinkedHashMap();
133         Element JavaDoc e = getElementByPath("module.properties");
134         if (e != null) {
135             for (Iterator iter = getChildElements(e, "property"); iter.hasNext();) {
136                 Element JavaDoc p = (Element JavaDoc) iter.next();
137                 String JavaDoc name = getElementAttributeValue(p, "name");
138                 String JavaDoc value = getElementValue(p);
139                 map.put(name, value);
140             }
141         }
142         return map;
143     }
144
145 }
146
Popular Tags