]> source.dussan.org Git - poi.git/commitdiff
Correct an eclipse warning around close(), and a related bug that this identified
authorNick Burch <nick@apache.org>
Thu, 24 Apr 2014 14:50:52 +0000 (14:50 +0000)
committerNick Burch <nick@apache.org>
Thu, 24 Apr 2014 14:50:52 +0000 (14:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1589756 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java

index 676ccba7d09ee65d8aa3fa0b42fd4a71c8438765..5cc894f7de7f69ee78ea4fcb5878b6d69520fafb 100644 (file)
@@ -403,6 +403,11 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
                        revert();
                        return;
                }
+               if (this.contentTypeManager == null) {
+                   logger.log(POILogger.WARN,
+                           "Unable to call close() on a package that hasn't been fully opened yet");
+                   return;
+               }
 
                // Save the content
                ReentrantReadWriteLock l = new ReentrantReadWriteLock();
index 33fd241eda5b286d4178bcf43dbe3b277753aa90..9ac8fd17faa2fea699cc20cdb345dd204a902184 100644 (file)
@@ -64,6 +64,10 @@ public final class ZipPackage extends Package {
     public ZipPackage() {
        super(defaultPackageAccess);
        this.zipArchive = null;
+       
+       try {
+           this.contentTypeManager = new ZipContentTypeManager(null, this);
+       } catch (InvalidFormatException e) {}
     }
 
     /**
index 56ba0e7e8d430477af5d0bf37a586b8e19d811c5..089ed5dc5d906a524bb0957ff797874758ab1328 100644 (file)
@@ -73,7 +73,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor {
        public static void main(String[] args) throws Exception {
                if(args.length < 1) {
                        System.err.println("Use:");
-                       System.err.println("  HXFWordExtractor <filename.docx>");
+                       System.err.println("  XWPFWordExtractor <filename.docx>");
                        System.exit(1);
                }
                POIXMLTextExtractor extractor = 
@@ -81,6 +81,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor {
                                        args[0]
                        ));
                System.out.println(extractor.getText());
+               extractor.close();
        }
        
     public String getText() {