Index: src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java =================================================================== diff --git a/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java b/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java --- a/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (revision 1574511) +++ b/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (working copy) @@ -27,22 +27,36 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; +import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.util.Internal; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFRelation; import org.apache.xmlbeans.XmlException; -import org.openxmlformats.schemas.presentationml.x2006.main.*; +import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList; +import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; +import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdList; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMaster; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdList; +import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry; +import org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument; +import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; /** * Experimental class to do low level processing of pptx files. - * + * * Most users should use the higher level {@link XMLSlideShow} instead. - * + * * If you are using these low level classes, then you * will almost certainly need to refer to the OOXML * specifications from * http://www.ecma-international.org/publications/standards/Ecma-376.htm - * + * * WARNING - APIs expected to change rapidly */ public class XSLFSlideShow extends POIXMLDocument { @@ -53,33 +67,43 @@ */ private List embedds; - public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException { - super(container); - - if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) { - rebase(getPackage()); - } - - presentationDoc = - PresentationDocument.Factory.parse(getCorePart().getInputStream()); - + public XSLFSlideShow(OPCPackage container, boolean loadExternalEmbded) throws OpenXML4JException, IOException, XmlException { + super(container); + + if(getCorePart().getContentType().equals(XSLFRelation.THEME_MANAGER.getContentType())) { + rebase(getPackage()); + } + + presentationDoc = + PresentationDocument.Factory.parse(getCorePart().getInputStream()); + embedds = new LinkedList(); for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdList()) { - PackagePart corePart = getCorePart(); - PackagePart slidePart = corePart.getRelatedPart( - corePart.getRelationship(ctSlide.getId2())); + PackagePart corePart = getCorePart(); + PackagePart slidePart = corePart.getRelatedPart( + corePart.getRelationship(ctSlide.getId2())); - for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) - embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well + for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE)) { + if (loadExternalEmbded || rel.getTargetMode() == TargetMode.INTERNAL) { + embedds.add(slidePart.getRelatedPart(rel)); // TODO: Add this reference to each slide as well + } + } - for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) - embedds.add(slidePart.getRelatedPart(rel)); - } - } + for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE)) + if (loadExternalEmbded || rel.getTargetMode() == TargetMode.INTERNAL) { + embedds.add(slidePart.getRelatedPart(rel)); + } + } + } + + public XSLFSlideShow(OPCPackage container) throws OpenXML4JException, IOException, XmlException { + this(container, false); + } + public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException { this(openPackage(file)); } - + /** * Returns the low level presentation base object */ @@ -87,7 +111,7 @@ public CTPresentation getPresentation() { return presentationDoc.getPresentation(); } - + /** * Returns the references from the presentation to its * slides. @@ -98,16 +122,16 @@ public CTSlideIdList getSlideReferences() { if(! getPresentation().isSetSldIdLst()) { getPresentation().setSldIdLst( - CTSlideIdList.Factory.newInstance() + CTSlideIdList.Factory.newInstance() ); } return getPresentation().getSldIdLst(); } - + /** * Returns the references from the presentation to its * slide masters. - * You'll need these to get at the actual slide + * You'll need these to get at the actual slide * masters themselves */ @Internal @@ -114,10 +138,10 @@ public CTSlideMasterIdList getSlideMasterReferences() { return getPresentation().getSldMasterIdLst(); } - + public PackagePart getSlideMasterPart(CTSlideMasterIdListEntry master) throws IOException, XmlException { try { - PackagePart corePart = getCorePart(); + PackagePart corePart = getCorePart(); return corePart.getRelatedPart( corePart.getRelationship(master.getId2()) ); @@ -139,7 +163,7 @@ public PackagePart getSlidePart(CTSlideIdListEntry slide) throws IOException, XmlException { try { - PackagePart corePart = getCorePart(); + PackagePart corePart = getCorePart(); return corePart.getRelatedPart( corePart.getRelationship(slide.getId2()) ); @@ -166,13 +190,13 @@ public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException { PackageRelationshipCollection notes; PackagePart slidePart = getSlidePart(parentSlide); - + try { notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation()); } catch(InvalidFormatException e) { throw new IllegalStateException(e); } - + if(notes.size() == 0) { // No notes for this slide return null; @@ -180,7 +204,7 @@ if(notes.size() > 1) { throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size()); } - + try { return slidePart.getRelatedPart(notes.getRelationship(0)); } catch(InvalidFormatException e) { @@ -196,13 +220,13 @@ PackagePart notesPart = getNodesPart(slide); if(notesPart == null) return null; - + NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream()); - + return notesDoc.getNotes(); } - + /** * Returns all the comments for the given slide */ @@ -210,13 +234,13 @@ public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException { PackageRelationshipCollection commentRels; PackagePart slidePart = getSlidePart(slide); - + try { commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation()); } catch(InvalidFormatException e) { throw new IllegalStateException(e); } - + if(commentRels.size() == 0) { // No comments for this slide return null; @@ -224,12 +248,12 @@ if(commentRels.size() > 1) { throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size()); } - + try { PackagePart cPart = slidePart.getRelatedPart( commentRels.getRelationship(0) ); - CmLstDocument commDoc = + CmLstDocument commDoc = CmLstDocument.Factory.parse(cPart.getInputStream()); return commDoc.getCmLst(); } catch(InvalidFormatException e) { Index: src/ooxml/testcases/org/apache/poi/TestEmbeded.java =================================================================== diff --git a/poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java b/poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java --- a/poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java (revision 1574511) +++ b/poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java (working copy) @@ -15,8 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi; import org.apache.poi.util.IOUtils; @@ -54,7 +54,14 @@ ); test(doc, 4); } - + + public void testInternalEmbbedOnly() throws Exception { + POIXMLDocument doc = new XSLFSlideShow(OPCPackage.open( + POIDataSamples.getSlideShowInstance().openResourceAsStream("with_external_rel_ole.pptx")) + ); + test(doc, 0); + } + private void test(POIXMLDocument doc, int expectedCount) throws Exception { assertNotNull(doc.getAllEmbedds()); assertEquals(expectedCount, doc.getAllEmbedds().size()); @@ -62,7 +69,7 @@ for(int i=0; i 0); } Index: test-data/slideshow/with_external_rel_ole.pptx =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: test-data/slideshow/with_external_rel_ole.pptx =================================================================== diff --git a/poi/trunk/test-data/slideshow/with_external_rel_ole.pptx b/poi/trunk/test-data/slideshow/with_external_rel_ole.pptx --- a/poi/trunk/test-data/slideshow/with_external_rel_ole.pptx (revision 0) +++ b/poi/trunk/test-data/slideshow/with_external_rel_ole.pptx (working copy) Property changes on: poi/trunk/test-data/slideshow/with_external_rel_ole.pptx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property