1 23 24 package org.infoglue.cms.controllers.kernel.impl.simple; 25 26 import java.io.StringReader ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.apache.xerces.parsers.DOMParser; 31 import org.infoglue.cms.applications.databeans.ComponentPropertyDefinition; 32 import org.infoglue.cms.applications.databeans.ComponentPropertyOptionDefinition; 33 import org.infoglue.cms.entities.kernel.BaseEntityVO; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.Element ; 36 import org.w3c.dom.Node ; 37 import org.w3c.dom.NodeList ; 38 import org.xml.sax.InputSource ; 39 40 45 46 public class ComponentPropertyDefinitionController extends BaseController 47 { 48 49 52 53 public static ComponentPropertyDefinitionController getController() 54 { 55 return new ComponentPropertyDefinitionController(); 56 } 57 58 public List parseComponentPropertyDefinitions(String xml) 59 { 60 List componentPropertyDefinitions = new ArrayList (); 61 62 if(xml == null || xml.equals("")) 63 return componentPropertyDefinitions; 64 65 try 66 { 67 InputSource xmlSource = new InputSource (new StringReader (xml)); 68 69 DOMParser parser = new DOMParser(); 70 parser.parse(xmlSource); 71 Document document = parser.getDocument(); 72 73 NodeList nl = document.getElementsByTagName("properties"); 74 for(int i=0; i<nl.getLength(); i++) 75 { 76 Node propertiesNode = nl.item(i); 77 Element propertiesElement = (Element )propertiesNode; 78 79 NodeList propertyNodeList = propertiesElement.getElementsByTagName("property"); 80 for(int j=0; j<propertyNodeList.getLength(); j++) 81 { 82 Node propertyNode = propertyNodeList.item(j); 83 Element propertyElement = (Element )propertyNode; 84 85 String name = propertyElement.getAttribute("name"); 86 String type = propertyElement.getAttribute("type"); 87 String entity = propertyElement.getAttribute("entity"); 88 String multiple = propertyElement.getAttribute("multiple"); 89 String allowedContentTypeNames = propertyElement.getAttribute("allowedContentTypeDefinitionNames"); 90 String description = propertyElement.getAttribute("description"); 91 92 ComponentPropertyDefinition cpd = new ComponentPropertyDefinition(name, type, entity, new Boolean (multiple), allowedContentTypeNames, description); 93 94 95 NodeList optionsNodeList = propertyElement.getElementsByTagName("option"); 96 for(int k=0; k<optionsNodeList.getLength(); k++) 97 { 98 Node optionNode = optionsNodeList.item(k); 99 Element optionElement = (Element )optionNode; 100 101 String optionName = optionElement.getAttribute("name"); 102 String optionValue = optionElement.getAttribute("value"); 103 104 ComponentPropertyOptionDefinition cpod = new ComponentPropertyOptionDefinition(optionName, optionValue); 105 106 cpd.getOptions().add(cpod); 107 } 108 109 110 componentPropertyDefinitions.add(cpd); 111 } 112 } 113 } 114 catch(Exception e) 115 { 116 e.printStackTrace(); 117 } 118 119 return componentPropertyDefinitions; 120 } 121 122 public BaseEntityVO getNewVO() 123 { 124 return null; 125 } 126 127 128 129 } 130 | Popular Tags |