KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
14 import org.mmbase.util.XMLEntityResolver;
15
16 /**
17  * @javadoc
18  * @author Case Roole
19  * @author Rico Jansen
20  * @author Pierre van Rooden
21  * @version $Id: ApplicationReader.java,v 1.2 2005/10/07 18:42:49 michiel Exp $
22  */

23 public class ApplicationReader extends DocumentReader {
24
25     /** Public ID of the Application DTD version 1.0 */
26     public static final String JavaDoc PUBLIC_ID_APPLICATION_1_0 = "-//MMBase//DTD application config 1.0//EN";
27     private static final String JavaDoc PUBLIC_ID_APPLICATION_1_0_FAULT = "-//MMBase/DTD application config 1.0//EN";
28     /** Public ID of the Application DTD version 1.1 */
29     public static final String JavaDoc PUBLIC_ID_APPLICATION_1_1 = "-//MMBase//DTD application config 1.1//EN";
30
31     /** DTD resource filename of the Application DTD version 1.0 */
32     public static final String JavaDoc DTD_APPLICATION_1_0 = "application_1_0.dtd";
33     /** DTD resource filename of the Application DTD version 1.1 */
34     public static final String JavaDoc DTD_APPLICATION_1_1 = "application_1_1.dtd";
35
36     /** Public ID of the most recent Application DTD */
37     public static final String JavaDoc PUBLIC_ID_APPLICATION = PUBLIC_ID_APPLICATION_1_1;
38     /** DTD resource filename of the most Application DTD */
39     public static final String JavaDoc DTD_APPLICATION = DTD_APPLICATION_1_1;
40
41     /**
42      * Register the Public Ids for DTDs used by ApplicationReader
43      * This method is called by XMLEntityResolve
44      * @since MMBase-1.7
45      */

46     public static void registerPublicIDs() {
47         // various builder dtd versions
48
XMLEntityResolver.registerPublicID(PUBLIC_ID_APPLICATION_1_0, DTD_APPLICATION_1_0, ApplicationReader.class);
49         XMLEntityResolver.registerPublicID(PUBLIC_ID_APPLICATION_1_1, DTD_APPLICATION_1_1, ApplicationReader.class);
50
51         // legacy public IDs (wrong, don't use these)
52
XMLEntityResolver.registerPublicID(PUBLIC_ID_APPLICATION_1_0_FAULT, DTD_APPLICATION_1_0, ApplicationReader.class);
53     }
54
55     private Element root;
56
57     public ApplicationReader(org.xml.sax.InputSource JavaDoc is) {
58         super(is, ApplicationReader.class);
59         root=getElementByPath("application");
60     }
61
62     /**
63      * @since MMBase-1.8
64      */

65     public ApplicationReader(Document doc) {
66         super(doc);
67     }
68
69     /**
70      * Get the name of this application
71      */

72     public String JavaDoc getName() {
73         return getElementAttributeValue(root,"name");
74     }
75
76     /**
77      * Get the version of this application
78      */

79     public int getVersion() {
80         String JavaDoc ver=getElementAttributeValue(root,"version");
81         if (!ver.equals(""))
82             try {
83                 return Integer.parseInt(ver);
84             } catch (Exception JavaDoc e) {
85                 return -1;
86             }
87         else
88             return -1;
89     }
90
91     /**
92      * Get the auto-deploy value of this application
93      */

94     public boolean hasAutoDeploy() {
95         return getElementAttributeValue(root,"auto-deploy").equals("true");
96     }
97
98     /**
99      * Get the maintainer of this application
100      */

101     public String JavaDoc getMaintainer() {
102         return getElementAttributeValue(root,"maintainer");
103     }
104
105     /**
106      * Get the applicationlist required by this application
107      * @since MMBase-1.7
108      */

109     public List getRequirements() {
110         List results=new Vector();
111         for(Iterator ns=getChildElements("application.requirements","requires");
112             ns.hasNext(); ) {
113             Element n3=(Element)ns.next();
114             Map bset=new HashMap();
115             bset.put("name",getElementAttributeValue(n3,"name"));
116             addAttribute(bset,n3,"maintainer");
117             addAttribute(bset,n3,"version");
118             addAttribute(bset,n3,"type");
119             results.add(bset);
120         }
121         return results;
122     }
123
124     private void addAttribute(Map bset, Element n, String JavaDoc attribute) {
125         String JavaDoc val=n.getAttribute(attribute);
126         if (!val.equals("")) {
127             bset.put(attribute,val);
128         }
129     }
130
131     /**
132      * Get the Builders needed for this application
133      */

134     public Vector getNeededBuilders() {
135         Vector results=new Vector();
136         for(Iterator ns=getChildElements("application.neededbuilderlist","builder");
137             ns.hasNext(); ) {
138             Element n3=(Element)ns.next();
139             Hashtable bset=new Hashtable();
140             bset.put("name",getElementValue(n3));
141             addAttribute(bset,n3,"maintainer");
142             addAttribute(bset,n3,"version");
143             results.addElement(bset);
144         }
145         return results;
146     }
147
148
149     /**
150      * Get the RelDefs needed for this application
151      */

152     public Vector getNeededRelDefs() {
153         Vector results=new Vector();
154         for(Iterator ns=getChildElements("application.neededreldeflist","reldef");
155             ns.hasNext(); ) {
156             Element n3=(Element)ns.next();
157             Hashtable bset=new Hashtable();
158             addAttribute(bset,n3,"source");
159             addAttribute(bset,n3,"target");
160             addAttribute(bset,n3,"direction");
161             addAttribute(bset,n3,"guisourcename");
162             addAttribute(bset,n3,"guitargetname");
163             addAttribute(bset,n3,"builder");
164             results.addElement(bset);
165         }
166         return results;
167     }
168
169
170     /**
171      * Get allowed relations for this application
172      */

173     public Vector getAllowedRelations() {
174         Vector results=new Vector();
175         for(Iterator ns=getChildElements("application.allowedrelationlist","relation");
176             ns.hasNext(); ) {
177             Element n3=(Element)ns.next();
178             Hashtable bset=new Hashtable();
179             addAttribute(bset,n3,"from");
180             addAttribute(bset,n3,"to");
181             addAttribute(bset,n3,"type");
182             results.addElement(bset);
183         }
184         return results;
185     }
186
187     /**
188      * Get datasources attached to this application
189      */

190     public List getDataSources() {
191         Vector results = new Vector();
192         for(Iterator ns=getChildElements("application.datasourcelist","datasource");
193             ns.hasNext(); ) {
194             Element n3=(Element)ns.next();
195             Hashtable bset=new Hashtable();
196             addAttribute(bset,n3,"path");
197             addAttribute(bset,n3,"builder");
198             results.addElement(bset);
199         }
200         return results;
201     }
202
203
204     /**
205      * Get relationsources attached to this application
206      */

207     public Vector getRelationSources() {
208         Vector results=new Vector();
209         for(Iterator ns=getChildElements("application.relationsourcelist","relationsource");
210             ns.hasNext(); ) {
211             Element n3=(Element)ns.next();
212             Hashtable bset=new Hashtable();
213             addAttribute(bset,n3,"path");
214             addAttribute(bset,n3,"builder");
215             results.addElement(bset);
216         }
217         return results;
218     }
219
220     /**
221      * contextsources attached to this application
222      */

223     public Vector getContextSources() {
224         Vector results=new Vector();
225         for(Iterator ns=getChildElements("application.contextsourcelist","contextsource"); ns.hasNext(); ) {
226             Element n3=(Element)ns.next();
227             Hashtable bset=new Hashtable();
228             addAttribute(bset,n3,"path");
229             addAttribute(bset,n3,"type");
230             addAttribute(bset,n3,"goal");
231             results.addElement(bset);
232         }
233         return results;
234     }
235
236     /**
237      * Get the installation notices for this application
238      */

239     public String JavaDoc getInstallNotice() {
240         return getElementValue("application.install-notice");
241     }
242
243
244     /**
245      * Get the description for this application
246      */

247     public String JavaDoc getDescription() {
248         return getElementValue("application.description");
249     }
250
251 }
252
Popular Tags