| 1 10 package org.mmbase.util.xml; 11 12 import java.util.*; 13 import org.w3c.dom.*; 14 import org.mmbase.util.XMLEntityResolver; 15 16 23 public class ApplicationReader extends DocumentReader { 24 25 26 public static final String PUBLIC_ID_APPLICATION_1_0 = "-//MMBase//DTD application config 1.0//EN"; 27 private static final String PUBLIC_ID_APPLICATION_1_0_FAULT = "-//MMBase/DTD application config 1.0//EN"; 28 29 public static final String PUBLIC_ID_APPLICATION_1_1 = "-//MMBase//DTD application config 1.1//EN"; 30 31 32 public static final String DTD_APPLICATION_1_0 = "application_1_0.dtd"; 33 34 public static final String DTD_APPLICATION_1_1 = "application_1_1.dtd"; 35 36 37 public static final String PUBLIC_ID_APPLICATION = PUBLIC_ID_APPLICATION_1_1; 38 39 public static final String DTD_APPLICATION = DTD_APPLICATION_1_1; 40 41 46 public static void registerPublicIDs() { 47 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 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 is) { 58 super(is, ApplicationReader.class); 59 root=getElementByPath("application"); 60 } 61 62 65 public ApplicationReader(Document doc) { 66 super(doc); 67 } 68 69 72 public String getName() { 73 return getElementAttributeValue(root,"name"); 74 } 75 76 79 public int getVersion() { 80 String ver=getElementAttributeValue(root,"version"); 81 if (!ver.equals("")) 82 try { 83 return Integer.parseInt(ver); 84 } catch (Exception e) { 85 return -1; 86 } 87 else 88 return -1; 89 } 90 91 94 public boolean hasAutoDeploy() { 95 return getElementAttributeValue(root,"auto-deploy").equals("true"); 96 } 97 98 101 public String getMaintainer() { 102 return getElementAttributeValue(root,"maintainer"); 103 } 104 105 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 attribute) { 125 String val=n.getAttribute(attribute); 126 if (!val.equals("")) { 127 bset.put(attribute,val); 128 } 129 } 130 131 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 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 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 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 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 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 239 public String getInstallNotice() { 240 return getElementValue("application.install-notice"); 241 } 242 243 244 247 public String getDescription() { 248 return getElementValue("application.description"); 249 } 250 251 } 252 | Popular Tags |