]> source.dussan.org Git - poi.git/commitdiff
Update to ooxml embeding from bug #45018 from Yury
authorNick Burch <nick@apache.org>
Wed, 28 May 2008 13:32:03 +0000 (13:32 +0000)
committerNick Burch <nick@apache.org>
Wed, 28 May 2008 13:32:03 +0000 (13:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@660945 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/POIXMLDocument.java
src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
src/ooxml/testcases/org/apache/poi/TestEmbeded.java
src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx
src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx
src/ooxml/testcases/org/apache/poi/ooxml/data/WordWithAttachments.docx

index 7be6372759c571fb2682c16d5ac427ae9399ece1..f9f543d7bffa9a734887513fce32a270cc033b32 100644 (file)
@@ -41,8 +41,12 @@ public abstract class POIXMLDocument {
     
     public static final String EXTENDED_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
     
+    // OLE embeddings relation name
     public static final String OLE_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
     
+    // Embedded OPC documents relation name
+    public static final String PACK_OBJECT_REL_TYPE="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+    
     /** The OPC Package */
     private Package pkg;
 
@@ -57,7 +61,7 @@ public abstract class POIXMLDocument {
        /**
         * The embedded OLE2 files in the OPC package
         */
-    private List<PackagePart> embedds;
+    protected List<PackagePart> embedds = new LinkedList<PackagePart>();
     
     protected POIXMLDocument() {}
     
@@ -70,16 +74,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());
        }
     }
+    
     protected POIXMLDocument(String path) throws IOException {
                this(openPackage(path));
     }
index fbdf00b01b61bdcfc718d939e2ecd6b7198883fe..ce66aefe9a595f1d6161357998276480827c0a8b 100644 (file)
@@ -24,6 +24,7 @@ import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxml4j.exceptions.OpenXML4JException;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
+import org.openxml4j.opc.PackageRelationship;
 import org.openxml4j.opc.PackageRelationshipCollection;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
@@ -63,6 +64,17 @@ public class XSLFSlideShow extends POIXMLDocument {
                
                presentationDoc =
                        PresentationDocument.Factory.parse(getCorePart().getInputStream());
+               
+               for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) {
+                 PackagePart slidePart =
+                       getTargetPart(getCorePart().getRelationship(ctSlide.getId2()));
+                 
+                 for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE))
+                     embedds.add(getTargetPart(rel)); // TODO: Add this reference to each slide as well
+                 
+                 for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE))
+                  embedds.add(getTargetPart(rel));
+               }
        }
        public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException {
                this(openPackage(file));
index 9fe9ff80ae753158efad0630a1cc8a7c7ca0d2af..719fc63a1d6e5d0f3f4b43149c1efec611985798 100644 (file)
@@ -121,7 +121,21 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
                    null,
                    null
        );
-    
+       public static final XSSFRelation OLEEMBEDDINGS = new XSSFRelation(
+               null,
+               OLE_OBJECT_REL_TYPE,
+               null,
+               null
+       );
+       
+       public static final XSSFRelation PACKEMBEDDINGS = new XSSFRelation(
+            null,
+            PACK_OBJECT_REL_TYPE,
+            null,
+            null
+    );
+       
+   
        public static class XSSFRelation {
                private String TYPE;
                private String REL;
@@ -292,6 +306,13 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
                 PackageRelationshipCollection hyperlinkRels =
                        part.getRelationshipsByType(SHEET_HYPERLINKS.REL);
                 sheet.initHyperlinks(hyperlinkRels);
+                
+                // Get the embeddings for the workbook
+                for(PackageRelationship rel : part.getRelationshipsByType(OLEEMBEDDINGS.REL))
+                    embedds.add(getTargetPart(rel)); // TODO: Add this reference to each sheet as well
+                
+                for(PackageRelationship rel : part.getRelationshipsByType(PACKEMBEDDINGS.REL))
+                    embedds.add(getTargetPart(rel));
             }
         } catch (XmlException e) {
             throw new IOException(e.toString());
index 4338b11f289b68cdb8a02b80cc45e4d205576489..d7fa573bba080f1bbd94a55dfb876b7aeb556192 100644 (file)
@@ -114,6 +114,15 @@ public class XWPFDocument extends POIXMLDocument {
                                tables.add(new XWPFTable(table));
                        }
                }
+               
+        this.embedds = new LinkedList<PackagePart>();
+        for(PackageRelationship rel : getCorePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
+            embedds.add(getTargetPart(rel));
+        }
+        
+        for(PackageRelationship rel : getCorePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
+            embedds.add(getTargetPart(rel));
+        }
        }
        
        /**
index 5e127e21c6117fa553d49401d3ff8a413b174b64..95bbe51f29dbf79061c6e2f53437d9868c6c94ba 100644 (file)
@@ -49,7 +49,7 @@ public class TestEmbeded extends TestCase
                assertTrue(f.exists());
                
                POIXMLDocument doc = new XSSFWorkbook(Package.open(f.toString()));
-               test(doc, 0);
+               test(doc, 4);
        }
 
        public void testWord() throws Exception {
@@ -57,7 +57,7 @@ public class TestEmbeded extends TestCase
                assertTrue(f.exists());
                
                POIXMLDocument doc = new XWPFDocument(Package.open(f.toString()));
-               test(doc, 4);
+               test(doc, 5);
        }
 
        public void testPowerPoint() throws Exception {
@@ -65,7 +65,7 @@ public class TestEmbeded extends TestCase
                assertTrue(f.exists());
                
                POIXMLDocument doc = new XSLFSlideShow(Package.open(f.toString()));
-               test(doc, 0);
+               test(doc, 4);
        }
        
        private void test(POIXMLDocument doc, int expectedCount) throws Exception {
index 5ec8b94adbf14888b71524caaa5fe73e15a26242..cb3e564428a6ee158b232f2b941a080d75c2aae1 100644 (file)
Binary files a/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx and b/src/ooxml/testcases/org/apache/poi/ooxml/data/ExcelWithAttachments.xlsx differ
index 01ec2d5728c2984ec8c3e0defbef9e38dc984222..00b148da14da026c11c904668602334834bef2b3 100644 (file)
Binary files a/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx and b/src/ooxml/testcases/org/apache/poi/ooxml/data/PPTWithAttachments.pptx differ
index 8de2f3168459bfafa3bab51eca9a71e5a2bf8975..ebefabc4432b1efed38102ad456ca45ad873ecb3 100644 (file)
Binary files a/src/ooxml/testcases/org/apache/poi/ooxml/data/WordWithAttachments.docx and b/src/ooxml/testcases/org/apache/poi/ooxml/data/WordWithAttachments.docx differ