1 17 package org.alfresco.config.xml.elementreader; 18 19 import java.util.Iterator ; 20 21 import org.dom4j.Attribute; 22 import org.dom4j.Element; 23 24 import org.alfresco.config.ConfigElement; 25 import org.alfresco.config.element.GenericConfigElement; 26 27 33 public class GenericElementReader implements ConfigElementReader 34 { 35 38 public ConfigElement parse(Element element) 39 { 40 GenericConfigElement configElement = null; 41 42 if (element != null) 43 { 44 configElement = createConfigElement(element); 45 46 processChildren(element, configElement); 48 } 49 50 return configElement; 51 } 52 53 60 private void processChildren(Element element, GenericConfigElement parentConfig) 61 { 62 Iterator <Element> children = element.elementIterator(); 64 while (children.hasNext()) 65 { 66 Element child = children.next(); 67 GenericConfigElement childConfigElement = createConfigElement(child); 68 parentConfig.addChild(childConfigElement); 69 70 processChildren(child, childConfigElement); 72 } 73 } 74 75 81 private GenericConfigElement createConfigElement(Element element) 82 { 83 String name = element.getName(); 85 86 GenericConfigElement configElement = new GenericConfigElement(name); 89 if ((element.hasContent()) && (element.hasMixedContent() == false)) 90 { 91 String value = element.getTextTrim(); 92 if (value != null && value.length() > 0) 93 { 94 configElement.setValue(value); 95 } 96 } 97 98 Iterator <Attribute> attrs = element.attributeIterator(); 99 while (attrs.hasNext()) 100 { 101 Attribute attr = attrs.next(); 102 String attrName = attr.getName(); 103 String attrValue = attr.getValue(); 104 105 configElement.addAttribute(attrName, attrValue); 106 } 107 108 return configElement; 109 } 110 } 111 | Popular Tags |