From 2fdc436d8e67fb92984c18724f15e8f78630863c Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 8 Dec 2013 08:39:10 +0000 Subject: [PATCH] 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 --- .../poi/xssf/extractor/XSSFExportToXml.java | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index a6e1a2785a..80b0c34deb 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -447,15 +447,23 @@ public class XSSFExportToXml implements Comparator{ } private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) { - Node complexTypeNode = null; - String elementNameWithoutNamespace = removeNamespace(elementName); + String complexTypeName = getComplexTypeNameFromChildren(localComplexTypeRootNode, elementNameWithoutNamespace); - NodeList list = localComplexTypeRootNode.getChildNodes(); - String complexTypeName = ""; + // 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(); + String complexTypeName = ""; for(int i=0; i< list.getLength();i++) { Node node = list.item(i); @@ -472,32 +480,34 @@ public class XSSFExportToXml implements Comparator{ } } } - // Note: we expect that all the complex types are defined at root level - 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(); - for(int j=0; j