bug 61630: performance improvements in XSSFExportToXml. Thanks to Daniel for the patch.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1812546 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-10-18 16:04:06 +00:00
parent 2a0aac8ea5
commit 9a27ae194f

View File

@ -436,29 +436,32 @@ public class XSSFExportToXml implements Comparator<String>{
return -1; return -1;
} }
NodeList list = complexType.getChildNodes();
int indexOf = -1; int indexOf = -1;
int i = 0;
Node node = complexType.getFirstChild();
final String elementNameWithoutNamespace = removeNamespace(elementName);
for(int i=0; i< list.getLength();i++) { while (node != null) {
Node node = list.item(i);
if (node instanceof Element && "element".equals(node.getLocalName())) { if (node instanceof Element && "element".equals(node.getLocalName())) {
Node element = getNameOrRefElement(node); Node element = getNameOrRefElement(node);
if (element.getNodeValue().equals(removeNamespace(elementName))) { if (element.getNodeValue().equals(elementNameWithoutNamespace)) {
indexOf = i; indexOf = i;
break; break;
} }
} }
i++;
node = node.getNextSibling();
} }
return indexOf; return indexOf;
} }
private Node getNameOrRefElement(Node node) { private Node getNameOrRefElement(Node node) {
Node returnNode = node.getAttributes().getNamedItem("name"); Node returnNode = node.getAttributes().getNamedItem("ref");
if(returnNode != null) { if(returnNode != null) {
return returnNode; return returnNode;
} }
return node.getAttributes().getNamedItem("ref"); return node.getAttributes().getNamedItem("name");
} }
private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) { private Node getComplexTypeForElement(String elementName,Node xmlSchema,Node localComplexTypeRootNode) {
@ -482,11 +485,10 @@ public class XSSFExportToXml implements Comparator<String>{
return ""; return "";
} }
NodeList list = localComplexTypeRootNode.getChildNodes(); Node node = localComplexTypeRootNode.getFirstChild();
String complexTypeName = ""; String complexTypeName = "";
for(int i=0; i<list.getLength(); i++) { while (node != null) {
final Node node = list.item(i);
if ( node instanceof Element && "element".equals(node.getLocalName())) { if ( node instanceof Element && "element".equals(node.getLocalName())) {
Node nameAttribute = getNameOrRefElement(node); Node nameAttribute = getNameOrRefElement(node);
if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) { if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
@ -497,23 +499,21 @@ public class XSSFExportToXml implements Comparator<String>{
} }
} }
} }
node = node.getNextSibling();
} }
return complexTypeName; return complexTypeName;
} }
private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode, private Node getComplexTypeNodeFromSchemaChildren(Node xmlSchema, Node complexTypeNode,
String complexTypeName) { String complexTypeName) {
NodeList complexTypeList = xmlSchema.getChildNodes(); Node node = xmlSchema.getFirstChild();
for(int i=0; i< complexTypeList.getLength();i++) { while (node != null) {
Node node = complexTypeList.item(i);
if ( node instanceof Element) { if ( node instanceof Element) {
if ("complexType".equals(node.getLocalName())) { if ("complexType".equals(node.getLocalName())) {
Node nameAttribute = getNameOrRefElement(node); Node nameAttribute = getNameOrRefElement(node);
if (nameAttribute.getNodeValue().equals(complexTypeName)) { if (nameAttribute.getNodeValue().equals(complexTypeName)) {
Node sequence = node.getFirstChild();
NodeList complexTypeChildList =node.getChildNodes(); while(sequence != null) {
for(int j=0; j<complexTypeChildList.getLength();j++) {
Node sequence = complexTypeChildList.item(j);
if ( sequence instanceof Element) { if ( sequence instanceof Element) {
final String localName = sequence.getLocalName(); final String localName = sequence.getLocalName();
@ -522,6 +522,7 @@ public class XSSFExportToXml implements Comparator<String>{
break; break;
} }
} }
sequence = sequence.getNextSibling();
} }
if (complexTypeNode!=null) { if (complexTypeNode!=null) {
break; break;
@ -530,6 +531,7 @@ public class XSSFExportToXml implements Comparator<String>{
} }
} }
} }
node = node.getNextSibling();
} }
return complexTypeNode; return complexTypeNode;
} }