]> source.dussan.org Git - poi.git/commitdiff
Patch from Yury from bug #45018 - Support for fetching embeded documents from within...
authorNick Burch <nick@apache.org>
Fri, 23 May 2008 15:05:12 +0000 (15:05 +0000)
committerNick Burch <nick@apache.org>
Fri, 23 May 2008 15:05:12 +0000 (15:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@659564 13f79535-47bb-0310-9956-ffa450edef68

build.xml
src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/POIXMLDocument.java
src/ooxml/java/org/apache/poi/POIXMLTextExtractor.java
src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java

index 121cbbd2d19f3bb281d40903948cc752a8b365e1..e1cb26c35320d877cb3bf9f1955aabfb3dee3a65 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -562,6 +562,7 @@ under the License.
         <uptodate property="main.test.notRequired" targetfile="${main.testokfile}">
             <srcfiles dir="${main.src}"/>
             <srcfiles dir="${main.src.test}"/>
+            <srcfiles dir="${ooxml.src}"/>
         </uptodate>
     </target>
 
index 5a90a0463a9880dbbd2d6bf36563120f9b67a04b..f26c6271b9be19b5c52855c63446691b5c779d87 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5.1-alpha1" date="2008-04-??">
+           <action dev="POI-DEVELOPERS" type="add">45018 - Support for fetching embeded documents from within an OOXML file</action>
            <action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
            <action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action>
            <action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action>
index 6709b3271919652a0a6fd2dd91c7141bee99d65e..4fc778a5f97209f69ad9bdb29315d2e48deff6a7 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5.1-alpha1" date="2008-04-??">
+           <action dev="POI-DEVELOPERS" type="add">45018 - Support for fetching embeded documents from within an OOXML file</action>
            <action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
            <action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action>
            <action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action>
index 9fa4789db0e56c472fafc2540f79a590c148d7b1..7be6372759c571fb2682c16d5ac427ae9399ece1 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.poi;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
+import java.util.LinkedList;
+import java.util.List;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.IOUtils;
@@ -39,6 +41,8 @@ public abstract class POIXMLDocument {
     
     public static final String EXTENDED_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
     
+    public static final String OLE_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+    
     /** The OPC Package */
     private Package pkg;
 
@@ -50,6 +54,10 @@ public abstract class POIXMLDocument {
      */
     private POIXMLProperties properties;
     
+       /**
+        * The embedded OLE2 files in the OPC package
+        */
+    private List<PackagePart> embedds;
     
     protected POIXMLDocument() {}
     
@@ -62,6 +70,12 @@ public abstract class POIXMLDocument {
            
                // Get core part
                this.corePart = this.pkg.getPart(coreDocRelationship);
+               
+                       // Get any embedded OLE2 documents
+               this.embedds = new LinkedList<PackagePart>();
+               for(PackageRelationship rel : corePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
+                   embedds.add(getTargetPart(rel));
+               }
         } catch (OpenXML4JException e) {
             throw new IOException(e.toString());
        }
@@ -190,4 +204,12 @@ public abstract class POIXMLDocument {
                }
                return properties;
        }
+       
+    /**
+     * Get the document's embedded files.
+     */
+    public List<PackagePart> getAllEmbedds() throws OpenXML4JException
+    {
+        return embedds;
+    }
 }
index ae8514c278e8675e867978e92a22769e71a6daa0..8df75d949d17196feb0b15a8ff99b39bc2f86682 100644 (file)
@@ -47,4 +47,11 @@ public abstract class POIXMLTextExtractor extends POITextExtractor {
        public ExtendedProperties getExtendedProperties() throws IOException, OpenXML4JException, XmlException {
                return document.getProperties().getExtendedProperties();
        }
+
+       /**
+        * Returns opened document 
+        */
+       public POIXMLDocument getDocument(){
+           return document;
+       }
 }
index 8ca4f0349b8030f38a7319923d71dbefc15e214b..64c8e3f7804fb31c8c86274d8ef98eba043a9e0e 100644 (file)
@@ -58,7 +58,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.xlsx>");
+                       System.err.println("  HXFWordExtractor <filename.docx>");
                        System.exit(1);
                }
                POIXMLTextExtractor extractor =