poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1681822 - in /poi/trunk/src/ooxml: java/org/apache/poi/POIXMLDocument.java java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java testcases/org/apache/poi/TestPOIXMLDocument.java
Date Tue, 26 May 2015 19:30:05 GMT
Author: centic
Date: Tue May 26 19:30:04 2015
New Revision: 1681822

URL: http://svn.apache.org/r1681822
Log:
Make POIXMLDocument implement Closeable as it holds an OCPPackage with open resources and
thus should be closed after usage. Until now only XSSFWorkbook did this, but it makes sense
for all derived classes.
Also make close() in POIXMLDocument public to not have to re-implement it in all sub-classes.

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=1681822&r1=1681821&r2=1681822&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Tue May 26 19:30:04 2015
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -37,7 +38,7 @@ import org.apache.poi.poifs.common.POIFS
 import org.apache.poi.util.IOUtils;
 import org.apache.xmlbeans.impl.common.SystemCache;
 
-public abstract class POIXMLDocument extends POIXMLDocumentPart{
+public abstract class POIXMLDocument extends POIXMLDocumentPart implements Closeable {
     public static final String DOCUMENT_CREATOR = "Apache POI";
 
     // OLE embeddings relation name
@@ -171,7 +172,7 @@ public abstract class POIXMLDocument ext
      * Closes the underlying {@link OPCPackage} from which this
      *  document was read, if there is one
      */
-    protected void close() throws IOException {
+    public void close() throws IOException {
         if (pkg != null) {
             if (pkg.getPackageAccess() == PackageAccess.READ) {
                 pkg.revert();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1681822&r1=1681821&r2=1681822&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Tue May 26 19:30:04
2015
@@ -1549,16 +1549,6 @@ public class XSSFWorkbook extends POIXML
     }
     
     /**
-     * Closes the underlying {@link OPCPackage} from which
-     *  the Workbook was read, if any. Has no effect on newly 
-     *  created Workbooks.
-     */
-    @Override
-    public void close() throws IOException {
-        super.close();
-    }
-
-    /**
      * Returns SharedStringsTable - tha cache of string for this workbook
      *
      * @return the shared string table

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java?rev=1681822&r1=1681821&r2=1681822&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java Tue May 26 19:30:04
2015
@@ -155,13 +155,16 @@ public final class TestPOIXMLDocument ex
     public void testRelationOrder() throws Exception {
         OPCPackage pkg = PackageHelper.open(POIDataSamples.getDocumentInstance().openResourceAsStream("WordWithAttachments.docx"));
         OPCParser doc = new OPCParser(pkg);
-        doc.parse(new TestFactory());
-
-        for(POIXMLDocumentPart rel : doc.getRelations()){
-            //TODO finish me
-            assertNotNull(rel);
+        try {
+            doc.parse(new TestFactory());
+    
+            for(POIXMLDocumentPart rel : doc.getRelations()){
+                //TODO finish me
+                assertNotNull(rel);
+            }
+        } finally {
+        	doc.close();
         }
-
     }
 
     public void testCommitNullPart() throws IOException, InvalidFormatException {



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


Mime
View raw message