diff --git a/src/java/org/apache/poi/sl/usermodel/Slide.java b/src/java/org/apache/poi/sl/usermodel/Slide.java index 00492df5f..91b80f107 100644 --- a/src/java/org/apache/poi/sl/usermodel/Slide.java +++ b/src/java/org/apache/poi/sl/usermodel/Slide.java @@ -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(); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 4df63e265..51fc80a54 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -390,5 +390,11 @@ implements Slide { 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(); + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java index 5bae46a8a..673b72009 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java @@ -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 ppt = SlideShowFactory.create(is)) { - final List shapes1 = ppt.getSlides().get(0).getShapes(); - assertEquals("The Title", shapes1.get(0).getShapeName()); - assertEquals("Another Subtitle", shapes1.get(1).getShapeName()); - final List 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 ppt = SlideShowFactory.create(is)) { + final List shapes1 = ppt.getSlides().get(0).getShapes(); + assertEquals("The Title", shapes1.get(0).getShapeName()); + assertEquals("Another Subtitle", shapes1.get(1).getShapeName()); + final List 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()); } } } diff --git a/test-data/slideshow/SampleShow.ppt b/test-data/slideshow/SampleShow.ppt index 7af347a5d..556f4c4e1 100644 Binary files a/test-data/slideshow/SampleShow.ppt and b/test-data/slideshow/SampleShow.ppt differ diff --git a/test-data/slideshow/SampleShow.pptx b/test-data/slideshow/SampleShow.pptx index 7db4d06e9..4496c2695 100644 Binary files a/test-data/slideshow/SampleShow.pptx and b/test-data/slideshow/SampleShow.pptx differ