poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dno...@apache.org
Subject svn commit: r1696559 - in /poi: site/src/documentation/content/xdocs/ trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/ trunk/test-data/spreadsheet/
Date Wed, 19 Aug 2015 11:10:13 GMT
Author: dnorth
Date: Wed Aug 19 11:10:13 2015
New Revision: 1696559

URL: http://svn.apache.org/r1696559
Log:
Improve ReadOnlySharedStringsTable to cope gracefully with an empty SST part.

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

Added:
    poi/trunk/test-data/spreadsheet/noSharedStringTable.xlsx   (with props)
Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.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=1696559&r1=1696558&r2=1696559&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Wed Aug 19 11:10:13 2015
@@ -39,6 +39,7 @@
     </devs>
 
     <release version="3.13-beta2" date="2015-10-??">
+        <action dev="DN" type="fix" fixes-bug="58262">ReadOnlySharedStringsTable now
handles workbooks with an empty SST part.</action>
         <action dev="DN" type="fix" fixes-bug="52111">Intersection formulae are now
supported in XSSF.</action>
         <action dev="PD" type="fix" fixes-bug="58253">CellReference upper-case check
for #REF!, and javadoc improvements</action>
         <action dev="PD" type="fix" fixes-bug="58252">More CellReference unit testing
coverage</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java?rev=1696559&r1=1696558&r2=1696559&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
Wed Aug 19 11:10:13 2015
@@ -132,13 +132,15 @@ public class ReadOnlySharedStringsTable
      * @throws ParserConfigurationException
      */
     public void readFrom(InputStream is) throws IOException, SAXException {
-        InputSource sheetSource = new InputSource(is);
-        try {
-           XMLReader sheetParser = SAXHelper.newXMLReader();
-           sheetParser.setContentHandler(this);
-           sheetParser.parse(sheetSource);
-        } catch(ParserConfigurationException e) {
-           throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
+        if (is.available() > 0) {
+            InputSource sheetSource = new InputSource(is);
+            try {
+                XMLReader sheetParser = SAXHelper.newXMLReader();
+                sheetParser.setContentHandler(this);
+                sheetParser.parse(sheetSource);
+            } catch(ParserConfigurationException e) {
+                throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
+            }
         }
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java?rev=1696559&r1=1696558&r2=1696559&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
Wed Aug 19 11:10:13 2015
@@ -20,12 +20,16 @@
 package org.apache.poi.xssf.eventusermodel;
 
 import junit.framework.TestCase;
+
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.xssf.model.SharedStringsTable;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+import org.xml.sax.SAXException;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -55,4 +59,24 @@ public final class TestReadOnlySharedStr
         }
 
 	}
+    
+    public void testEmptySSTOnPackageObtainedViaWorkbook() throws Exception {
+        XSSFWorkbook wb = new XSSFWorkbook(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"));
+        OPCPackage pkg = wb.getPackage();
+        assertEmptySST(pkg);
+        wb.close();
+    }
+    
+    public void testEmptySSTOnPackageDirect() throws Exception {
+        OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"));
+        assertEmptySST(pkg);
+    }
+
+    private void assertEmptySST(OPCPackage pkg) throws IOException, SAXException {
+        ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg);
+        assertEquals(0, sst.getCount());
+        assertEquals(0, sst.getUniqueCount());
+        assertNull(sst.getItems()); // same state it's left in if fed a package which has
no SST part.
+    }
+    
 }

Added: poi/trunk/test-data/spreadsheet/noSharedStringTable.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/noSharedStringTable.xlsx?rev=1696559&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/noSharedStringTable.xlsx
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/test-data/spreadsheet/noSharedStringTable.xlsx
------------------------------------------------------------------------------
--- svn:mime-type (added)
+++ svn:mime-type Wed Aug 19 11:10:13 2015
@@ -0,0 +1 @@
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet



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


Mime
View raw message