poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1734862 - in /poi/trunk/src/ooxml: java/org/apache/poi/xslf/usermodel/XMLSlideShow.java testcases/org/apache/poi/xslf/TestXSLFBugs.java
Date Sun, 13 Mar 2016 21:30:27 GMT
Author: centic
Date: Sun Mar 13 21:30:27 2016
New Revision: 1734862

URL: http://svn.apache.org/viewvc?rev=1734862&view=rev
Log:
Bug 55791: Avoid using an existing file-name when creating a new slide, it could still be
left over from previous partial removal

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1734862&r1=1734861&r2=1734862&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Sun Mar 13 21:30:27
2016
@@ -103,7 +103,7 @@ implements SlideShow<XSLFShape,XSLFTextP
         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'");
@@ -215,11 +215,37 @@ implements SlideShow<XSLFShape,XSLFTextP
                 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);
@@ -286,7 +312,7 @@ implements SlideShow<XSLFShape,XSLFTextP
     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();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1734862&r1=1734861&r2=1734862&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Sun Mar 13 21:30:27
2016
@@ -18,9 +18,7 @@ package org.apache.poi.xslf;
 
 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;
@@ -412,4 +410,22 @@ public class TestXSLFBugs {
         
         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());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message