diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index 872f82f83..8663b897f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -19,28 +19,34 @@ package org.apache.poi.xslf.usermodel; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; + +import javax.imageio.ImageIO; +import javax.xml.namespace.QName; + import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.drawingml.x2006.main.*; +import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; +import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; +import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension; +import org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtensionList; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType; import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps; import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual; -import javax.imageio.ImageIO; -import javax.xml.namespace.QName; -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; - /** * Represents a picture shape - * - * @author Yegor Kozlov */ @Beta public class XSLFPictureShape extends XSLFSimpleShape { diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java index 8c1600fff..fc422e778 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java @@ -25,7 +25,10 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xslf.usermodel.DrawingParagraph; import org.apache.poi.xslf.usermodel.DrawingTextBody; import org.apache.poi.xslf.usermodel.XMLSlideShow; +import org.apache.poi.xslf.usermodel.XSLFPictureData; +import org.apache.poi.xslf.usermodel.XSLFPictureShape; import org.apache.poi.xslf.usermodel.XSLFRelation; +import org.apache.poi.xslf.usermodel.XSLFShape; import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlideLayout; @@ -136,6 +139,31 @@ public class TestXSLFBugs extends POITestCase { assertContains("POI can read this", getSlideText(slide)); } + /** + * When the picture is not embedded but inserted only as a "link to file", + * there is no data available and XSLFPictureShape.getPictureData() + * gives a NPE, see bug #56812 + */ + public void DISABLEDtest56812() throws Exception { + XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("56812.pptx"); + + int pictures = 0; + for (XSLFSlide slide : ppt.getSlides()){ + for (XSLFShape shape : slide.getShapes()){ + assertNotNull(shape); + + if (shape instanceof XSLFPictureShape) { + XSLFPictureData data = ((XSLFPictureShape) shape).getPictureData(); + assertNotNull(data); + assertNotNull(data.getFileName()); + pictures++; + } + } + } + + assertEquals(3, pictures); + } + protected String getSlideText(XSLFSlide slide) { StringBuffer text = new StringBuffer(); for(DrawingTextBody textBody : slide.getCommonSlideData().getDrawingText()) { diff --git a/test-data/slideshow/56812.pptx b/test-data/slideshow/56812.pptx new file mode 100644 index 000000000..2fa070ad1 Binary files /dev/null and b/test-data/slideshow/56812.pptx differ