]> source.dussan.org Git - poi.git/commitdiff
Make POIXMLDocument implement Closeable as it holds an OCPPackage with open resources...
authorDominik Stadler <centic@apache.org>
Tue, 26 May 2015 19:30:04 +0000 (19:30 +0000)
committerDominik Stadler <centic@apache.org>
Tue, 26 May 2015 19:30:04 +0000 (19:30 +0000)
Also make close() in POIXMLDocument public to not have to re-implement it in all sub-classes.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1681822 13f79535-47bb-0310-9956-ffa450edef68

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

index bf241f897b6998492416aa1b81662198ab5f3f15..0e18ee1121e9bf8a0493d215df4c043cafe1ff42 100644 (file)
@@ -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.POIFSConstants;
 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 extends POIXMLDocumentPart{
      * 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();
index 9230797e413ca83debd97134600d2a82f557d592..9406fb17c76d67ef63ee1542b29267d13c082264 100644 (file)
@@ -1548,16 +1548,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         out.close();
     }
     
-    /**
-     * 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
      *
index f4e39ab6588ca165a639eb845d444634a6f601c1..55f4093fb6dedd8f54ad89d3420f21d18ae658eb 100644 (file)
@@ -155,13 +155,16 @@ public final class TestPOIXMLDocument extends TestCase {
     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 {