aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2014-12-07 15:28:01 +0000
committerAndreas Beeker <kiwiwings@apache.org>2014-12-07 15:28:01 +0000
commitac0cc6c56e965869f6b4d129dc6d4b246090dbff (patch)
treebbeab721154e681071061035ef4150bf9d0274fb
parent39dbbe9c413f9d04d6b51a20e93f2a2ff270f314 (diff)
downloadpoi-ac0cc6c56e965869f6b4d129dc6d4b246090dbff.tar.gz
poi-ac0cc6c56e965869f6b4d129dc6d4b246090dbff.zip
57250 - XMLSlideShow.setSlideOrder() produces corrupted CTSlideIdList
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1643684 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java20
-rw-r--r--src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java40
2 files changed, 52 insertions, 8 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index dca1aed06d..b1c6be4573 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -20,11 +20,7 @@ import java.awt.Dimension;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.regex.Pattern;
import org.apache.poi.POIXMLDocument;
@@ -366,18 +362,26 @@ public class XMLSlideShow extends POIXMLDocument {
*
* @param newIndex 0-based index of the slide
*/
+ @SuppressWarnings("deprecation")
public void setSlideOrder(XSLFSlide slide, int newIndex){
int oldIndex = _slides.indexOf(slide);
if(oldIndex == -1) throw new IllegalArgumentException("Slide not found");
+ if (oldIndex == newIndex) return;
// fix the usermodel container
_slides.add(newIndex, _slides.remove(oldIndex));
// fix ordering in the low-level xml
CTSlideIdList sldIdLst = _presentation.getSldIdLst();
- CTSlideIdListEntry oldEntry = sldIdLst.getSldIdArray(oldIndex);
- sldIdLst.insertNewSldId(newIndex).set(oldEntry);
- sldIdLst.removeSldId(oldIndex);
+ CTSlideIdListEntry[] entries = sldIdLst.getSldIdArray();
+ CTSlideIdListEntry oldEntry = entries[oldIndex];
+ if (oldIndex < newIndex) {
+ System.arraycopy(entries, oldIndex + 1, entries, oldIndex, newIndex - oldIndex);
+ } else {
+ System.arraycopy(entries, newIndex, entries, newIndex + 1, oldIndex - newIndex);
+ }
+ entries[newIndex] = oldEntry;
+ sldIdLst.setSldIdArray(entries);
}
public XSLFSlide removeSlide(int index){
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
index bee3651432..7d18541d9b 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
@@ -233,4 +233,44 @@ public class TestXSLFBugs {
}
return text.toString();
}
+
+ @Test
+ public void bug57250() throws Exception {
+ XMLSlideShow ss = new XMLSlideShow();
+ for (String s : new String[]{"Slide1","Slide2"}) {
+ ss.createSlide().createTextBox().setText(s);
+ }
+ validateSlides(ss, false, "Slide1","Slide2");
+
+ XSLFSlide slide = ss.createSlide();
+ slide.createTextBox().setText("New slide");
+ validateSlides(ss, true, "Slide1","Slide2","New slide");
+
+ // Move backward
+ ss.setSlideOrder(slide, 0);
+ validateSlides(ss, true, "New slide","Slide1","Slide2");
+
+ // Move forward
+ ss.setSlideOrder(slide, 1);
+ validateSlides(ss, true, "Slide1","New slide","Slide2");
+
+ // Move to end
+ ss.setSlideOrder(slide, 0);
+ ss.setSlideOrder(slide, 2);
+ validateSlides(ss, true, "Slide1","Slide2","New slide");
+ }
+
+ private void validateSlides(XMLSlideShow ss, boolean saveAndReload, String... slideTexts) {
+ if (saveAndReload) {
+ ss = XSLFTestDataSamples.writeOutAndReadBack(ss);
+ }
+
+ assertEquals(slideTexts.length, ss.getSlides().length);
+
+ for (int i = 0; i < slideTexts.length; i++) {
+ XSLFSlide slide = ss.getSlides()[i];
+ assertContains(getSlideText(slide), slideTexts[i]);
+ }
+ }
+
}