View | Details | Raw Unified | Return to bug 62736
Collapse All | Expand All

(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java (-2 / +15 lines)
Lines 692-701 implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> { Link Here
692
    /**
692
    /**
693
     * Helper method for sheet and group shapes
693
     * Helper method for sheet and group shapes
694
     *
694
     *
695
     * @param pictureShape the picture shapes whose relation is to be removed
695
     * @param pictureShape the picture shapes whose relation is to be removed,
696
     *                     only if there are no more relations on its sheet to that picture
696
     */
697
     */
697
    void removePictureRelation(XSLFPictureShape pictureShape) {
698
    void removePictureRelation(XSLFPictureShape pictureShape) {
698
        removeRelation(pictureShape.getBlipId());
699
        int numberOfRelations = 0;
700
        String targetBlipId = pictureShape.getBlipId();
701
        for (XSLFShape shape : pictureShape.getSheet().getShapes()) {
702
            if (shape instanceof XSLFPictureShape) {
703
                XSLFPictureShape currentPictureShape = ((XSLFPictureShape) shape);
704
                if (currentPictureShape.getBlipId().equals(targetBlipId)) {
705
                    numberOfRelations++;
706
                }
707
            }
708
        }
709
        if (numberOfRelations <= 1) {
710
            removeRelation(pictureShape.getBlipId());
711
        }
699
    }
712
    }
700
713
701
714
(-)a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (+81 lines)
Lines 93-98 import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; Link Here
93
public class TestXSLFBugs {
93
public class TestXSLFBugs {
94
    private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
94
    private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
95
95
96
    @Test
97
    public void bug62736() throws Exception {
98
        XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("bug62736.pptx");
99
100
        assertEquals(1, ss1.getSlides().size());
101
102
        XSLFSlide slide0 = ss1.getSlides().get(0);
103
104
        assertEquals(slide0.getShapes().size(), 4);
105
106
        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
107
        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
108
        assertRelation(slide0, "/ppt/media/image1.png", "rId2");
109
        assertEquals(slide0.getRelations().size(), 2);
110
111
        List<XSLFPictureShape> pictures = new ArrayList<>();
112
        for (XSLFShape shape : slide0.getShapes()) {
113
            if (shape instanceof XSLFPictureShape) {
114
                pictures.add((XSLFPictureShape) shape);
115
            }
116
        }
117
118
        assertEquals(pictures.size(), 2);
119
        assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
120
        assertEquals(pictures.get(1).getPictureData().getFileName(), "image1.png");
121
        // blipId is rId2 of both pictures
122
123
        // remove just the first picture
124
        slide0.removeShape(pictures.get(0));
125
126
        assertEquals(slide0.getShapes().size(), 3);
127
128
        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
129
        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
130
        // the bug is that the following relation is gone
131
        assertRelation(slide0, "/ppt/media/image1.png", "rId2");
132
        assertEquals(slide0.getRelations().size(), 2);
133
134
        // Save and re-load
135
        XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
136
        ss1.close();
137
        assertEquals(1, ss2.getSlides().size());
138
139
        slide0 = ss2.getSlides().get(0);
140
141
        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
142
        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
143
        assertRelation(slide0, "/ppt/media/image1.png", "rId2");
144
        assertEquals(slide0.getRelations().size(), 2);
145
146
        pictures.clear();
147
        for (XSLFShape shape : slide0.getShapes()) {
148
            if (shape instanceof XSLFPictureShape) {
149
                pictures.add((XSLFPictureShape) shape);
150
            }
151
        }
152
153
        assertEquals(pictures.size(), 1);
154
        assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
155
156
        slide0.removeShape(pictures.get(0));
157
158
        assertEquals(slide0.getShapes().size(), 2);
159
160
        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
161
        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
162
        assertNull(slide0.getRelationById("rId2"));
163
        assertEquals(slide0.getRelations().size(), 1);
164
165
        // Save and re-load
166
        XMLSlideShow ss3 = XSLFTestDataSamples.writeOutAndReadBack(ss2);
167
        ss2.close();
168
        assertEquals(1, ss3.getSlides().size());
169
170
        slide0 = ss3.getSlides().get(0);
171
172
        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
173
        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
174
        assertEquals(slide0.getShapes().size(), 2);
175
        ss3.close();
176
    }
96
177
97
    @Test
178
    @Test
98
    public void bug61589() throws IOException {
179
    public void bug61589() throws IOException {

Return to bug 62736