this(PackageHelper.open(is));
}
- static final OPCPackage empty() {
+ static OPCPackage empty() {
InputStream is = XMLSlideShow.class.getResourceAsStream("empty.pptx");
if (is == null) {
throw new POIXMLException("Missing resource 'empty.pptx'");
slideNumber = (int)Math.max(slideId.getId() + 1, slideNumber);
cnt++;
}
+
+ // Bug 55791: We also need to check that the resulting file name is not already taken
+ // this can happen when removing/adding slides
+ while(true) {
+ String slideName = XSLFRelation.SLIDE.getFileName(cnt);
+ boolean found = false;
+ for (POIXMLDocumentPart relation : getRelations()) {
+ if (relation.getPackagePart() != null &&
+ slideName.equals(relation.getPackagePart().getPartName().getName())) {
+ // name is taken => try next one
+ found = true;
+ break;
+ }
+ }
+
+ if(!found &&
+ getPackage().getPartsByName(Pattern.compile(Pattern.quote(slideName))).size() > 0) {
+ // name is taken => try next one
+ found = true;
+ }
+
+ if (!found) {
+ break;
+ }
+ cnt++;
+ }
}
RelationPart rp = createRelationship(
XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt, false);
- XSLFSlide slide = (XSLFSlide)rp.getDocumentPart();
+ XSLFSlide slide = rp.getDocumentPart();
CTSlideIdListEntry slideId = slideList.addNewSldId();
slideId.setId(slideNumber);
public void createNotesMaster() {
RelationPart rp = createRelationship
(XSLFRelation.NOTES_MASTER, XSLFFactory.getInstance(), 1, false);
- _notesMaster = (XSLFNotesMaster)rp.getDocumentPart();
+ _notesMaster = rp.getDocumentPart();
CTNotesMasterIdList notesMasterIdList = _presentation.addNewNotesMasterIdLst();
CTNotesMasterIdListEntry notesMasterId = notesMasterIdList.addNewNotesMasterId();
import static junit.framework.TestCase.assertEquals;
import static org.apache.poi.POITestCase.assertContains;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.awt.Color;
import java.awt.Dimension;
ss.close();
}
+
+ @Test
+ public void bug55791a() {
+ XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("45541_Footer.pptx");
+ removeAndCreateSlide(ppt);
+ }
+
+ @Test
+ public void bug55791b() {
+ XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("SampleShow.pptx");
+ removeAndCreateSlide(ppt);
+ }
+
+ private void removeAndCreateSlide(XMLSlideShow ppt) {
+ assertTrue(ppt.getSlides().size() > 1);
+ ppt.removeSlide(1);
+ assertNotNull(ppt.createSlide());
+ }
}