001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.util.xml;
011:
012: import java.util.*;
013: import org.w3c.dom.*;
014: import org.mmbase.util.XMLEntityResolver;
015:
016: /**
017: * @javadoc
018: * @author Case Roole
019: * @author Rico Jansen
020: * @author Pierre van Rooden
021: * @version $Id: ApplicationReader.java,v 1.4 2007/02/11 19:21:12 nklasens Exp $
022: */
023: public class ApplicationReader extends DocumentReader {
024:
025: /** Public ID of the Application DTD version 1.0 */
026: public static final String PUBLIC_ID_APPLICATION_1_0 = "-//MMBase//DTD application config 1.0//EN";
027: private static final String PUBLIC_ID_APPLICATION_1_0_FAULT = "-//MMBase/DTD application config 1.0//EN";
028: /** Public ID of the Application DTD version 1.1 */
029: public static final String PUBLIC_ID_APPLICATION_1_1 = "-//MMBase//DTD application config 1.1//EN";
030:
031: /** DTD resource filename of the Application DTD version 1.0 */
032: public static final String DTD_APPLICATION_1_0 = "application_1_0.dtd";
033: /** DTD resource filename of the Application DTD version 1.1 */
034: public static final String DTD_APPLICATION_1_1 = "application_1_1.dtd";
035:
036: /** Public ID of the most recent Application DTD */
037: public static final String PUBLIC_ID_APPLICATION = PUBLIC_ID_APPLICATION_1_1;
038: /** DTD resource filename of the most Application DTD */
039: public static final String DTD_APPLICATION = DTD_APPLICATION_1_1;
040:
041: /**
042: * Register the Public Ids for DTDs used by ApplicationReader
043: * This method is called by XMLEntityResolve
044: * @since MMBase-1.7
045: */
046: public static void registerPublicIDs() {
047: // various builder dtd versions
048: XMLEntityResolver.registerPublicID(PUBLIC_ID_APPLICATION_1_0,
049: DTD_APPLICATION_1_0, ApplicationReader.class);
050: XMLEntityResolver.registerPublicID(PUBLIC_ID_APPLICATION_1_1,
051: DTD_APPLICATION_1_1, ApplicationReader.class);
052:
053: // legacy public IDs (wrong, don't use these)
054: XMLEntityResolver.registerPublicID(
055: PUBLIC_ID_APPLICATION_1_0_FAULT, DTD_APPLICATION_1_0,
056: ApplicationReader.class);
057: }
058:
059: private Element root;
060:
061: public ApplicationReader(org.xml.sax.InputSource is) {
062: super (is, ApplicationReader.class);
063: root = getElementByPath("application");
064: }
065:
066: /**
067: * @since MMBase-1.8
068: */
069: public ApplicationReader(Document doc) {
070: super (doc);
071: }
072:
073: /**
074: * Get the name of this application
075: */
076: public String getName() {
077: return getElementAttributeValue(root, "name");
078: }
079:
080: /**
081: * Get the version of this application
082: */
083: public int getVersion() {
084: String ver = getElementAttributeValue(root, "version");
085: if (!ver.equals(""))
086: try {
087: return Integer.parseInt(ver);
088: } catch (Exception e) {
089: return -1;
090: }
091: else
092: return -1;
093: }
094:
095: /**
096: * Get the auto-deploy value of this application
097: */
098: public boolean hasAutoDeploy() {
099: return getElementAttributeValue(root, "auto-deploy").equals(
100: "true");
101: }
102:
103: /**
104: * Get the maintainer of this application
105: */
106: public String getMaintainer() {
107: return getElementAttributeValue(root, "maintainer");
108: }
109:
110: /**
111: * Get the applicationlist required by this application
112: * @since MMBase-1.7
113: */
114: public List<Map<String, String>> getRequirements() {
115: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
116: for (Element n3 : getChildElements("application.requirements",
117: "requires")) {
118: Map<String, String> bset = new HashMap<String, String>();
119: bset.put("name", getElementAttributeValue(n3, "name"));
120: addAttribute(bset, n3, "maintainer");
121: addAttribute(bset, n3, "version");
122: addAttribute(bset, n3, "type");
123: results.add(bset);
124: }
125: return results;
126: }
127:
128: private void addAttribute(Map<String, String> bset, Element n,
129: String attribute) {
130: String val = n.getAttribute(attribute);
131: if (!val.equals("")) {
132: bset.put(attribute, val);
133: }
134: }
135:
136: /**
137: * Get the Builders needed for this application
138: */
139: public List<Map<String, String>> getNeededBuilders() {
140: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
141: for (Element n3 : getChildElements(
142: "application.neededbuilderlist", "builder")) {
143: Map<String, String> bset = new HashMap<String, String>();
144: bset.put("name", getElementValue(n3));
145: addAttribute(bset, n3, "maintainer");
146: addAttribute(bset, n3, "version");
147: results.add(bset);
148: }
149: return results;
150: }
151:
152: /**
153: * Get the RelDefs needed for this application
154: */
155: public List<Map<String, String>> getNeededRelDefs() {
156: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
157: for (Element n3 : getChildElements(
158: "application.neededreldeflist", "reldef")) {
159: Map<String, String> bset = new HashMap<String, String>();
160: addAttribute(bset, n3, "source");
161: addAttribute(bset, n3, "target");
162: addAttribute(bset, n3, "direction");
163: addAttribute(bset, n3, "guisourcename");
164: addAttribute(bset, n3, "guitargetname");
165: addAttribute(bset, n3, "builder");
166: results.add(bset);
167: }
168: return results;
169: }
170:
171: /**
172: * Get allowed relations for this application
173: */
174: public List<Map<String, String>> getAllowedRelations() {
175: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
176: for (Element n3 : getChildElements(
177: "application.allowedrelationlist", "relation")) {
178: Map<String, String> bset = new HashMap<String, String>();
179: addAttribute(bset, n3, "from");
180: addAttribute(bset, n3, "to");
181: addAttribute(bset, n3, "type");
182: results.add(bset);
183: }
184: return results;
185: }
186:
187: /**
188: * Get datasources attached to this application
189: */
190: public List<Map<String, String>> getDataSources() {
191: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
192: for (Element n3 : getChildElements(
193: "application.datasourcelist", "datasource")) {
194: Map<String, String> bset = new HashMap<String, String>();
195: addAttribute(bset, n3, "path");
196: addAttribute(bset, n3, "builder");
197: results.add(bset);
198: }
199: return results;
200: }
201:
202: /**
203: * Get relationsources attached to this application
204: */
205: public List<Map<String, String>> getRelationSources() {
206: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
207: for (Element n3 : getChildElements(
208: "application.relationsourcelist", "relationsource")) {
209: Map<String, String> bset = new HashMap<String, String>();
210: addAttribute(bset, n3, "path");
211: addAttribute(bset, n3, "builder");
212: results.add(bset);
213: }
214: return results;
215: }
216:
217: /**
218: * contextsources attached to this application
219: */
220: public List<Map<String, String>> getContextSources() {
221: List<Map<String, String>> results = new ArrayList<Map<String, String>>();
222: for (Element n3 : getChildElements(
223: "application.contextsourcelist", "contextsource")) {
224: Map<String, String> bset = new HashMap<String, String>();
225: addAttribute(bset, n3, "path");
226: addAttribute(bset, n3, "type");
227: addAttribute(bset, n3, "goal");
228: results.add(bset);
229: }
230: return results;
231: }
232:
233: /**
234: * Get the installation notices for this application
235: */
236: public String getInstallNotice() {
237: return getElementValue("application.install-notice");
238: }
239:
240: /**
241: * Get the description for this application
242: */
243: public String getDescription() {
244: return getElementValue("application.description");
245: }
246:
247: }
|