mirror of https://github.com/apache/poi.git
bug 61630: revert r1813240, which failed the integration test with org.apache.poi.stress.XSSFFileHandler on test-data/spreadsheet/59025.xlsx
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1813243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4e782652dc
commit
91fbf5db4f
|
@ -82,7 +82,7 @@ public class XSSFExportToXml implements Comparator<String>{
|
||||||
private static final POILogger LOG = POILogFactory.getLogger(XSSFExportToXml.class);
|
private static final POILogger LOG = POILogFactory.getLogger(XSSFExportToXml.class);
|
||||||
|
|
||||||
private XSSFMap map;
|
private XSSFMap map;
|
||||||
private final HashMap<String, Integer> indexMap = new HashMap<>();
|
|
||||||
/**
|
/**
|
||||||
* Creates a new exporter and sets the mapping to be used when generating the XML output document
|
* Creates a new exporter and sets the mapping to be used when generating the XML output document
|
||||||
*
|
*
|
||||||
|
@ -146,10 +146,8 @@ public class XSSFExportToXml implements Comparator<String>{
|
||||||
tableMappings.put(commonXPath, table);
|
tableMappings.put(commonXPath, table);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexMap.clear();
|
|
||||||
xpaths.sort(this);
|
xpaths.sort(this);
|
||||||
indexMap.clear();
|
|
||||||
|
|
||||||
for(String xpath : xpaths) {
|
for(String xpath : xpaths) {
|
||||||
|
|
||||||
XSSFSingleXmlCell simpleXmlCell = singleXmlCellsMappings.get(xpath);
|
XSSFSingleXmlCell simpleXmlCell = singleXmlCellsMappings.get(xpath);
|
||||||
|
@ -403,7 +401,6 @@ public class XSSFExportToXml implements Comparator<String>{
|
||||||
|
|
||||||
String[] leftTokens = leftXpath.split("/");
|
String[] leftTokens = leftXpath.split("/");
|
||||||
String[] rightTokens = rightXpath.split("/");
|
String[] rightTokens = rightXpath.split("/");
|
||||||
String samePath = "/";
|
|
||||||
|
|
||||||
int minLength = leftTokens.length< rightTokens.length? leftTokens.length : rightTokens.length;
|
int minLength = leftTokens.length< rightTokens.length? leftTokens.length : rightTokens.length;
|
||||||
|
|
||||||
|
@ -415,47 +412,47 @@ public class XSSFExportToXml implements Comparator<String>{
|
||||||
String rightElementName = rightTokens[i];
|
String rightElementName = rightTokens[i];
|
||||||
|
|
||||||
if (leftElementName.equals(rightElementName)) {
|
if (leftElementName.equals(rightElementName)) {
|
||||||
samePath += "/" + leftElementName;
|
|
||||||
localComplexTypeRootNode = getComplexTypeForElement(leftElementName, xmlSchema, localComplexTypeRootNode);
|
localComplexTypeRootNode = getComplexTypeForElement(leftElementName, xmlSchema, localComplexTypeRootNode);
|
||||||
} else {
|
} else {
|
||||||
return indexOfElementInComplexType(samePath, leftElementName, rightElementName,localComplexTypeRootNode);
|
int leftIndex = indexOfElementInComplexType(leftElementName,localComplexTypeRootNode);
|
||||||
|
int rightIndex = indexOfElementInComplexType(rightElementName,localComplexTypeRootNode);
|
||||||
|
if (leftIndex!=-1 && rightIndex!=-1) {
|
||||||
|
if ( leftIndex < rightIndex) {
|
||||||
|
return -1;
|
||||||
|
}if ( leftIndex > rightIndex) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} /*else {
|
||||||
|
// NOTE: the xpath doesn't match correctly in the schema
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int indexOfElementInComplexType(String samePath,String leftElementName,String rightElementName,Node complexType) {
|
private int indexOfElementInComplexType(String elementName,Node complexType) {
|
||||||
if(complexType == null) {
|
if(complexType == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int indexOf = -1;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Node node = complexType.getFirstChild();
|
Node node = complexType.getFirstChild();
|
||||||
final String leftWithoutNamespace = removeNamespace(leftElementName);
|
final String elementNameWithoutNamespace = removeNamespace(elementName);
|
||||||
int leftIndexOf = getAndStoreIndex(samePath, leftWithoutNamespace);
|
|
||||||
final String rightWithoutNamespace = removeNamespace(rightElementName);
|
|
||||||
int rightIndexOf = getAndStoreIndex(samePath, rightWithoutNamespace);
|
|
||||||
|
|
||||||
while (node != null && (rightIndexOf==-1||leftIndexOf==-1)) {
|
while (node != null) {
|
||||||
if (node instanceof Element && "element".equals(node.getLocalName())) {
|
if (node instanceof Element && "element".equals(node.getLocalName())) {
|
||||||
String elementValue = getNameOrRefElement(node).getNodeValue();
|
Node element = getNameOrRefElement(node);
|
||||||
if (elementValue.equals(leftWithoutNamespace)) {
|
if (element.getNodeValue().equals(elementNameWithoutNamespace)) {
|
||||||
leftIndexOf = i;
|
indexOf = i;
|
||||||
}
|
break;
|
||||||
if (elementValue.equals(rightWithoutNamespace)) {
|
|
||||||
rightIndexOf = i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
node = node.getNextSibling();
|
node = node.getNextSibling();
|
||||||
}
|
}
|
||||||
return Integer.compare(leftIndexOf, rightIndexOf);
|
return indexOf;
|
||||||
}
|
|
||||||
|
|
||||||
private int getAndStoreIndex(String samePath,String withoutNamespace) {
|
|
||||||
String withPath = samePath+"/"+withoutNamespace;
|
|
||||||
return indexMap.getOrDefault(withPath, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getNameOrRefElement(Node node) {
|
private Node getNameOrRefElement(Node node) {
|
||||||
|
|
Loading…
Reference in New Issue