aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2018-09-26 21:42:21 +0000
committerPJ Fanning <fanningpj@apache.org>2018-09-26 21:42:21 +0000
commit43c57c26c26d85a0e083d40b92e98a0f5efb34a2 (patch)
treee966151ee8e5823b4be72095e82e9ce345c7d9ed
parent9973fecad03c8155833f076c8d4139d6a2925e23 (diff)
downloadpoi-43c57c26c26d85a0e083d40b92e98a0f5efb34a2.tar.gz
poi-43c57c26c26d85a0e083d40b92e98a0f5efb34a2.zip
[bug-62736] Relations on XSLFPictureShape are removed unconditionally. Thanks to Mate Borcsok
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1842055 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java17
-rw-r--r--src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java81
-rw-r--r--test-data/slideshow/bug62736.pptxbin0 -> 50926 bytes
3 files changed, 96 insertions, 2 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
index 2dbc39bff4..cee875a831 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java
@@ -692,10 +692,23 @@ implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
/**
* Helper method for sheet and group shapes
*
- * @param pictureShape the picture shapes whose relation is to be removed
+ * @param pictureShape the picture shapes whose relation is to be removed,
+ * only if there are no more relations on its sheet to that picture
*/
void removePictureRelation(XSLFPictureShape pictureShape) {
- removeRelation(pictureShape.getBlipId());
+ int numberOfRelations = 0;
+ String targetBlipId = pictureShape.getBlipId();
+ for (XSLFShape shape : pictureShape.getSheet().getShapes()) {
+ if (shape instanceof XSLFPictureShape) {
+ XSLFPictureShape currentPictureShape = ((XSLFPictureShape) shape);
+ if (currentPictureShape.getBlipId().equals(targetBlipId)) {
+ numberOfRelations++;
+ }
+ }
+ }
+ if (numberOfRelations <= 1) {
+ removeRelation(pictureShape.getBlipId());
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
index c594280654..48b0816993 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
@@ -93,6 +93,87 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
public class TestXSLFBugs {
private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+ @Test
+ public void bug62736() throws Exception {
+ XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("bug62736.pptx");
+
+ assertEquals(1, ss1.getSlides().size());
+
+ XSLFSlide slide0 = ss1.getSlides().get(0);
+
+ assertEquals(slide0.getShapes().size(), 4);
+
+ assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+ assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+ assertRelation(slide0, "/ppt/media/image1.png", "rId2");
+ assertEquals(slide0.getRelations().size(), 2);
+
+ List<XSLFPictureShape> pictures = new ArrayList<>();
+ for (XSLFShape shape : slide0.getShapes()) {
+ if (shape instanceof XSLFPictureShape) {
+ pictures.add((XSLFPictureShape) shape);
+ }
+ }
+
+ assertEquals(pictures.size(), 2);
+ assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
+ assertEquals(pictures.get(1).getPictureData().getFileName(), "image1.png");
+ // blipId is rId2 of both pictures
+
+ // remove just the first picture
+ slide0.removeShape(pictures.get(0));
+
+ assertEquals(slide0.getShapes().size(), 3);
+
+ assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+ assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+ // the bug is that the following relation is gone
+ assertRelation(slide0, "/ppt/media/image1.png", "rId2");
+ assertEquals(slide0.getRelations().size(), 2);
+
+ // Save and re-load
+ XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
+ ss1.close();
+ assertEquals(1, ss2.getSlides().size());
+
+ slide0 = ss2.getSlides().get(0);
+
+ assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+ assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+ assertRelation(slide0, "/ppt/media/image1.png", "rId2");
+ assertEquals(slide0.getRelations().size(), 2);
+
+ pictures.clear();
+ for (XSLFShape shape : slide0.getShapes()) {
+ if (shape instanceof XSLFPictureShape) {
+ pictures.add((XSLFPictureShape) shape);
+ }
+ }
+
+ assertEquals(pictures.size(), 1);
+ assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
+
+ slide0.removeShape(pictures.get(0));
+
+ assertEquals(slide0.getShapes().size(), 2);
+
+ assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+ assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+ assertNull(slide0.getRelationById("rId2"));
+ assertEquals(slide0.getRelations().size(), 1);
+
+ // Save and re-load
+ XMLSlideShow ss3 = XSLFTestDataSamples.writeOutAndReadBack(ss2);
+ ss2.close();
+ assertEquals(1, ss3.getSlides().size());
+
+ slide0 = ss3.getSlides().get(0);
+
+ assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+ assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+ assertEquals(slide0.getShapes().size(), 2);
+ ss3.close();
+ }
@Test
public void bug61589() throws IOException {
diff --git a/test-data/slideshow/bug62736.pptx b/test-data/slideshow/bug62736.pptx
new file mode 100644
index 0000000000..5593bff217
--- /dev/null
+++ b/test-data/slideshow/bug62736.pptx
Binary files differ