1 23 24 package org.infoglue.deliver.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.log4j.Logger; 31 import org.apache.xerces.parsers.DOMParser; 32 import org.infoglue.cms.entities.management.ContentTypeAttribute; 33 import org.infoglue.cms.entities.management.ContentTypeAttributeParameter; 34 import org.infoglue.cms.entities.management.ContentTypeAttributeParameterValue; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.Element ; 37 import org.w3c.dom.NamedNodeMap ; 38 import org.w3c.dom.Node ; 39 import org.w3c.dom.NodeList ; 40 import org.xml.sax.InputSource ; 41 42 public class FormDeliveryController 43 { 44 private final static Logger logger = Logger.getLogger(FormDeliveryController.class.getName()); 45 46 49 50 private FormDeliveryController() 51 { 52 } 53 54 57 58 public static FormDeliveryController getFormDeliveryController() 59 { 60 return new FormDeliveryController(); 61 } 62 63 66 67 public List getContentTypeAttributes(String schemaValue) 68 { 69 logger.info("schemaValue:" + schemaValue); 70 List attributes = new ArrayList (); 71 72 try 73 { 74 InputSource xmlSource = new InputSource (new StringReader (schemaValue)); 75 76 DOMParser parser = new DOMParser(); 77 parser.parse(xmlSource); 78 Document document = parser.getDocument(); 79 80 String attributesXPath = "/xs:schema/xs:complexType/xs:all/xs:element/xs:complexType/xs:all/xs:element"; 81 NodeList anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), attributesXPath); 82 for(int i=0; i < anl.getLength(); i++) 83 { 84 Element child = (Element )anl.item(i); 85 String attributeName = child.getAttribute("name"); 86 String attributeType = child.getAttribute("type"); 87 88 ContentTypeAttribute contentTypeAttribute = new ContentTypeAttribute(); 89 contentTypeAttribute.setPosition(i); 90 contentTypeAttribute.setName(attributeName); 91 contentTypeAttribute.setInputType(attributeType); 92 93 Node paramsNode = org.apache.xpath.XPathAPI.selectSingleNode(child, "xs:annotation/xs:appinfo/params"); 95 if (paramsNode != null) 96 { 97 NodeList childnl = ((Element )paramsNode).getElementsByTagName("param"); 98 for(int ci=0; ci < childnl.getLength(); ci++) 99 { 100 Element param = (Element )childnl.item(ci); 101 String paramId = param.getAttribute("id"); 102 String paramInputTypeId = param.getAttribute("inputTypeId"); 103 104 ContentTypeAttributeParameter contentTypeAttributeParameter = new ContentTypeAttributeParameter(); 105 contentTypeAttributeParameter.setId(paramId); 106 if(paramInputTypeId != null && paramInputTypeId.length() > 0) 107 contentTypeAttributeParameter.setType(Integer.parseInt(paramInputTypeId)); 108 109 contentTypeAttribute.putContentTypeAttributeParameter(paramId, contentTypeAttributeParameter); 110 111 NodeList valuesNodeList = param.getElementsByTagName("values"); 112 for(int vsnli=0; vsnli < valuesNodeList.getLength(); vsnli++) 113 { 114 Element values = (Element )valuesNodeList.item(vsnli); 115 116 NodeList valueNodeList = param.getElementsByTagName("value"); 117 for(int vnli=0; vnli < valueNodeList.getLength(); vnli++) 118 { 119 Element value = (Element )valueNodeList.item(vnli); 120 String valueId = value.getAttribute("id"); 121 122 ContentTypeAttributeParameterValue contentTypeAttributeParameterValue = new ContentTypeAttributeParameterValue(); 123 contentTypeAttributeParameterValue.setId(valueId); 124 125 NamedNodeMap nodeMap = value.getAttributes(); 126 for(int nmi =0; nmi < nodeMap.getLength(); nmi++) 127 { 128 Node attribute = (Node )nodeMap.item(nmi); 129 String valueAttributeName = attribute.getNodeName(); 130 String valueAttributeValue = attribute.getNodeValue(); 131 contentTypeAttributeParameterValue.addAttribute(valueAttributeName, valueAttributeValue); 132 } 133 134 contentTypeAttributeParameter.addContentTypeAttributeParameterValue(valueId, contentTypeAttributeParameterValue); 135 } 136 } 137 } 138 } 139 141 attributes.add(contentTypeAttribute); 142 } 143 144 } 145 catch(Exception e) 146 { 147 logger.error("An error occurred when we tried to get the attributes of the content type: " + e.getMessage(), e); 148 } 149 150 return attributes; 151 } 152 153 } | Popular Tags |