]> source.dussan.org Git - poi.git/commitdiff
Bug 55850: fix NullPointerException during extraction from XSSF
authorDominik Stadler <centic@apache.org>
Sun, 8 Dec 2013 08:35:20 +0000 (08:35 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 8 Dec 2013 08:35:20 +0000 (08:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1549007 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
test-data/spreadsheet/55850.xlsx [new file with mode: 0644]

index 2e6b90242a21d10c96fae896e7c9886a91e297ee..a6e1a2785acdacdd8457be91dabb1d58fc6b5826 100644 (file)
@@ -41,11 +41,11 @@ import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.xssf.usermodel.XSSFTable;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFMap;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFTable;
 import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell;
 import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
@@ -476,7 +476,7 @@ public class XSSFExportToXml implements Comparator<String>{
         if (!"".equals(complexTypeName)) {
             NodeList  complexTypeList  = xmlSchema.getChildNodes();
             for(int i=0; i< complexTypeList.getLength();i++) {
-                Node node = list.item(i);
+                Node node = complexTypeList.item(i);
                 if ( node instanceof Element) {
                     if (node.getLocalName().equals("complexType")) {
                         Node nameAttribute  = node.getAttributes().getNamedItem("name");
@@ -504,4 +504,4 @@ public class XSSFExportToXml implements Comparator<String>{
         }
         return complexTypeNode;
     }
-}
+}
\ No newline at end of file
index 3bbb861f4203c450d19ae27135eaf5f37fee09a8..cb70b358f8e8e0478bffe1ee9b11112f57c4c4f0 100644 (file)
@@ -176,4 +176,42 @@ public final class TestXSSFExportToXML extends TestCase {
                        }
                }
        }
+
+    public void test55850ComplexXmlExport() throws Exception {
+
+        XSSFWorkbook wb = XSSFTestDataSamples
+                .openSampleWorkbook("55850.xlsx");
+
+        for (POIXMLDocumentPart p : wb.getRelations()) {
+
+            if (!(p instanceof MapInfo)) {
+                continue;
+            }
+            MapInfo mapInfo = (MapInfo) p;
+
+            XSSFMap map = mapInfo.getXSSFMapById(2);
+
+            assertNotNull("XSSFMap is null", map);
+
+            XSSFExportToXml exporter = new XSSFExportToXml(map);
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            exporter.exportToXML(os, true);
+            String xmlData = os.toString("UTF-8");
+
+            assertNotNull(xmlData);
+            assertTrue(!xmlData.equals(""));
+
+            String a = xmlData.split("<A>")[1].split("</A>")[0].trim();
+            String b = a.split("<B>")[1].split("</B>")[0].trim();
+            String c = b.split("<C>")[1].split("</C>")[0].trim();
+            String d = c.split("<D>")[1].split("</Dd>")[0].trim();
+            String e = d.split("<E>")[1].split("</EA>")[0].trim();
+
+            String euro = e.split("<EUR>")[1].split("</EUR>")[0].trim();
+            String chf = e.split("<CHF>")[1].split("</CHF>")[0].trim();
+
+            assertEquals("15", euro);
+            assertEquals("19", chf);
+        }
+    }
 }
diff --git a/test-data/spreadsheet/55850.xlsx b/test-data/spreadsheet/55850.xlsx
new file mode 100644 (file)
index 0000000..ea8dc0e
Binary files /dev/null and b/test-data/spreadsheet/55850.xlsx differ