]> source.dussan.org Git - poi.git/commitdiff
Refactor XSSFExportToXml a bit, split code into more methods
authorDominik Stadler <centic@apache.org>
Sun, 8 Dec 2013 08:39:10 +0000 (08:39 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 8 Dec 2013 08:39:10 +0000 (08:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1549008 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java

index a6e1a2785acdacdd8457be91dabb1d58fc6b5826..80b0c34deba743515c953e68589fffcfe469f7dd 100644 (file)
@@ -447,15 +447,23 @@ public class XSSFExportToXml implements Comparator<String>{
     }
 
     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<String>{
                 }
             }
         }
-        // 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<complexTypeChildList.getLength();j++) {
-                                Node sequence = complexTypeChildList.item(j);
-
-                                if ( sequence instanceof Element) {
-                                    if (sequence.getLocalName().equals("sequence")) {
-                                        complexTypeNode = sequence;
-                                        break;
-                                    }
+        return complexTypeName;
+    }
+
+    private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode,
+            String 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<complexTypeChildList.getLength();j++) {
+                            Node sequence = complexTypeChildList.item(j);
+
+                            if ( sequence instanceof Element) {
+                                if (sequence.getLocalName().equals("sequence")) {
+                                    complexTypeNode = sequence;
+                                    break;
                                 }
                             }
-                            if (complexTypeNode!=null) {
-                                break;
-                            }
-
                         }
+                        if (complexTypeNode!=null) {
+                            break;
+                        }
+
                     }
                 }
             }