poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1549008 - /poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
Date Sun, 08 Dec 2013 08:39:10 GMT
Author: centic
Date: Sun Dec  8 08:39:10 2013
New Revision: 1549008

URL: http://svn.apache.org/r1549008
Log:
Refactor XSSFExportToXml a bit, split code into more methods

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java?rev=1549008&r1=1549007&r2=1549008&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java Sun Dec  8
08:39:10 2013
@@ -447,15 +447,23 @@ public class XSSFExportToXml implements 
     }
 
     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 
                 }
             }
         }
-        // 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;
+                        }
+
                     }
                 }
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message