Browse Source

Bug 55850: fix NullPointerException during extraction from XSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1549007 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_10_FINAL
Dominik Stadler 10 years ago
parent
commit
9484ef6f17

+ 3
- 3
src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java View File

import javax.xml.validation.Validator; import javax.xml.validation.Validator;


import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 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.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFMap;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; 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.XSSFSingleXmlCell;
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr; import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
if (!"".equals(complexTypeName)) { if (!"".equals(complexTypeName)) {
NodeList complexTypeList = xmlSchema.getChildNodes(); NodeList complexTypeList = xmlSchema.getChildNodes();
for(int i=0; i< complexTypeList.getLength();i++) { for(int i=0; i< complexTypeList.getLength();i++) {
Node node = list.item(i);
Node node = complexTypeList.item(i);
if ( node instanceof Element) { if ( node instanceof Element) {
if (node.getLocalName().equals("complexType")) { if (node.getLocalName().equals("complexType")) {
Node nameAttribute = node.getAttributes().getNamedItem("name"); Node nameAttribute = node.getAttributes().getNamedItem("name");
} }
return complexTypeNode; return complexTypeNode;
} }
}
}

+ 38
- 0
src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java View File

} }
} }
} }

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);
}
}
} }

BIN
test-data/spreadsheet/55850.xlsx View File


Loading…
Cancel
Save