[bug-67005] XSLFPictureShape - audio-related methods. Thanks to Max

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912315 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2023-09-14 14:56:01 +00:00
parent 3a6b91dd1f
commit 4afcb281ce
5 changed files with 45 additions and 1 deletions

View 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;
}
}
}

View 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");
}
}
}

View 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

View File

@ -1175,3 +1175,4 @@ ctdlblpos9ce4type
stdlblpos1cf4type
staxisunit6cc7type
chartelement2
ctaudiofile1563type

Binary file not shown.