1 18 23 24 package org.apache.roller.config.runtime; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import org.jdom.Document; 31 import org.jdom.Element; 32 import org.jdom.JDOMException; 33 import org.jdom.input.SAXBuilder; 34 35 36 42 public class RuntimeConfigDefsParser { 43 44 45 public RuntimeConfigDefsParser() {} 46 47 48 52 public RuntimeConfigDefs unmarshall(InputStream instream) 53 throws IOException , JDOMException { 54 55 if(instream == null) 56 throw new IOException ("InputStream is null!"); 57 58 RuntimeConfigDefs configs = new RuntimeConfigDefs(); 59 60 SAXBuilder builder = new SAXBuilder(); 61 Document doc = builder.build(instream); 62 63 Element root = doc.getRootElement(); 64 List configdefs = root.getChildren("config-def"); 65 Iterator iter = configdefs.iterator(); 66 while (iter.hasNext()) { 67 Element e = (Element) iter.next(); 68 configs.addConfigDef(this.elementToConfigDef(e)); 69 } 70 71 return configs; 72 } 73 74 75 private ConfigDef elementToConfigDef(Element element) { 76 77 ConfigDef configdef = new ConfigDef(); 78 79 configdef.setName(element.getAttributeValue("name")); 80 81 List displaygroups = element.getChildren("display-group"); 82 Iterator iter = displaygroups.iterator(); 83 while (iter.hasNext()) 84 { 85 Element e = (Element) iter.next(); 86 configdef.addDisplayGroup(this.elementToDisplayGroup(e)); 87 } 88 89 return configdef; 90 } 91 92 93 private DisplayGroup elementToDisplayGroup(Element element) { 94 95 DisplayGroup displaygroup = new DisplayGroup(); 96 97 displaygroup.setName(element.getAttributeValue("name")); 98 displaygroup.setKey(element.getAttributeValue("key")); 99 100 List displaygroups = element.getChildren("property-def"); 101 Iterator iter = displaygroups.iterator(); 102 while (iter.hasNext()) 103 { 104 Element e = (Element) iter.next(); 105 displaygroup.addPropertyDef(this.elementToPropertyDef(e)); 106 } 107 108 return displaygroup; 109 } 110 111 112 private PropertyDef elementToPropertyDef(Element element) { 113 114 PropertyDef prop = new PropertyDef(); 115 116 prop.setName(element.getAttributeValue("name")); 117 prop.setKey(element.getAttributeValue("key")); 118 prop.setType(element.getChildText("type")); 119 prop.setDefaultValue(element.getChildText("default-value")); 120 121 if(element.getChild("rows") != null) 123 prop.setRows(element.getChildText("rows")); 124 125 if(element.getChild("cols") != null) 126 prop.setCols(element.getChildText("cols")); 127 128 return prop; 129 } 130 131 } 132 | Popular Tags |