Refactor XSSFExportToXml a bit, split code into more methods
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1549008 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a08a1dd10
commit
76c0cfc2c9
@ -447,16 +447,24 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
|
private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
|
||||||
Node complexTypeNode = null;
|
|
||||||
|
|
||||||
String elementNameWithoutNamespace = removeNamespace(elementName);
|
String elementNameWithoutNamespace = removeNamespace(elementName);
|
||||||
|
|
||||||
|
String complexTypeName = getComplexTypeNameFromChildren(localComplexTypeRootNode, elementNameWithoutNamespace);
|
||||||
|
|
||||||
|
// Note: we expect that all the complex types are defined at root level
|
||||||
|
Node complexTypeNode = null;
|
||||||
|
if (!"".equals(complexTypeName)) {
|
||||||
|
complexTypeNode = getComplexTypeNodeFromSchemaChildren(xmlSchema, complexTypeNode, complexTypeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return complexTypeNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getComplexTypeNameFromChildren(Node localComplexTypeRootNode,
|
||||||
|
String elementNameWithoutNamespace) {
|
||||||
NodeList list = localComplexTypeRootNode.getChildNodes();
|
NodeList list = localComplexTypeRootNode.getChildNodes();
|
||||||
String complexTypeName = "";
|
String complexTypeName = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(int i=0; i< list.getLength();i++) {
|
for(int i=0; i< list.getLength();i++) {
|
||||||
Node node = list.item(i);
|
Node node = list.item(i);
|
||||||
if ( node instanceof Element) {
|
if ( node instanceof Element) {
|
||||||
@ -472,32 +480,34 @@ public class XSSFExportToXml implements Comparator<String>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note: we expect that all the complex types are defined at root level
|
return complexTypeName;
|
||||||
if (!"".equals(complexTypeName)) {
|
}
|
||||||
NodeList complexTypeList = xmlSchema.getChildNodes();
|
|
||||||
for(int i=0; i< complexTypeList.getLength();i++) {
|
|
||||||
Node node = complexTypeList.item(i);
|
|
||||||
if ( node instanceof Element) {
|
|
||||||
if (node.getLocalName().equals("complexType")) {
|
|
||||||
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
|
||||||
if (nameAttribute.getNodeValue().equals(complexTypeName)) {
|
|
||||||
|
|
||||||
NodeList complexTypeChildList =node.getChildNodes();
|
private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode,
|
||||||
for(int j=0; j<complexTypeChildList.getLength();j++) {
|
String complexTypeName) {
|
||||||
Node sequence = complexTypeChildList.item(j);
|
NodeList complexTypeList = xmlSchema.getChildNodes();
|
||||||
|
for(int i=0; i< complexTypeList.getLength();i++) {
|
||||||
|
Node node = complexTypeList.item(i);
|
||||||
|
if ( node instanceof Element) {
|
||||||
|
if (node.getLocalName().equals("complexType")) {
|
||||||
|
Node nameAttribute = node.getAttributes().getNamedItem("name");
|
||||||
|
if (nameAttribute.getNodeValue().equals(complexTypeName)) {
|
||||||
|
|
||||||
if ( sequence instanceof Element) {
|
NodeList complexTypeChildList =node.getChildNodes();
|
||||||
if (sequence.getLocalName().equals("sequence")) {
|
for(int j=0; j<complexTypeChildList.getLength();j++) {
|
||||||
complexTypeNode = sequence;
|
Node sequence = complexTypeChildList.item(j);
|
||||||
break;
|
|
||||||
}
|
if ( sequence instanceof Element) {
|
||||||
|
if (sequence.getLocalName().equals("sequence")) {
|
||||||
|
complexTypeNode = sequence;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (complexTypeNode!=null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (complexTypeNode!=null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user