1 6 7 package org.roller.config.runtime; 8 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 import org.jdom.Document; 14 import org.jdom.Element; 15 import org.jdom.JDOMException; 16 import org.jdom.input.SAXBuilder; 17 18 19 25 public class RuntimeConfigDefsParser { 26 27 28 public RuntimeConfigDefsParser() {} 29 30 31 35 public RuntimeConfigDefs unmarshall(InputStream instream) 36 throws IOException , JDOMException { 37 38 RuntimeConfigDefs configs = new RuntimeConfigDefs(); 39 40 SAXBuilder builder = new SAXBuilder(); 41 Document doc = builder.build(instream); 42 43 Element root = doc.getRootElement(); 44 List configdefs = root.getChildren("config-def"); 45 Iterator iter = configdefs.iterator(); 46 while (iter.hasNext()) { 47 Element e = (Element) iter.next(); 48 configs.addConfigDef(this.elementToConfigDef(e)); 49 } 50 51 return configs; 52 } 53 54 55 private ConfigDef elementToConfigDef(Element element) { 56 57 ConfigDef configdef = new ConfigDef(); 58 59 configdef.setName(element.getAttributeValue("name")); 60 61 List displaygroups = element.getChildren("display-group"); 62 Iterator iter = displaygroups.iterator(); 63 while (iter.hasNext()) 64 { 65 Element e = (Element) iter.next(); 66 configdef.addDisplayGroup(this.elementToDisplayGroup(e)); 67 } 68 69 return configdef; 70 } 71 72 73 private DisplayGroup elementToDisplayGroup(Element element) { 74 75 DisplayGroup displaygroup = new DisplayGroup(); 76 77 displaygroup.setName(element.getAttributeValue("name")); 78 displaygroup.setKey(element.getAttributeValue("key")); 79 80 List displaygroups = element.getChildren("property-def"); 81 Iterator iter = displaygroups.iterator(); 82 while (iter.hasNext()) 83 { 84 Element e = (Element) iter.next(); 85 displaygroup.addPropertyDef(this.elementToPropertyDef(e)); 86 } 87 88 return displaygroup; 89 } 90 91 92 private PropertyDef elementToPropertyDef(Element element) { 93 94 PropertyDef prop = new PropertyDef(); 95 96 prop.setName(element.getAttributeValue("name")); 97 prop.setKey(element.getAttributeValue("key")); 98 prop.setType(element.getChildText("type")); 99 prop.setDefaultValue(element.getChildText("default-value")); 100 101 if(element.getChild("rows") != null) 103 prop.setRows(element.getChildText("rows")); 104 105 if(element.getChild("cols") != null) 106 prop.setCols(element.getChildText("cols")); 107 108 return prop; 109 } 110 111 } 112 | Popular Tags |