]> source.dussan.org Git - poi.git/commitdiff
[bug-67005] XSLFPictureShape - audio-related methods. Thanks to Max
authorPJ Fanning <fanningpj@apache.org>
Thu, 14 Sep 2023 14:56:01 +0000 (14:56 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 14 Sep 2023 14:56:01 +0000 (14:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912315 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFPictureShape.java
src/resources/ooxml-lite-report.clazz
src/resources/ooxml-lite-report.xsb
test-data/slideshow/EmbeddedAudio.pptx [new file with mode: 0644]

index b7e2bb54967dcee539489cb2ffa65965d085cc9c..3e0f6bccc3ab1038d0756ca172367ba0d00c5b13 100644 (file)
@@ -469,6 +469,27 @@ public class XSLFPictureShape extends XSLFSimpleShape
         return null;
     }
 
+    private CTApplicationNonVisualDrawingProps getCTApplicationNonVisualDrawing() {
+        CTPictureNonVisual nvPicPr = getCTPictureNonVisual();
+        return nvPicPr == null ? null : nvPicPr.getNvPr();
+    }
+
+    /**
+     * @return boolean; true if the picture is an audio
+     */
+    public boolean isAudioFile() {
+        CTApplicationNonVisualDrawingProps nvPr = getCTApplicationNonVisualDrawing();
+        return nvPr != null && nvPr.isSetAudioFile();
+    }
+
+    /**
+     * @return the link ID for the audio file
+     */
+    public String getAudioFileLink() {
+        CTApplicationNonVisualDrawingProps nvPr = getCTApplicationNonVisualDrawing();
+        return nvPr != null && nvPr.isSetAudioFile() ? nvPr.getAudioFile().getLink() : null;
+    }
+
     private CTPictureNonVisual getCTPictureNonVisual() {
         XmlObject xmlObject = getXmlObject();
         if (xmlObject instanceof CTPicture) {
@@ -477,4 +498,4 @@ public class XSLFPictureShape extends XSLFSimpleShape
         }
         return null;
     }
-}
\ No newline at end of file
+}
index 65d18e9043411a936b0431d92179bf46b953de6c..48c91615013ea3b9f08cb8f8198715245322bab1 100644 (file)
@@ -359,4 +359,24 @@ class TestXSLFPictureShape {
             assertEquals(ps.getVideoFileLink(), "rId2");
         }
     }
+
+    @Test
+    void testIsSetAudioFile() throws IOException {
+        try (XMLSlideShow ppt = openSampleDocument("EmbeddedAudio.pptx")) {
+            XSLFSlide slide = ppt.getSlides().get(0);
+            XSLFPictureShape ps = (XSLFPictureShape) slide.getShapes().get(0);
+
+            assertTrue(ps.isAudioFile());
+        }
+    }
+
+    @Test
+    void testGetAudioLink() throws IOException {
+        try (XMLSlideShow ppt = openSampleDocument("EmbeddedAudio.pptx")) {
+            XSLFSlide slide = ppt.getSlides().get(0);
+            XSLFPictureShape ps = (XSLFPictureShape) slide.getShapes().get(0);
+
+            assertEquals(ps.getAudioFileLink(), "rId2");
+        }
+    }
 }
\ No newline at end of file
index 16c5c9d4b21ae40ffc4b6189b83b550e2e6ac6cc..50963a55bd938585747dc54a7d6ac19beaf2e469 100644 (file)
@@ -2525,3 +2525,5 @@ org/openxmlformats/schemas/drawingml/x2006/main/CTComplementTransform
 org/openxmlformats/schemas/drawingml/x2006/main/CTPositiveFixedAngle
 org/openxmlformats/schemas/drawingml/x2006/chart/impl/STAxisUnitImpl
 org/openxmlformats/schemas/drawingml/x2006/chart/STAxisUnit
+org/openxmlformats/schemas/drawingml/x2006/main/impl/CTAudioFileImpl
+org/openxmlformats/schemas/drawingml/x2006/main/CTAudioFile
index 26de7ad4db26e38eda560ab6dbb6ff6e71358939..f6be2d73d2011060433a37125252f39f9675b53c 100644 (file)
@@ -1175,3 +1175,4 @@ ctdlblpos9ce4type
 stdlblpos1cf4type
 staxisunit6cc7type
 chartelement2
+ctaudiofile1563type
diff --git a/test-data/slideshow/EmbeddedAudio.pptx b/test-data/slideshow/EmbeddedAudio.pptx
new file mode 100644 (file)
index 0000000..ab12d00
Binary files /dev/null and b/test-data/slideshow/EmbeddedAudio.pptx differ