]> source.dussan.org Git - poi.git/commitdiff
#62037 - SlideNames should not be null but have a default as if accessed by VBA
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 16 May 2018 21:57:49 +0000 (21:57 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 16 May 2018 21:57:49 +0000 (21:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1831745 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/sl/usermodel/Slide.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java
src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
test-data/slideshow/SampleShow.ppt
test-data/slideshow/SampleShow.pptx

index 00492df5fc757631edf0ad73ee39508210895c2a..91b80f107e48296926a2413f96d4212ff5ca6129 100644 (file)
@@ -83,4 +83,11 @@ public interface Slide<
      * @since POI 4.0.0
      */
     MasterSheet getSlideLayout();
+
+    /**
+     * @return the slide name, defaults to "Slide[slideNumber]"
+     *
+     * @since POI 4.0.0
+     */
+    String getSlideName();
 }
index 4df63e265546ed8f041762011ad19383844a1ba9..51fc80a54b02ea2df570c025c1826485cffd01cd 100644 (file)
@@ -390,5 +390,11 @@ implements Slide<XSLFShape,XSLFTextParagraph> {
     public boolean isHidden() {
         CTSlide sld = getXmlObject();
         return sld.isSetShow() && !sld.getShow();
-    }    
+    }
+
+    @Override
+    public String getSlideName() {
+        final CTCommonSlideData cSld = getXmlObject().getCSld();
+        return cSld.isSetName() ? cSld.getName() : "Slide"+getSlideNumber();
+    }
 }
index 5bae46a8ad33ed2c6f219c1d33e1c8613ca33491..673b72009aa1faa512a82198c441a2a05e4f1ca0 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.poi.ddf.EscherDggRecord;
 import org.apache.poi.ddf.EscherSpRecord;
 import org.apache.poi.hslf.exceptions.HSLFException;
 import org.apache.poi.hslf.model.HeadersFooters;
+import org.apache.poi.hslf.record.CString;
 import org.apache.poi.hslf.record.ColorSchemeAtom;
 import org.apache.poi.hslf.record.Comment2000;
 import org.apache.poi.hslf.record.EscherTextboxWrapper;
@@ -231,7 +232,12 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTe
                return null;
        }
 
-       // Simple Accesser methods follow
+    @Override
+       public String getSlideName() {
+        final CString name = (CString)getSlideRecord().findFirstOfType(RecordTypes.CString.typeID);
+        return name != null ? name.getText() : "Slide"+getSlideNumber();
+    }
+
 
        /**
         * Returns an array of all the TextRuns found
index 347ea73a6c11f1f0d038d4356fa56ba65c938e54..c4daa50b3f16a067ee28d222e51deb9ad6340e8f 100644 (file)
@@ -159,16 +159,20 @@ public abstract class BaseTestSlideShow {
     }
 
     @Test
-    public void shapeName() throws IOException {
+    public void shapeAndSlideName() throws IOException {
         final String file = "SampleShow.ppt"+(getClass().getSimpleName().contains("XML")?"x":"");
-        try (final InputStream is = slTests.openResourceAsStream(file)) {
-            try (final SlideShow<? extends Shape, ?> ppt = SlideShowFactory.create(is)) {
-                final List<? extends Shape> shapes1 = ppt.getSlides().get(0).getShapes();
-                assertEquals("The Title", shapes1.get(0).getShapeName());
-                assertEquals("Another Subtitle", shapes1.get(1).getShapeName());
-                final List<? extends Shape> shapes2 = ppt.getSlides().get(1).getShapes();
-                assertEquals("Title 1", shapes2.get(0).getShapeName());
-                assertEquals("Content Placeholder 2", shapes2.get(1).getShapeName());
+        try (final InputStream is = slTests.openResourceAsStream(file);
+             final SlideShow<? extends Shape, ?> ppt = SlideShowFactory.create(is)) {
+            final List<? extends Shape> shapes1 = ppt.getSlides().get(0).getShapes();
+            assertEquals("The Title", shapes1.get(0).getShapeName());
+            assertEquals("Another Subtitle", shapes1.get(1).getShapeName());
+            final List<? extends Shape> shapes2 = ppt.getSlides().get(1).getShapes();
+            assertEquals("Title 1", shapes2.get(0).getShapeName());
+            assertEquals("Content Placeholder 2", shapes2.get(1).getShapeName());
+
+            for (final Slide<?,?> slide : ppt.getSlides()) {
+                final String expected = slide.getSlideNumber()==1 ? "FirstSlide" : "Slide2";
+                assertEquals(expected, slide.getSlideName());
             }
         }
     }
index 7af347a5df883e4096849323830f8d07eb3f86ad..556f4c4e1f7ad2aca89bc82b59f8c451c84caeae 100644 (file)
Binary files a/test-data/slideshow/SampleShow.ppt and b/test-data/slideshow/SampleShow.ppt differ
index 7db4d06e9ebd4d9e15381ea9df0d873446231b47..4496c269530b69ad70631e2543f8c3a360866238 100644 (file)
Binary files a/test-data/slideshow/SampleShow.pptx and b/test-data/slideshow/SampleShow.pptx differ