poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dno...@apache.org
Subject svn commit: r1777146 - in /poi: site/src/documentation/content/xdocs/status.xml trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFImportFromXML.java
Date Tue, 03 Jan 2017 15:41:42 GMT
Author: dnorth
Date: Tue Jan  3 15:41:41 2017
New Revision: 1777146

URL: http://svn.apache.org/viewvc?rev=1777146&view=rev
Log:
Fix poor XPath performance when importing XSSF from XML

https://bz.apache.org/bugzilla/show_bug.cgi?id=60498

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFImportFromXML.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1777146&r1=1777145&r2=1777146&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Tue Jan  3 15:41:41 2017
@@ -61,6 +61,7 @@
         <summary-item>The third-party jar for commons-collections4 is now required
for handling of OLE2 properties</summary-item>
       </summary>
       <actions>
+        <action dev="PD" type="fix" fixes-bug="60498" module="XSSF">Fix performance
problem with XPath parsing in XSSF import from XML</action>
         <action dev="PD" type="fix" fixes-bug="60484" module="HWPF">NPE when reading
a document containing an embedded picture</action>
         <action dev="PD" type="add" fixes-bug="60521" module="XSSF">XSSFGroupShape
nesting</action>
         <action dev="PD" type="add" fixes-bug="60519" module="SS Common">Extractor
for *SSF embeddings</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java?rev=1777146&r1=1777145&r2=1777146&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFImportFromXML.java Tue Jan
 3 15:41:41 2017
@@ -132,21 +132,18 @@ public class XSSFImportFromXML {
                 // TODO: implement support for denormalized XMLs (see
                 // OpenOffice part 4: chapter 3.5.1.7)
 
+            	Node singleNode = result.item(i).cloneNode(true);
                 for (XSSFXmlColumnPr xmlColumnPr : table.getXmlColumnPrs()) {
 
                     int localColumnId = (int) xmlColumnPr.getId();
                     int rowId = rowOffset + i;
                     int columnId = columnOffset + localColumnId;
                     String localXPath = xmlColumnPr.getLocalXPath();
-                    localXPath = localXPath.substring(localXPath.substring(1).indexOf('/')
+ 1);
-
-                    // Build an XPath to select the right node (assuming
-                    // that the commonXPath != "/")
-                    String nodeXPath = commonXPath + "[" + (i + 1) + "]" + localXPath;
+                    localXPath = localXPath.substring(localXPath.substring(1).indexOf('/')
+ 2);
 
                     // TODO: convert the data to the cell format
-                    String value = (String) xpath.evaluate(nodeXPath, result.item(i), XPathConstants.STRING);
-                    logger.log(POILogger.DEBUG, "Extracting with xpath " + nodeXPath + "
: value is '" + value + "'");
+					String value = (String) xpath.evaluate(localXPath, singleNode, XPathConstants.STRING);
+                    logger.log(POILogger.DEBUG, "Extracting with xpath " + localXPath + "
: value is '" + value + "'");
                     XSSFRow row = table.getXSSFSheet().getRow(rowId);
                     if (row == null) {
                         row = table.getXSSFSheet().createRow(rowId);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFImportFromXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFImportFromXML.java?rev=1777146&r1=1777145&r2=1777146&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFImportFromXML.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFImportFromXML.java
Tue Jan  3 15:41:41 2017
@@ -89,7 +89,7 @@ public class TestXSSFImportFromXML {
 		 }
 	}
 	
-	@Test	
+	@Test(timeout=10000)
 	public void testMultiTable() throws IOException, XPathExpressionException, SAXException{
 		XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings-complex-type.xlsx");
 
 		try {
@@ -102,8 +102,13 @@ public class TestXSSFImportFromXML {
     						 "<ns1:Schema ID=\""+cellC6+"\" SchemaRef=\"a\" />"+ 
     						 "<ns1:Schema ID=\""+cellC7+"\" SchemaRef=\"b\" />"+ 
     						 "<ns1:Schema ID=\""+cellC8+"\" SchemaRef=\"c\" />"+ 
-    						 "<ns1:Schema ID=\""+cellC9+"\" SchemaRef=\"d\" />"+ 
-    						 "<ns1:Map ID=\"1\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\"
AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">"+
+    						 "<ns1:Schema ID=\""+cellC9+"\" SchemaRef=\"d\" />";
+    		
+    						 for(int i = 10; i< 10010; i++){
+    							 testXML +=  "<ns1:Schema ID=\"c"+i+"\" SchemaRef=\"d\" />";
+    						 }
+    		
+    						testXML += "<ns1:Map ID=\"1\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\"
AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">"+
     						 "<ns1:DataBinding DataBindingLoadMode=\"\" />"+ 
     						 "</ns1:Map>"+
     						 "<ns1:Map ID=\"2\" Name=\"\" RootElement=\"\" SchemaID=\"\" ShowImportExportValidationErrors=\"\"
AutoFit=\"\" Append=\"\" PreserveSortAFLayout=\"\" PreserveFormat=\"\">"+
@@ -127,6 +132,7 @@ public class TestXSSFImportFromXML {
     		assertEquals(cellC7,sheet.getRow(6).getCell(2).getStringCellValue());
     		assertEquals(cellC8,sheet.getRow(7).getCell(2).getStringCellValue());
     		assertEquals(cellC9,sheet.getRow(8).getCell(2).getStringCellValue());
+    		assertEquals("c5001",sheet.getRow(5000).getCell(2).getStringCellValue());
         } finally {
             wb.close();
         }
@@ -238,4 +244,7 @@ public class TestXSSFImportFromXML {
 		
 		wb.close();
 	}
+	
+	
+	
 }



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


Mime
View raw message